mirror of
https://github.com/He4eT/simple-spaceapi.git
synced 2026-05-04 17:37:24 +00:00
Linting
This commit is contained in:
parent
4363a362fa
commit
782072f19f
1 changed files with 40 additions and 37 deletions
|
|
@ -1,16 +1,18 @@
|
||||||
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 =>
|
||||||
? true
|
x == null
|
||||||
: Object.keys(x).length === 0
|
? true
|
||||||
? String(x).length === 0
|
: Object.keys(x).length === 0
|
||||||
: false;
|
? String(x).length === 0
|
||||||
|
: false;
|
||||||
|
|
||||||
const pickFields = (fields: Array<string>) => (obj: Record<string, unknown>): object =>
|
const pickFields = (fields: Array<string>) =>
|
||||||
Object.fromEntries(Object.entries(obj)
|
(obj: Record<string, unknown>): object =>
|
||||||
.filter(([k, _]) => fields.includes(k))
|
Object.fromEntries(Object.entries(obj)
|
||||||
.filter(([_, v]) => !isEmpty(v)));
|
.filter(([k, _]) => fields.includes(k))
|
||||||
|
.filter(([_, v]) => !isEmpty(v)));
|
||||||
|
|
||||||
const dateTimeToUnixtime = (updatedAt: string) => {
|
const dateTimeToUnixtime = (updatedAt: string) => {
|
||||||
const date = new Date(updatedAt);
|
const date = new Date(updatedAt);
|
||||||
|
|
@ -29,24 +31,26 @@ 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({
|
||||||
'logo',
|
populate: [
|
||||||
'location',
|
'logo',
|
||||||
'location.areas',
|
'location',
|
||||||
'spacefed',
|
'location.areas',
|
||||||
'cam',
|
'spacefed',
|
||||||
'contact',
|
'cam',
|
||||||
'contact.keymasters',
|
'contact',
|
||||||
'feeds',
|
'contact.keymasters',
|
||||||
'feeds.blog',
|
'feeds',
|
||||||
'feeds.wiki',
|
'feeds.blog',
|
||||||
'feeds.calendar',
|
'feeds.wiki',
|
||||||
'feeds.flickr',
|
'feeds.calendar',
|
||||||
'projects',
|
'feeds.flickr',
|
||||||
'links',
|
'projects',
|
||||||
'membership_plans',
|
'links',
|
||||||
'linked_spaces',
|
'membership_plans',
|
||||||
]});
|
'linked_spaces',
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
result.api_compatibility = ['15'];
|
result.api_compatibility = ['15'];
|
||||||
result.space = hackspace.space;
|
result.space = hackspace.space;
|
||||||
|
|
@ -82,7 +86,7 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
|
|
||||||
if (!isEmpty(hackspace.cam)) {
|
if (!isEmpty(hackspace.cam)) {
|
||||||
result.cam = hackspace.cam
|
result.cam = hackspace.cam
|
||||||
.map(({url}) => url);
|
.map(({ url }) => url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
|
|
@ -242,7 +246,7 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
'description',
|
'description',
|
||||||
'lastchange',
|
'lastchange',
|
||||||
],
|
],
|
||||||
)).map((sensor: {unit: string}) => {
|
)).map((sensor: { unit: string }) => {
|
||||||
const { unit, ...rest } = sensor;
|
const { unit, ...rest } = sensor;
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
|
|
@ -301,7 +305,7 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
'properties.direction',
|
'properties.direction',
|
||||||
'properties.elevation',
|
'properties.elevation',
|
||||||
],
|
],
|
||||||
)).map((sensor: {properties: {bits_per_second: number, packets_per_second: number}}) => {
|
)).map((sensor: { properties: { bits_per_second: number, packets_per_second: number } }) => {
|
||||||
const { properties, ...rest } = sensor;
|
const { properties, ...rest } = sensor;
|
||||||
|
|
||||||
const propertiesEntries = Object.entries(pickFields([
|
const propertiesEntries = Object.entries(pickFields([
|
||||||
|
|
@ -310,7 +314,7 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
'direction',
|
'direction',
|
||||||
'elevation',
|
'elevation',
|
||||||
])(properties))
|
])(properties))
|
||||||
.map(([k, {value, unit}]) => [k, {
|
.map(([k, { value, unit }]) => [k, {
|
||||||
value,
|
value,
|
||||||
unit: unit === 'degree' ? '°' : unit,
|
unit: unit === 'degree' ? '°' : unit,
|
||||||
}]);
|
}]);
|
||||||
|
|
@ -336,7 +340,7 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
[
|
[
|
||||||
'machines',
|
'machines',
|
||||||
],
|
],
|
||||||
)).map((sensor: {machines: Array<{name?: string, mac?: string}>}) => {
|
)).map((sensor: { machines: Array<{ name?: string, mac?: string }> }) => {
|
||||||
const { machines, ...rest } = sensor;
|
const { machines, ...rest } = sensor;
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
|
|
@ -382,7 +386,7 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
[
|
[
|
||||||
'names',
|
'names',
|
||||||
],
|
],
|
||||||
)).map((sensor: { names: Array<{name: string}> }) => {
|
)).map((sensor: { names: Array<{ name: string }> }) => {
|
||||||
const { names, ...rest } = sensor;
|
const { names, ...rest } = sensor;
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
|
|
@ -407,7 +411,7 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
'properties.bits_per_second',
|
'properties.bits_per_second',
|
||||||
'properties.packets_per_second',
|
'properties.packets_per_second',
|
||||||
],
|
],
|
||||||
)).map((sensor: {properties: {bits_per_second: number, packets_per_second: number}}) => {
|
)).map((sensor: { properties: { bits_per_second: number, packets_per_second: number } }) => {
|
||||||
const { properties, ...rest } = sensor;
|
const { properties, ...rest } = sensor;
|
||||||
|
|
||||||
const propertiesEntries = Object.entries(pickFields([
|
const propertiesEntries = Object.entries(pickFields([
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
@ -474,7 +477,7 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
|
|
||||||
if (!isEmpty(hackspace.projects)) {
|
if (!isEmpty(hackspace.projects)) {
|
||||||
result.projects = hackspace.projects
|
result.projects = hackspace.projects
|
||||||
.map(({url}) => url);
|
.map(({ url }) => url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue