finalized event cancel logic

This commit is contained in:
2025-11-27 19:53:31 -05:00
parent 33fcb16427
commit 0ba42e6f78
6 changed files with 106 additions and 22 deletions

View File

@@ -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;

View File

@@ -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 };
}