Add classes table and API enpoint

This commit is contained in:
2022-05-01 23:35:21 +02:00
parent a47d913d6f
commit 078d9f6c66
3 changed files with 26 additions and 1 deletions

View File

@ -127,3 +127,17 @@ export async function getHistory(req, res) {
});
res.send(changes);
}
export async function getClasses(req, res) {
const classes = await prisma.class.findMany({
select: {
name: true,
regex: false,
},
orderBy: {
name: "asc",
},
});
const classList = classes.map((element) => element.name);
res.send(classList);
}

View File

@ -1,5 +1,10 @@
import express from "express";
import { getTimetable, getSubstitutions, getHistory } from "./api/index.js";
import {
getTimetable,
getSubstitutions,
getHistory,
getClasses,
} from "./api/index.js";
const app = express();
const port = process.send.PORT || 3000;
@ -7,6 +12,7 @@ const port = process.send.PORT || 3000;
app.get("/api/timetable", getTimetable);
app.get("/api/substitutions", getSubstitutions);
app.get("/api/history", getHistory);
app.get("/api/classes", getClasses);
app.get("/api/*", (req, res) => {
res.sendStatus(400);
});

View File

@ -54,3 +54,8 @@ model ParseEvent {
SubstitutionChange SubstitutionChange[]
}
model Class {
name String @id @unique
regex String
}