From 0ba42e6f788d0c8a3d8015c8a376bf1fd9c3f66e Mon Sep 17 00:00:00 2001 From: ajdj100 Date: Thu, 27 Nov 2025 19:53:31 -0500 Subject: [PATCH] finalized event cancel logic --- api/src/routes/calendar.ts | 25 ++++++++- api/src/services/calendarService.ts | 8 ++- ui/src/api/calendar.ts | 16 ++++-- .../calendar/CreateCalendarEvent.vue | 17 +++++- .../components/calendar/ViewCalendarEvent.vue | 56 ++++++++++++++++--- ui/src/pages/Calendar.vue | 6 +- 6 files changed, 106 insertions(+), 22 deletions(-) diff --git a/api/src/routes/calendar.ts b/api/src/routes/calendar.ts index f734468..f7b6acb 100644 --- a/api/src/routes/calendar.ts +++ b/api/src/routes/calendar.ts @@ -1,5 +1,5 @@ import { Request, Response } from "express"; -import { createEvent, getEventAttendance, getEventDetails, getShortEventsInRange, setAttendanceStatus } from "../services/calendarService"; +import { createEvent, getEventAttendance, getEventDetails, getShortEventsInRange, setAttendanceStatus, setEventCancelled } from "../services/calendarService"; import { CalendarAttendance, CalendarEvent } from "@app/shared/types/calendar"; const express = require('express'); @@ -35,6 +35,28 @@ r.get('/upcoming', async (req, res) => { res.sendStatus(501); }) +r.post('/:id/cancel', async (req: Request, res: Response) => { + try { + const eventID = Number(req.params.id); + setEventCancelled(eventID, true); + res.sendStatus(200); + } catch (error) { + console.error('Error setting cancel status:', error); + res.status(500).send('Error setting cancel status'); + } +}) +r.post('/:id/uncancel', async (req: Request, res: Response) => { + try { + const eventID = Number(req.params.id); + setEventCancelled(eventID, false); + res.sendStatus(200); + } catch (error) { + console.error('Error setting cancel status:', error); + res.status(500).send('Error setting cancel status'); + } +}) + + r.post('/:id/attendance', async (req: Request, res: Response) => { try { let member = req.user.id; @@ -78,4 +100,5 @@ r.post('/', async (req: Request, res: Response) => { } }) + module.exports.calendarRouter = r; \ No newline at end of file diff --git a/api/src/services/calendarService.ts b/api/src/services/calendarService.ts index ce4e805..657bcbf 100644 --- a/api/src/services/calendarService.ts +++ b/api/src/services/calendarService.ts @@ -52,13 +52,15 @@ export async function updateEvent(eventObject: CalendarEvent) { return { success: true }; } -export async function cancelEvent(eventID: number) { +export async function setEventCancelled(eventID: number, cancelled: boolean) { + const input = cancelled ? 1 : 0; + console.log(cancelled, input); const sql = ` UPDATE calendar_events - SET cancelled = 1 + SET cancelled = ? WHERE id = ? `; - await pool.query(sql, [eventID]); + await pool.query(sql, [input, eventID]); return { success: true }; } diff --git a/ui/src/api/calendar.ts b/ui/src/api/calendar.ts index 35c10f0..6c10c2b 100644 --- a/ui/src/api/calendar.ts +++ b/ui/src/api/calendar.ts @@ -86,12 +86,20 @@ export async function editCalendarEvent(eventData: CalendarEvent) { } -export async function cancelCalendarEvent(eventID: number) { +export async function setCancelCalendarEvent(eventID: number, cancel: boolean) { + let route = cancel ? "cancel" : "uncancel"; -} - -export async function adminCancelCalendarEvent(eventID: number) { + console.log(route); + let res = await fetch(`${addr}/calendar/${eventID}/${route}`, { + method: "POST", + credentials: "include" + }); + if (res.ok) { + return; + } else { + throw new Error(`Failed to set attendance: ${res.status} ${res.statusText}`); + } } export async function setCalendarEventAttendance(eventID: number, state: CalendarAttendance) { diff --git a/ui/src/components/calendar/CreateCalendarEvent.vue b/ui/src/components/calendar/CreateCalendarEvent.vue index 62d812c..a2a407b 100644 --- a/ui/src/components/calendar/CreateCalendarEvent.vue +++ b/ui/src/components/calendar/CreateCalendarEvent.vue @@ -49,12 +49,23 @@ import { createCalendarEvent } from "@/api/calendar" const formSchema = toTypedSchema(calendarEventSchema) // ---------- dialog state & defaults ---------- +const clickedDate = ref(null); const dialogOpen = ref(false) -function openDialog() { dialogOpen.value = true } +function openDialog(dateStr?: string) { + clickedDate.value=dateStr ?? null; + dialogOpen.value = true + initialValues.value = makeInitialValues() +} defineExpose({ openDialog }) function makeInitialValues() { - const start = roundToNextHour() + let start: Date; + if (clickedDate.value) { + const local = new Date(clickedDate.value + "T00:00:00"); + start = roundToNextHour(local); + } else { + start = roundToNextHour(); + } const end = new Date(start.getTime() + 60 * 60 * 1000) return { name: "", @@ -68,7 +79,7 @@ function makeInitialValues() { id: null as number | null, } } -const initialValues = ref(makeInitialValues()) +const initialValues = ref(null) const formKey = ref(0) diff --git a/ui/src/components/calendar/ViewCalendarEvent.vue b/ui/src/components/calendar/ViewCalendarEvent.vue index 1d67e26..f769cc9 100644 --- a/ui/src/components/calendar/ViewCalendarEvent.vue +++ b/ui/src/components/calendar/ViewCalendarEvent.vue @@ -1,12 +1,16 @@