Implemented update event systems
This commit is contained in:
@@ -9,7 +9,7 @@ app.use(morgan('dev'))
|
||||
|
||||
app.use(cors({
|
||||
origin: ['https://aj17thdev.nexuszone.net', 'http://localhost:5173'], // your SPA origins
|
||||
credentials: true
|
||||
credentials: true,
|
||||
}));
|
||||
|
||||
app.use(express.json())
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Request, Response } from "express";
|
||||
import { createEvent, getEventAttendance, getEventDetails, getShortEventsInRange, setAttendanceStatus, setEventCancelled } from "../services/calendarService";
|
||||
import { createEvent, getEventAttendance, getEventDetails, getShortEventsInRange, setAttendanceStatus, setEventCancelled, updateEvent } from "../services/calendarService";
|
||||
import { CalendarAttendance, CalendarEvent } from "@app/shared/types/calendar";
|
||||
|
||||
const express = require('express');
|
||||
@@ -92,7 +92,6 @@ r.post('/', async (req: Request, res: Response) => {
|
||||
event.creator_id = member;
|
||||
event.start = new Date(event.start);
|
||||
event.end = new Date(event.end);
|
||||
console.log(event);
|
||||
createEvent(event);
|
||||
res.sendStatus(200);
|
||||
} catch (error) {
|
||||
@@ -101,5 +100,19 @@ r.post('/', async (req: Request, res: Response) => {
|
||||
}
|
||||
})
|
||||
|
||||
r.put('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
let event: CalendarEvent = req.body;
|
||||
event.start = new Date(event.start);
|
||||
event.end = new Date(event.end);
|
||||
console.log(event);
|
||||
updateEvent(event);
|
||||
res.sendStatus(200);
|
||||
} catch (error) {
|
||||
console.error('Failed to update event:', error);
|
||||
res.status(500).json(error);
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
module.exports.calendarRouter = r;
|
||||
@@ -34,7 +34,7 @@ export async function updateEvent(eventObject: CalendarEvent) {
|
||||
end = ?,
|
||||
location = ?,
|
||||
color = ?,
|
||||
description = ?,
|
||||
description = ?
|
||||
WHERE id = ?
|
||||
`;
|
||||
|
||||
@@ -54,7 +54,6 @@ export async function updateEvent(eventObject: CalendarEvent) {
|
||||
|
||||
export async function setEventCancelled(eventID: number, cancelled: boolean) {
|
||||
const input = cancelled ? 1 : 0;
|
||||
console.log(cancelled, input);
|
||||
const sql = `
|
||||
UPDATE calendar_events
|
||||
SET cancelled = ?
|
||||
@@ -73,7 +72,6 @@ export async function getShortEventsInRange(startDate: string, endDate: string):
|
||||
ORDER BY start ASC
|
||||
`;
|
||||
const res: CalendarEventShort[] = await pool.query(sql, [startDate, endDate]);
|
||||
console.log(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user