Fixed application acceptance not setting state correctly
This commit is contained in:
@@ -225,15 +225,29 @@ router.post('/approve/:id', [requireLogin, requireRole("Recruiter")], async (req
|
|||||||
const appID = Number(req.params.id);
|
const appID = Number(req.params.id);
|
||||||
const approved_by = req.user.id;
|
const approved_by = req.user.id;
|
||||||
|
|
||||||
|
const app = await getApplicationByID(appID);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const app = await getApplicationByID(appID);
|
console.log("HELLO MFS")
|
||||||
await approveApplication(appID, approved_by);
|
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
|
//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", {
|
logger.info('app', "Member application approved", {
|
||||||
application: app.id,
|
application: app.id,
|
||||||
applicant: app.member_id,
|
applicant: app.member_id,
|
||||||
@@ -241,6 +255,9 @@ router.post('/approve/:id', [requireLogin, requireRole("Recruiter")], async (req
|
|||||||
})
|
})
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
|
con.rollback();
|
||||||
|
|
||||||
logger.error(
|
logger.error(
|
||||||
'app',
|
'app',
|
||||||
'Failed to approve application',
|
'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' });
|
res.status(500).json({ error: 'Failed to approve application' });
|
||||||
|
} finally {
|
||||||
|
if (con) con.release();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { ApplicationListRow, ApplicationRow, CommentRow } from "@app/shared/types/application";
|
import { ApplicationListRow, ApplicationRow, CommentRow } from "@app/shared/types/application";
|
||||||
import pool from "../../db";
|
import pool from "../../db";
|
||||||
import { error } from "console";
|
import { error } from "console";
|
||||||
|
import * as mariadb from 'mariadb';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an application in the db
|
* Create an application in the db
|
||||||
@@ -72,7 +74,7 @@ export async function getAllMemberApplications(memberID: number): Promise<Applic
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function approveApplication(id: number, approver: number) {
|
export async function approveApplication(id: number, approver: number, con: mariadb.Connection | mariadb.Pool = pool) {
|
||||||
const sql = `
|
const sql = `
|
||||||
UPDATE applications
|
UPDATE applications
|
||||||
SET approved_at = NOW(), approved_by = ?
|
SET approved_at = NOW(), approved_by = ?
|
||||||
@@ -81,7 +83,7 @@ export async function approveApplication(id: number, approver: number) {
|
|||||||
AND denied_at IS NULL
|
AND denied_at IS NULL
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const result = await pool.execute(sql, [approver, id]);
|
const result = await con.query(sql, [approver, id]);
|
||||||
if (result.affectedRows == 1) {
|
if (result.affectedRows == 1) {
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -99,9 +99,13 @@ export async function getUserData(userID: number): Promise<Member> {
|
|||||||
return res[0] ?? null;
|
return res[0] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setUserState(userID: number, state: MemberState, reason: string, creatorID: number, externalCon?: mariadb.Connection | mariadb.PoolConnection) {
|
export async function setUserState(userID: number, state: MemberState, reason: string, creatorID: number, externalCon?: mariadb.PoolConnection) {
|
||||||
const isInternalConn = !externalCon;
|
const isInternalConn = !externalCon;
|
||||||
const con = (externalCon || await pool.getConnection()) as mariadb.PoolConnection;
|
if(isInternalConn)
|
||||||
|
var con = await pool.getConnection();
|
||||||
|
else
|
||||||
|
var con = externalCon;
|
||||||
|
// const con = (externalCon || await pool.getConnection()) as mariadb.PoolConnection;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isInternalConn) await con.beginTransaction();
|
if (isInternalConn) await con.beginTransaction();
|
||||||
@@ -246,12 +250,13 @@ export async function endLatestMemberState(memberID: number, con: mariadb.Pool |
|
|||||||
try {
|
try {
|
||||||
let res = await con.query(sql, [memberID]);
|
let res = await con.query(sql, [memberID]);
|
||||||
console.log(res);
|
console.log(res);
|
||||||
|
return;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('app', 'Error ending latest member state', {
|
logger.error('app', 'Error ending latest member state', {
|
||||||
error: error instanceof Error ? error.message : String(error),
|
error: error instanceof Error ? error.message : String(error),
|
||||||
});
|
});
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
let res = await pool.query(sql, [memberID]);
|
// let res = await pool.query(sql, [memberID]);
|
||||||
console.log(res);
|
// console.log(res);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user