Add support for multiple remote timetables

- Add timetable "title" column to db
- Make API return array of timetables
- Add settings page for selecting a timetable
- Add InfoCard if no timetable is selected
This commit is contained in:
2023-06-18 14:30:36 +02:00
parent dac0d09167
commit 48364d4c59
10 changed files with 176 additions and 30 deletions

View File

@ -13,7 +13,7 @@ export async function getTimetable(req, res) {
return;
}
const requestedClass = req.query.class.toLowerCase();
const timetable = await prisma.timetable.findFirst({
const timetables = await prisma.timetable.findMany({
where: {
class: requestedClass,
},
@ -22,19 +22,9 @@ export async function getTimetable(req, res) {
},
});
const times = await prisma.time.findMany();
if (!timetable) {
res.status(404).send({
success: false,
error: "no_timetable",
message: "No timetable was found for this class",
});
return;
}
res.send({
trusted: timetable.trusted,
source: timetable.source,
data: timetable.data,
times: times,
timetables,
times,
});
}

View File

@ -9,6 +9,7 @@ datasource db {
model Timetable {
id Int @id @unique @default(autoincrement())
title String @default("Default")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
class String