implemented pagination for training reports

This commit is contained in:
2025-12-16 00:23:59 -05:00
parent 627f6bfe3d
commit 9e469013c7
4 changed files with 132 additions and 38 deletions

View File

@@ -33,23 +33,26 @@ cr.get('/roles', async (req, res) => {
})
er.get('/', async (req: Request, res: Response) => {
const allowedSorts = new Map([
["ascending", "ASC"],
["descending", "DESC"]
]);
const sort = String(req.query.sort || "").toLowerCase();
const search = String(req.query.search || "").toLowerCase();
if (!allowedSorts.has(sort)) {
return res.status(400).json({
message: `Invalid sort direction '${req.query.sort}'. Allowed values are 'ascending' or 'descending'.`
});
}
const sortDir = allowedSorts.get(sort);
try {
let events = await getCourseEvents(sortDir, search);
const allowedSorts = new Map([
["ascending", "ASC"],
["descending", "DESC"]
]);
const page = Number(req.query.page) || undefined;
const pageSize = Number(req.query.pageSize) || undefined;
const sort = String(req.query.sort || "").toLowerCase();
const search = String(req.query.search || "").toLowerCase();
if (!allowedSorts.has(sort)) {
return res.status(400).json({
message: `Invalid sort direction '${req.query.sort}'. Allowed values are 'ascending' or 'descending'.`
});
}
const sortDir = allowedSorts.get(sort);
let events = await getCourseEvents(sortDir, search, page, pageSize);
res.status(200).json(events);
} catch (error) {
console.error('failed to fetch reports', error);