added service with base function to get course and event attendees
This commit is contained in:
43
api/src/routes/course.ts
Normal file
43
api/src/routes/course.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { CourseAttendee } from "@app/shared/types/course";
|
||||
import { getAllCourses, getCourseAttendees } from "../services/CourseSerivce";
|
||||
import { Request, Response, Router } from "express";
|
||||
|
||||
const courseRouter = Router();
|
||||
const eventRouter = Router();
|
||||
|
||||
courseRouter.get('/', async (req, res) => {
|
||||
try {
|
||||
const courses = await getAllCourses();
|
||||
res.status(200).json(courses);
|
||||
} catch (err) {
|
||||
console.error('failed to fetch courses', err);
|
||||
res.status(500).json('failed to fetch courses\n' + err);
|
||||
}
|
||||
})
|
||||
|
||||
eventRouter.get('/attendees/:id', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const attendees: CourseAttendee[] = await getCourseAttendees(Number(req.params.id));
|
||||
res.status(200).json(attendees);
|
||||
} catch (err) {
|
||||
console.error('failed to fetch attendees', err);
|
||||
res.status(500).json("failed to fetch attendees\n" + err);
|
||||
}
|
||||
})
|
||||
|
||||
// //insert a new latest rank for a user
|
||||
// ur.post('/', async (req, res) => {
|
||||
|
||||
// try {
|
||||
// const change = req.body?.change;
|
||||
// await insertMemberRank(change.member_id, change.rank_id, change.date);
|
||||
|
||||
// res.sendStatus(201);
|
||||
// } catch (err) {
|
||||
// console.error('Insert failed:', err);
|
||||
// res.status(500).json({ error: 'Failed to update ranks' });
|
||||
// }
|
||||
// });
|
||||
|
||||
module.exports.courseRouter = courseRouter;
|
||||
module.exports.eventRouter = eventRouter;
|
||||
Reference in New Issue
Block a user