fixed error on approve/deny applications
This commit is contained in:
@@ -155,21 +155,13 @@ router.post('/approve/:id', [requireLogin, requireRole("Recruiter")], async (req
|
||||
|
||||
try {
|
||||
const app = await getApplicationByID(appID);
|
||||
const result = await approveApplication(appID);
|
||||
|
||||
//guard against failures
|
||||
if (result.affectedRows != 1) {
|
||||
throw new Error("Something went wrong approving the application");
|
||||
}
|
||||
await approveApplication(appID, approved_by);
|
||||
|
||||
//update user profile
|
||||
await setUserState(app.member_id, MemberState.Member);
|
||||
|
||||
await pool.query('CALL sp_accept_new_recruit_validation(?, ?, ?, ?)', [Number(process.env.CONFIG_ID), app.member_id, approved_by, approved_by])
|
||||
// let nextRank = await getRankByName('Recruit')
|
||||
// await insertMemberRank(app.member_id, nextRank.id);
|
||||
// //assign user to "pending basic"
|
||||
// await assignUserToStatus(app.member_id, 1);
|
||||
|
||||
res.sendStatus(200);
|
||||
} catch (err) {
|
||||
console.error('Approve failed:', err);
|
||||
@@ -178,12 +170,13 @@ router.post('/approve/:id', [requireLogin, requireRole("Recruiter")], async (req
|
||||
});
|
||||
|
||||
// POST /application/deny/:id
|
||||
router.post('/deny/:id', [requireLogin, requireRole("Recruiter")], async (req, res) => {
|
||||
const appID = req.params.id;
|
||||
router.post('/deny/:id', [requireLogin, requireRole("Recruiter")], async (req: Request, res: Response) => {
|
||||
const appID = Number(req.params.id);
|
||||
const approver = Number(req.user.id);
|
||||
|
||||
try {
|
||||
const app = await getApplicationByID(appID);
|
||||
await denyApplication(appID);
|
||||
await denyApplication(appID, approver);
|
||||
await setUserState(app.member_id, MemberState.Denied);
|
||||
res.sendStatus(200);
|
||||
} catch (err) {
|
||||
|
||||
@@ -59,30 +59,35 @@ export async function getAllMemberApplications(memberID: number): Promise<Applic
|
||||
}
|
||||
|
||||
|
||||
export async function approveApplication(id: number) {
|
||||
export async function approveApplication(id: number, approver: number) {
|
||||
const sql = `
|
||||
UPDATE applications
|
||||
SET approved_at = NOW()
|
||||
SET approved_at = NOW(), approved_by = ?
|
||||
WHERE id = ?
|
||||
AND approved_at IS NULL
|
||||
AND denied_at IS NULL
|
||||
`;
|
||||
|
||||
const result = await pool.execute(sql, id);
|
||||
return result;
|
||||
const result = await pool.execute(sql, [approver, id]);
|
||||
console.log(result);
|
||||
if (result.affectedRows == 1) {
|
||||
return
|
||||
} else {
|
||||
throw new Error(`"Something went wrong approving application with ID ${id}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function denyApplication(id: number) {
|
||||
export async function denyApplication(id: number, approver: number) {
|
||||
const sql = `
|
||||
UPDATE applications
|
||||
SET denied_at = NOW()
|
||||
SET denied_at = NOW(), approved_by = ?
|
||||
WHERE id = ?
|
||||
AND approved_at IS NULL
|
||||
AND denied_at IS NULL
|
||||
`;
|
||||
|
||||
const result = await pool.execute(sql, id);
|
||||
|
||||
const result = await pool.execute(sql, [approver, id]);
|
||||
console.log(result);
|
||||
if (result.affectedRows == 1) {
|
||||
return
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user