Port application from Next.js to Nuxt
Nuxt is based on Vue.js and I find their building blocks to be much neater compared to the React based Next.js.
This commit is contained in:
parent
8c8b561f1a
commit
250ca9a1ac
45 changed files with 662 additions and 1358 deletions
31
server/api/create-event.post.ts
Normal file
31
server/api/create-event.post.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { Schedule } from "~/shared/types/schedule";
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { broadcastUpdate } from "~/server/streams";
|
||||
import { sendPush } from "~/server/web-push";
|
||||
|
||||
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 name = formData.get("name") as string;
|
||||
const description = formData.get("description") as string;
|
||||
const start = formData.get("start") as string;
|
||||
const end = formData.get("end") as string;
|
||||
const location = formData.get("location") as string;
|
||||
schedule.events.push({
|
||||
name,
|
||||
id,
|
||||
description,
|
||||
slots: [
|
||||
{
|
||||
id: `${id}-1`,
|
||||
start: start + "Z",
|
||||
end: end + "Z",
|
||||
locations: [location],
|
||||
}
|
||||
]
|
||||
});
|
||||
broadcastUpdate(schedule);
|
||||
await writeFile("schedule.json", JSON.stringify(schedule, null, "\t"), "utf-8");
|
||||
await sendPush("New event", `${name} will start at ${start}`);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue