added support for getting all training reports
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { CourseAttendee, CourseEventDetails } from "@app/shared/types/course";
|
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";
|
import { Request, Response, Router } from "express";
|
||||||
|
|
||||||
const courseRouter = Router();
|
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) => {
|
eventRouter.get('/:id', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
let out = await getCourseEventDetails(Number(req.params.id));
|
let out = await getCourseEventDetails(Number(req.params.id));
|
||||||
|
|||||||
@@ -84,4 +84,10 @@ export async function insertCourseEvent(event: CourseEventDetails): Promise<numb
|
|||||||
await con.release();
|
await con.release();
|
||||||
return eventID;
|
return eventID;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getCourseEvents(): Promise<CourseEventDetails[]> {
|
||||||
|
const sql = "SELECT * FROM course_events;";
|
||||||
|
let events: CourseEventDetails[] = await pool.query(sql);
|
||||||
|
return events;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user