Nuxt is based on Vue.js and I find their building blocks to be much neater compared to the React based Next.js.
16 lines
651 B
TypeScript
16 lines
651 B
TypeScript
import { Schedule } from "~/shared/types/schedule";
|
|
import { readFile, writeFile } from "fs/promises";
|
|
import { broadcastUpdate } from "~/server/streams";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const formData = await readFormData(event);
|
|
const schedule: Schedule = JSON.parse(await readFile("schedule.json", "utf-8"));
|
|
const id = formData.get("id") as string;
|
|
const index = schedule.events.findIndex(event => event.id === id);
|
|
if (index === -1) {
|
|
throw Error("No such event");
|
|
}
|
|
schedule.events.splice(index, 1);
|
|
broadcastUpdate(schedule);
|
|
await writeFile("schedule.json", JSON.stringify(schedule, null, "\t"), "utf-8");
|
|
});
|