mirror of
https://github.com/He4eT/simple-spaceapi.git
synced 2026-05-05 01:47:24 +00:00
Linting
This commit is contained in:
parent
4363a362fa
commit
782072f19f
1 changed files with 40 additions and 37 deletions
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue