hooked up create event

This commit is contained in:
2025-11-27 13:08:33 -05:00
parent 4dc121c018
commit 81716d4a4f
6 changed files with 80 additions and 51 deletions

View File

@@ -1,5 +1,5 @@
import { Request, Response } from "express";
import { getEventAttendance, getEventDetails, getShortEventsInRange, setAttendanceStatus } from "../services/calendarService";
import { createEvent, getEventAttendance, getEventDetails, getShortEventsInRange, setAttendanceStatus } from "../services/calendarService";
import { CalendarAttendance, CalendarEvent } from "@app/shared/types/calendar";
const express = require('express');
@@ -63,9 +63,18 @@ r.get('/:id', async (req: Request, res: Response) => {
})
//post a new calendar event
r.post('/', async (req, res) => {
//post a new calendar event
r.post('/', async (req: Request, res: Response) => {
try {
const member = req.user.id;
let event: CalendarEvent = req.body;
console.log(event);
createEvent(event);
res.sendStatus(200);
} catch (error) {
console.error('Failed to create event:', error);
res.status(500).json(error);
}
})
module.exports.calendarRouter = r;

View File

@@ -1,11 +1,12 @@
import pool from '../db';
import { CalendarEventShort, CalendarSignup, CalendarEvent, CalendarAttendance } from "@app/shared/types/calendar"
import { toDateTime } from "@app/shared/utils/time"
export async function createEvent(eventObject: Omit<CalendarEvent, 'id' | 'created_at' | 'updated_at' | 'cancelled'>) {
const sql = `
INSERT INTO calendar_events
(name, start, end, location, color, description, creator)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
VALUES (?, ?, ?, ?, ?, ?, ?)
`;
const params = [
eventObject.name,
@@ -40,8 +41,8 @@ export async function updateEvent(eventObject: CalendarEvent) {
const params = [
eventObject.name,
eventObject.start,
eventObject.end,
toDateTime(eventObject.start),
toDateTime(eventObject.end),
eventObject.location,
eventObject.color,
eventObject.description ?? null,