✨ added area and last change support
This commit is contained in:
parent
d1ac9663a9
commit
ee4fdd36c6
4 changed files with 28 additions and 3 deletions
18
app.js
18
app.js
|
@ -23,11 +23,14 @@ let schema = buildSchema(`
|
|||
id: String!
|
||||
open: Boolean!
|
||||
updatedAt: String!
|
||||
lastChange: String
|
||||
area: String
|
||||
}
|
||||
|
||||
type Query {
|
||||
isOpen(id: String): Boolean
|
||||
spaces: [Space!]!
|
||||
inArea(area: String): [Space!]!
|
||||
}
|
||||
`);
|
||||
|
||||
|
@ -39,6 +42,20 @@ let root = {
|
|||
spaces: async () => {
|
||||
let data = await prisma.space.findMany();
|
||||
return data;
|
||||
},
|
||||
inArea: async ({ area }) => {
|
||||
// try to find the exact area first, if that fails, try to find at least a partial match
|
||||
let data = await prisma.space.findMany({ where: { area: area } });
|
||||
if (data.length == 0) {
|
||||
data = await prisma.space.findMany({
|
||||
where: {
|
||||
area: {
|
||||
contains: area
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -86,6 +103,7 @@ async function loop() {
|
|||
open: response.open,
|
||||
lastChange: response.lastchange,
|
||||
name: space.name,
|
||||
area: space.area,
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
// This is your Prisma schema file,
|
||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
@ -13,6 +10,7 @@ datasource db {
|
|||
model Space {
|
||||
id String @id
|
||||
name String?
|
||||
area String?
|
||||
open Boolean
|
||||
lastChange DateTime?
|
||||
updatedAt DateTime @updatedAt
|
||||
|
|
|
@ -28,6 +28,7 @@ So sieht ein Eintrag in der `spaces.json` aus:
|
|||
{
|
||||
"name": "CCC Aachen",
|
||||
"id": "cccaachen",
|
||||
"area": "DE-NW",
|
||||
"endpoint": "https://status.aachen.ccc.de/api/v0/status/current?public",
|
||||
"path": "$.changed.status",
|
||||
"expected": "public"
|
||||
|
@ -35,6 +36,7 @@ So sieht ein Eintrag in der `spaces.json` aus:
|
|||
```
|
||||
`id` ist eine einfache ID des Spaces. Sollte sich natürlich nicht überschneiden.
|
||||
`name` ist eine Art Friendly Name. Kann man benutzen damit es schön aussieht.
|
||||
`area` ist ein optionaler Value, der den Standort nach [`ISO 3166-2:DE`](https://www.iso.org/obp/ui/#iso:code:3166:DE) beschreibt. Kann benutzt werden, um später nach Region zu filtern.
|
||||
`endpoint` beschreibt die URL, die der Server anhauen soll.
|
||||
`path` ist ein JSONPath zum Wert, der beschreibt, ob der Space offen ist. Das ist nur nötig, wenn die API vom SpaceAPI Standard abweicht.
|
||||
`expected` kann einen Value beschreiben, wenn der Wert sich nicht durch einen Boolean darstellen lässt (also nicht `true`, `"true"`, `1`, usw.). Das sollte auch nur nötig sein, wenn die API vom SpaceAPI Srandard abweicht.
|
||||
|
|
|
@ -2,21 +2,25 @@
|
|||
{
|
||||
"name": "UNHB",
|
||||
"id": "unhb",
|
||||
"area": "DE-NW",
|
||||
"endpoint": "https://keinanschluss.unhb.de/spaceapi.json"
|
||||
},
|
||||
{
|
||||
"name": "Chaostreff Dortmund",
|
||||
"id": "ctdo",
|
||||
"area": "DE-NW",
|
||||
"endpoint": "https://status.ctdo.de/api/spaceapi/v13"
|
||||
},
|
||||
{
|
||||
"name": "Chaospott",
|
||||
"id": "chaospott",
|
||||
"area": "DE-NW",
|
||||
"endpoint": "https://status.chaospott.de/status.json"
|
||||
},
|
||||
{
|
||||
"name": "CCC Aachen",
|
||||
"id": "cccaachen",
|
||||
"area": "DE-NW",
|
||||
"endpoint": "https://status.aachen.ccc.de/api/v0/status/current?public",
|
||||
"path": "$.changed.status",
|
||||
"expected": "public"
|
||||
|
@ -24,16 +28,19 @@
|
|||
{
|
||||
"name": "CCC Köln",
|
||||
"id": "ccckoeln",
|
||||
"area": "DE-NW",
|
||||
"endpoint": "https://api.koeln.ccc.de"
|
||||
},
|
||||
{
|
||||
"name": "Hasi",
|
||||
"id": "hasi",
|
||||
"area": "DE-NW",
|
||||
"endpoint": "https://status.hasi.it/"
|
||||
},
|
||||
{
|
||||
"name": "Warpzone",
|
||||
"id": "warpzone",
|
||||
"area": "DE-NW",
|
||||
"endpoint": "https://api.warpzone.ms/status",
|
||||
"path": "$.tuerOffen"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue