Fixed application acceptance not setting state correctly

This commit is contained in:
2026-02-08 00:49:23 -05:00
parent 2789b79b82
commit f77f5b5a7f
3 changed files with 36 additions and 10 deletions

View File

@@ -225,15 +225,29 @@ router.post('/approve/:id', [requireLogin, requireRole("Recruiter")], async (req
const appID = Number(req.params.id);
const approved_by = req.user.id;
const app = await getApplicationByID(appID);
try {
const app = await getApplicationByID(appID);
await approveApplication(appID, approved_by);
console.log("HELLO MFS")
var con = await pool.getConnection();
console.log("START")
con.beginTransaction();
console.log("APPROVE")
await approveApplication(appID, approved_by, con);
console.log("STATE")
//update user profile
await setUserState(app.member_id, MemberState.Member, "Application Accepted", approved_by);
await setUserState(app.member_id, MemberState.Member, "Application Accepted", approved_by, con);
await pool.query('CALL sp_accept_new_recruit_validation(?, ?, ?, ?)', [Number(process.env.CONFIG_ID), app.member_id, approved_by, approved_by])
console.log("SP")
await con.query('CALL sp_accept_new_recruit_validation(?, ?, ?, ?)', [Number(process.env.CONFIG_ID), app.member_id, approved_by, approved_by])
console.log("COMMIT")
con.commit();
logger.info('app', "Member application approved", {
application: app.id,
applicant: app.member_id,
@@ -241,6 +255,9 @@ router.post('/approve/:id', [requireLogin, requireRole("Recruiter")], async (req
})
res.sendStatus(200);
} catch (error) {
con.rollback();
logger.error(
'app',
'Failed to approve application',
@@ -251,6 +268,8 @@ router.post('/approve/:id', [requireLogin, requireRole("Recruiter")], async (req
}
);
res.status(500).json({ error: 'Failed to approve application' });
} finally {
if (con) con.release();
}
});