owltide/server/api/create-event.post.ts
Hornwitser c986d939ec Read vapid details from runtime config
Use the useRuntimeConfig interface to read vapid details on the server
side.  This is a more portale way to deal with loading data from the
environment in Nuxt.js.
2025-05-20 00:22:28 +02:00

31 lines
972 B
TypeScript

import { Schedule } from "~/shared/types/schedule";
import { broadcastUpdate } from "~/server/streams";
import { sendPush } from "~/server/web-push";
import { readSchedule, writeSchedule } from "~/server/database";
export default defineEventHandler(async (event) => {
const formData = await readFormData(event);
const schedule: Schedule = await readSchedule();
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],
}
]
});
await broadcastUpdate(schedule);
await writeSchedule(schedule);
await sendPush(event, "New event", `${name} will start at ${start}`);
});