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