This commit is contained in:
He4eT 2025-04-05 02:08:41 +02:00
commit 782072f19f

View file

@ -1,13 +1,15 @@
import type { Core, UID } from '@strapi/strapi';
import type { Context } from 'koa';
const isEmpty = <A>(x: A): boolean => x == null
const isEmpty = <A>(x: A): boolean =>
x == null
? true
: Object.keys(x).length === 0
? String(x).length === 0
: false;
const pickFields = (fields: Array<string>) => (obj: Record<string, unknown>): object =>
const pickFields = (fields: Array<string>) =>
(obj: Record<string, unknown>): object =>
Object.fromEntries(Object.entries(obj)
.filter(([k, _]) => fields.includes(k))
.filter(([_, v]) => !isEmpty(v)));
@ -29,7 +31,8 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
const hackspace = await strapi
.documents('api::hackspace.hackspace')
.findFirst({ populate: [
.findFirst({
populate: [
'logo',
'location',
'location.areas',
@ -46,7 +49,8 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
'links',
'membership_plans',
'linked_spaces',
]});
],
});
result.api_compatibility = ['15'];
result.space = hackspace.space;
@ -446,7 +450,6 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
network_traffic: networkTrafficSensors,
};
if (Object.entries(sensors).some(([_, sensor]) => !isEmpty(sensor))) {
result.sensors = pickFields(Object.keys(sensors))(sensors);
}