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 {
|
try {
|
||||||
const app = await getApplicationByID(appID);
|
const app = await getApplicationByID(appID);
|
||||||
const result = await approveApplication(appID);
|
await approveApplication(appID, approved_by);
|
||||||
|
|
||||||
//guard against failures
|
|
||||||
if (result.affectedRows != 1) {
|
|
||||||
throw new Error("Something went wrong approving the application");
|
|
||||||
}
|
|
||||||
|
|
||||||
//update user profile
|
//update user profile
|
||||||
await setUserState(app.member_id, MemberState.Member);
|
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])
|
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);
|
res.sendStatus(200);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Approve failed:', err);
|
console.error('Approve failed:', err);
|
||||||
@@ -178,12 +170,13 @@ router.post('/approve/:id', [requireLogin, requireRole("Recruiter")], async (req
|
|||||||
});
|
});
|
||||||
|
|
||||||
// POST /application/deny/:id
|
// POST /application/deny/:id
|
||||||
router.post('/deny/:id', [requireLogin, requireRole("Recruiter")], async (req, res) => {
|
router.post('/deny/:id', [requireLogin, requireRole("Recruiter")], async (req: Request, res: Response) => {
|
||||||
const appID = req.params.id;
|
const appID = Number(req.params.id);
|
||||||
|
const approver = Number(req.user.id);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const app = await getApplicationByID(appID);
|
const app = await getApplicationByID(appID);
|
||||||
await denyApplication(appID);
|
await denyApplication(appID, approver);
|
||||||
await setUserState(app.member_id, MemberState.Denied);
|
await setUserState(app.member_id, MemberState.Denied);
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
} catch (err) {
|
} 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 = `
|
const sql = `
|
||||||
UPDATE applications
|
UPDATE applications
|
||||||
SET approved_at = NOW()
|
SET approved_at = NOW(), approved_by = ?
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
AND approved_at IS NULL
|
AND approved_at IS NULL
|
||||||
AND denied_at IS NULL
|
AND denied_at IS NULL
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const result = await pool.execute(sql, id);
|
const result = await pool.execute(sql, [approver, id]);
|
||||||
return result;
|
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 = `
|
const sql = `
|
||||||
UPDATE applications
|
UPDATE applications
|
||||||
SET denied_at = NOW()
|
SET denied_at = NOW(), approved_by = ?
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
AND approved_at IS NULL
|
AND approved_at IS NULL
|
||||||
AND denied_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) {
|
if (result.affectedRows == 1) {
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user