#179-suspensions #188
@@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { ApplicationListRow, ApplicationRow, CommentRow } from "@app/shared/types/application";
|
||||
import pool from "../../db";
|
||||
import { error } from "console";
|
||||
import * as mariadb from 'mariadb';
|
||||
|
||||
|
||||
/**
|
||||
* 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 = `
|
||||
UPDATE applications
|
||||
SET approved_at = NOW(), approved_by = ?
|
||||
@@ -81,7 +83,7 @@ export async function approveApplication(id: number, approver: number) {
|
||||
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) {
|
||||
return
|
||||
} else {
|
||||
|
||||
@@ -99,9 +99,13 @@ export async function getUserData(userID: number): Promise<Member> {
|
||||
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 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 {
|
||||
if (isInternalConn) await con.beginTransaction();
|
||||
@@ -246,12 +250,13 @@ export async function endLatestMemberState(memberID: number, con: mariadb.Pool |
|
||||
try {
|
||||
let res = await con.query(sql, [memberID]);
|
||||
console.log(res);
|
||||
return;
|
||||
} catch (error) {
|
||||
logger.error('app', 'Error ending latest member state', {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
let res = await pool.query(sql, [memberID]);
|
||||
console.log(res);
|
||||
// let res = await pool.query(sql, [memberID]);
|
||||
// console.log(res);
|
||||
}
|
||||
Reference in New Issue
Block a user