integrated the new logger across the entire API
This commit is contained in:
@@ -46,29 +46,64 @@ router.get('/coc', async (req: Request, res: Response) => {
|
||||
|
||||
// POST /application
|
||||
router.post('/', [requireLogin], async (req, res) => {
|
||||
const memberID = req.user.id;
|
||||
const App = req.body?.App || {};
|
||||
const appVersion = 1;
|
||||
|
||||
try {
|
||||
const App = req.body?.App || {};
|
||||
const memberID = req.user.id;
|
||||
req.profiler?.start('createApplication');
|
||||
await createApplication(memberID, appVersion, JSON.stringify(App));
|
||||
req.profiler?.end('createApplication');
|
||||
|
||||
const appVersion = 1;
|
||||
|
||||
await createApplication(memberID, appVersion, JSON.stringify(App))
|
||||
req.profiler?.start('setUserState');
|
||||
await setUserState(memberID, MemberState.Applicant);
|
||||
req.profiler?.end('setUserState');
|
||||
|
||||
res.sendStatus(201);
|
||||
|
||||
// Log full route profiling
|
||||
const summary = req.profiler?.summary();
|
||||
if (summary) {
|
||||
logger.info(
|
||||
'profiling',
|
||||
'POST /application completed',
|
||||
{
|
||||
memberID,
|
||||
appVersion,
|
||||
...summary,
|
||||
},
|
||||
'profiling'
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to create application: \n', err);
|
||||
logger.error(
|
||||
'app',
|
||||
'Failed to create application',
|
||||
{
|
||||
memberID,
|
||||
error: err instanceof Error ? err.message : String(err),
|
||||
stack: err instanceof Error ? err.stack : undefined,
|
||||
}
|
||||
);
|
||||
res.status(500).json({ error: 'Failed to create application' });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// GET /application/all
|
||||
router.get('/all', [requireLogin, requireRole("Recruiter")], async (req, res) => {
|
||||
try {
|
||||
const rows = await getApplicationList();
|
||||
res.status(200).json(rows);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
logger.error(
|
||||
'app',
|
||||
'Failed to get applications',
|
||||
{
|
||||
error: err instanceof Error ? err.message : String(err),
|
||||
stack: err instanceof Error ? err.stack : undefined,
|
||||
}
|
||||
);
|
||||
res.status(500);
|
||||
}
|
||||
});
|
||||
@@ -82,8 +117,16 @@ router.get('/meList', async (req, res) => {
|
||||
|
||||
return res.status(200).json(application);
|
||||
} catch (error) {
|
||||
console.error('Failed to load applications: \n', error);
|
||||
return res.status(500).json(error);
|
||||
logger.error(
|
||||
'app',
|
||||
'Failed to get applications for user',
|
||||
{
|
||||
user: userID,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
}
|
||||
);
|
||||
return res.status(500);
|
||||
}
|
||||
})
|
||||
|
||||
@@ -108,12 +151,20 @@ router.get('/me', [requireLogin], async (req, res) => {
|
||||
|
||||
return res.status(200).json(output);
|
||||
} catch (error) {
|
||||
console.error('Failed to load application:', error);
|
||||
logger.error(
|
||||
'app',
|
||||
'Failed to load application',
|
||||
{
|
||||
user: userID,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
}
|
||||
);
|
||||
return res.status(500).json(error);
|
||||
}
|
||||
})
|
||||
|
||||
// GET /application/:id
|
||||
// GET /me/:id
|
||||
router.get('/me/:id', [requireLogin], async (req: Request, res: Response) => {
|
||||
let appID = Number(req.params.id);
|
||||
let member = req.user.id;
|
||||
@@ -133,9 +184,18 @@ router.get('/me/:id', [requireLogin], async (req: Request, res: Response) => {
|
||||
}
|
||||
return res.status(200).json(output);
|
||||
}
|
||||
catch (err) {
|
||||
console.error('Query failed:', err);
|
||||
return res.status(500).json({ error: 'Failed to load application' });
|
||||
catch (error) {
|
||||
logger.error(
|
||||
'app',
|
||||
'Failed to load application',
|
||||
{
|
||||
application: appID,
|
||||
user: member,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
}
|
||||
);
|
||||
return res.status(500);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -157,9 +217,17 @@ router.get('/:id', [requireLogin, requireRole("Recruiter")], async (req: Request
|
||||
}
|
||||
return res.status(200).json(output);
|
||||
}
|
||||
catch (err) {
|
||||
console.error('Query failed:', err);
|
||||
return res.status(500).json({ error: 'Failed to load application' });
|
||||
catch (error) {
|
||||
logger.error(
|
||||
'app',
|
||||
'Failed to load application',
|
||||
{
|
||||
application: appID,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
}
|
||||
);
|
||||
return res.status(500);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -177,9 +245,22 @@ router.post('/approve/:id', [requireLogin, requireRole("Recruiter")], async (req
|
||||
|
||||
await pool.query('CALL sp_accept_new_recruit_validation(?, ?, ?, ?)', [Number(process.env.CONFIG_ID), app.member_id, approved_by, approved_by])
|
||||
|
||||
logger.info('app', "Member application approved", {
|
||||
application: app.id,
|
||||
applicant: app.member_id,
|
||||
approver: approved_by
|
||||
})
|
||||
res.sendStatus(200);
|
||||
} catch (err) {
|
||||
console.error('Approve failed:', err);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
'app',
|
||||
'Failed to approve application',
|
||||
{
|
||||
application: appID,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
}
|
||||
);
|
||||
res.status(500).json({ error: 'Failed to approve application' });
|
||||
}
|
||||
});
|
||||
@@ -193,9 +274,23 @@ router.post('/deny/:id', [requireLogin, requireRole("Recruiter")], async (req: R
|
||||
const app = await getApplicationByID(appID);
|
||||
await denyApplication(appID, approver);
|
||||
await setUserState(app.member_id, MemberState.Denied);
|
||||
|
||||
logger.info('app', "Member application approved", {
|
||||
application: app.id,
|
||||
applicant: app.member_id,
|
||||
approver: approver
|
||||
})
|
||||
res.sendStatus(200);
|
||||
} catch (err) {
|
||||
console.error('Approve failed:', err);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
'app',
|
||||
'Failed to deny application',
|
||||
{
|
||||
application: appID,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
}
|
||||
);
|
||||
res.status(500).json({ error: 'Failed to deny application' });
|
||||
}
|
||||
});
|
||||
@@ -233,10 +328,25 @@ VALUES(?, ?, ?);`
|
||||
INNER JOIN members AS member ON member.id = app.poster_id
|
||||
WHERE app.id = ?; `;
|
||||
const comment = await conn.query(getSQL, [result.insertId])
|
||||
|
||||
logger.info('app', "Application comment posted", {
|
||||
application: appID,
|
||||
poster: user.id,
|
||||
comment: result.insertId,
|
||||
})
|
||||
|
||||
res.status(201).json(comment[0]);
|
||||
|
||||
} catch (err) {
|
||||
console.error('Comment failed:', err);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
'app',
|
||||
'Failed to post comment',
|
||||
{
|
||||
application: appID,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
}
|
||||
);
|
||||
res.status(500).json({ error: 'Could not post comment' });
|
||||
} finally {
|
||||
conn.release();
|
||||
@@ -277,10 +387,24 @@ VALUES(?, ?, ?, 1);`
|
||||
INNER JOIN members AS member ON member.id = app.poster_id
|
||||
WHERE app.id = ?; `;
|
||||
const comment = await conn.query(getSQL, [result.insertId])
|
||||
res.status(201).json(comment[0]);
|
||||
|
||||
} catch (err) {
|
||||
console.error('Comment failed:', err);
|
||||
logger.info('app', "Admin application comment posted", {
|
||||
application: appID,
|
||||
poster: user.id,
|
||||
comment: result.insertId,
|
||||
})
|
||||
|
||||
res.status(201).json(comment[0]);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
'app',
|
||||
'Failed to post comment',
|
||||
{
|
||||
application: appID,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
}
|
||||
);
|
||||
res.status(500).json({ error: 'Could not post comment' });
|
||||
} finally {
|
||||
conn.release();
|
||||
@@ -291,9 +415,22 @@ router.post('/restart', async (req: Request, res: Response) => {
|
||||
const user = req.user.id;
|
||||
try {
|
||||
await setUserState(user, MemberState.Guest);
|
||||
|
||||
logger.info('app', "Member restarted application", {
|
||||
user: user
|
||||
})
|
||||
|
||||
res.sendStatus(200);
|
||||
} catch (error) {
|
||||
console.error('Comment failed:', error);
|
||||
logger.error(
|
||||
'app',
|
||||
'Failed to restart application',
|
||||
{
|
||||
user: user,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
}
|
||||
);
|
||||
res.status(500).json({ error: 'Could not rester application' });
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user