added support for getting all training reports

This commit is contained in:
2025-11-16 10:15:52 -05:00
parent 810a15d279
commit 4d0dea553e
2 changed files with 17 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
import { CourseAttendee, CourseEventDetails } from "@app/shared/types/course";
import { getAllCourses, getCourseEventAttendees, getCourseEventDetails, insertCourseEvent } from "../services/CourseSerivce";
import { getAllCourses, getCourseEventAttendees, getCourseEventDetails, getCourseEvents, insertCourseEvent } from "../services/CourseSerivce";
import { Request, Response, Router } from "express";
const courseRouter = Router();
@@ -15,6 +15,16 @@ courseRouter.get('/', async (req, res) => {
}
})
eventRouter.get('/', async (req: Request, res: Response) => {
try {
let events: CourseEventDetails[] = await getCourseEvents();
res.status(200).json(events);
} catch (error) {
console.error('failed to fetch reports', error);
res.status(500).json(error);
}
});
eventRouter.get('/:id', async (req: Request, res: Response) => {
try {
let out = await getCourseEventDetails(Number(req.params.id));

View File

@@ -84,4 +84,10 @@ export async function insertCourseEvent(event: CourseEventDetails): Promise<numb
await con.release();
return eventID;
}
}
export async function getCourseEvents(): Promise<CourseEventDetails[]> {
const sql = "SELECT * FROM course_events;";
let events: CourseEventDetails[] = await pool.query(sql);
return events;
}