diff --git a/server/api/index.js b/server/api/index.js index 34f8452..5c7a3bd 100644 --- a/server/api/index.js +++ b/server/api/index.js @@ -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); +} diff --git a/server/index.js b/server/index.js index ecc1eab..ff03f61 100644 --- a/server/index.js +++ b/server/index.js @@ -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); }); diff --git a/server/prisma/schema.prisma b/server/prisma/schema.prisma index 1b83cb0..40d0224 100644 --- a/server/prisma/schema.prisma +++ b/server/prisma/schema.prisma @@ -54,3 +54,8 @@ model ParseEvent { SubstitutionChange SubstitutionChange[] } + +model Class { + name String @id @unique + regex String +}