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

@@ -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 {

View File

@@ -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);
}