✨ Add classes table and API enpoint
This commit is contained in:
@ -127,3 +127,17 @@ export async function getHistory(req, res) {
|
|||||||
});
|
});
|
||||||
res.send(changes);
|
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);
|
||||||
|
}
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
import express from "express";
|
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 app = express();
|
||||||
const port = process.send.PORT || 3000;
|
const port = process.send.PORT || 3000;
|
||||||
@ -7,6 +12,7 @@ const port = process.send.PORT || 3000;
|
|||||||
app.get("/api/timetable", getTimetable);
|
app.get("/api/timetable", getTimetable);
|
||||||
app.get("/api/substitutions", getSubstitutions);
|
app.get("/api/substitutions", getSubstitutions);
|
||||||
app.get("/api/history", getHistory);
|
app.get("/api/history", getHistory);
|
||||||
|
app.get("/api/classes", getClasses);
|
||||||
app.get("/api/*", (req, res) => {
|
app.get("/api/*", (req, res) => {
|
||||||
res.sendStatus(400);
|
res.sendStatus(400);
|
||||||
});
|
});
|
||||||
|
@ -54,3 +54,8 @@ model ParseEvent {
|
|||||||
|
|
||||||
SubstitutionChange SubstitutionChange[]
|
SubstitutionChange SubstitutionChange[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model Class {
|
||||||
|
name String @id @unique
|
||||||
|
regex String
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user