Generate a demo schedule if no schedule exists

This commit is contained in:
Hornwitser 2025-03-05 22:15:46 +01:00
parent f42dfcc13d
commit 228d75db72
2 changed files with 147 additions and 4 deletions

View file

@ -1,5 +1,6 @@
import { readFile, writeFile } from "node:fs/promises";
import { Schedule } from "~/shared/types/schedule";
import { generateDemoSchedule } from "./generate-demo-schedule";
// For this demo I'm just storing the runtime data in JSON files. When making
// this into proper application this should be replaced with an actual database.
@ -14,10 +15,12 @@ export async function readSchedule() {
} catch (err: any) {
if (err.code !== "ENOENT")
throw err;
// Use an empty schedule if nothing is stored yet.
schedule = {
locations: [],
events: [],
// Use the demo schedule if nothing is stored yet.
try {
schedule = generateDemoSchedule();
} catch (err) {
console.error(err);
throw err;
}
}
return schedule;;