Merge branch 'main' into homepage/welcome

This commit is contained in:
2025-12-16 23:44:50 -05:00
7 changed files with 73 additions and 28 deletions

View File

@@ -56,9 +56,13 @@ router.get("/me", async (req: Request, res: Response) => {
//get my LOA history
router.get("/history", async (req: Request, res: Response) => {
const user = req.user.id;
try {
const result = await getUserLOA(user);
const user = req.user.id;
const page = Number(req.query.page) || undefined;
const pageSize = Number(req.query.pageSize) || undefined;
const result = await getUserLOA(user, page, pageSize);
res.status(200).json(result)
} catch (error) {
console.error(error);

View File

@@ -32,6 +32,8 @@ export async function getApplicationByID(appID: number): Promise<ApplicationRow>
}
export async function getApplicationList(page: number = 1, pageSize: number = 25): Promise<ApplicationListRow[]> {
const offset = (page - 1) * pageSize;
const sql = `SELECT
member.name AS member_name,
app.id,
@@ -44,7 +46,7 @@ export async function getApplicationList(page: number = 1, pageSize: number = 25
ORDER BY app.submitted_at DESC
LIMIT ? OFFSET ?;`
const rows: ApplicationListRow[] = await pool.query(sql, [pageSize, page]);
const rows: ApplicationListRow[] = await pool.query(sql, [pageSize, offset]);
return rows;
}

View File

@@ -36,7 +36,10 @@ export async function getAllLOA(page = 1, pageSize = 10): Promise<PagedData<LOAR
return output;
}
export async function getUserLOA(userId: number): Promise<LOARequest[]> {
export async function getUserLOA(userId: number, page = 1, pageSize = 10): Promise<PagedData<LOARequest>> {
const offset = (page - 1) * pageSize;
const result: LOARequest[] = await pool.query(`
SELECT loa.*, members.name, t.name AS type_name
FROM leave_of_absences AS loa
@@ -53,8 +56,12 @@ export async function getUserLOA(userId: number): Promise<LOARequest[]> {
WHEN loa.closed IS NOT NULL THEN 4
END,
loa.start_date DESC
`, [userId])
return result;
LIMIT ? OFFSET ?;`, [userId, pageSize, offset])
let loaCount = Number((await pool.query(`SELECT COUNT(*) as count FROM leave_of_absences WHERE member_id = ?;`, [userId]))[0].count);
let pageCount = loaCount / pageSize;
let output: PagedData<LOARequest> = { data: result, pagination: { page: page, pageSize: pageSize, total: loaCount, totalPages: pageCount } }
return output;
}
export async function getUserActiveLOA(userId: number): Promise<LOARequest[]> {