Hooked up calendar viewing to API, still needs a lot more polish

This commit is contained in:
2025-11-23 17:00:47 -05:00
parent b8bf809c14
commit 531371d059
11 changed files with 312 additions and 240 deletions

View File

@@ -1,4 +1,6 @@
import { Request, Response } from "express";
import { getEventAttendance, getEventDetails, getShortEventsInRange } from "../services/calendarService";
import { CalendarEvent } from "@app/shared/types/calendar";
const express = require('express');
const r = express.Router();
@@ -9,16 +11,24 @@ function addMonths(date: Date, months: number): Date {
return d
}
//get calendar events paged
//get calendar events paged, requires a query string with from= and to= as mariadb ISO strings
r.get('/', async (req, res) => {
const viewDate: Date = req.body.date;
//generate date range
const backDate: Date = addMonths(viewDate, -1);
const frontDate: Date = addMonths(viewDate, 2);
try {
const fromDate: string = req.query.from;
const toDate: string = req.query.to;
const events = getShortEventsInRange(backDate, frontDate);
if (fromDate === undefined || toDate === undefined) {
res.status(400).send("Missing required query parameters 'from' and 'to'");
return;
}
res.status(200).json(events);
const events = await getShortEventsInRange(fromDate, toDate);
res.status(200).json(events);
} catch (error) {
console.error('Error fetching calendar events:', error);
res.status(500).send('Error fetching calendar events');
}
});
r.get('/upcoming', async (req, res) => {
@@ -26,19 +36,17 @@ r.get('/upcoming', async (req, res) => {
})
//get event details
r.get('/:id', async (req, res) => {
r.get('/:id', async (req: Request, res: Response) => {
try {
const eventID: number = req.params.id;
const eventID: number = Number(req.params.id);
let details = getEventDetails(eventID);
let attendance = await getEventAttendance(eventID);
let out = { ...details, attendance }
console.log(out);
res.status(200).json(out);
let details: CalendarEvent = await getEventDetails(eventID);
details.eventSignups = await getEventAttendance(eventID);
console.log(details);
res.status(200).json(details);
} catch (err) {
console.error('Insert failed:', err);
res.status(500).json(err);
res.status(500).json(err);
}
})
@@ -47,4 +55,4 @@ r.post('/', async (req, res) => {
})
module.exports.calendar = r;
module.exports.calendarRouter = r;