implemented integrations and events system
This commit is contained in:
@@ -12,6 +12,7 @@ import { Request, response, Response } from 'express';
|
||||
import { getUserRoles } from '../services/db/rolesService';
|
||||
import { requireLogin, requireRole } from '../middleware/auth';
|
||||
import { logger } from '../services/logging/logger';
|
||||
import { bus } from '../services/events/eventBus';
|
||||
|
||||
//get CoC
|
||||
router.get('/coc', async (req: Request, res: Response) => {
|
||||
@@ -45,36 +46,24 @@ router.get('/coc', async (req: Request, res: Response) => {
|
||||
|
||||
|
||||
// POST /application
|
||||
router.post('/', [requireLogin], async (req, res) => {
|
||||
router.post('/', [requireLogin], async (req: Request, res: Response) => {
|
||||
const memberID = req.user.id;
|
||||
const App = req.body?.App || {};
|
||||
const appVersion = 1;
|
||||
|
||||
try {
|
||||
req.profiler?.start('createApplication');
|
||||
await createApplication(memberID, appVersion, JSON.stringify(App));
|
||||
req.profiler?.end('createApplication');
|
||||
let appID = 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'
|
||||
);
|
||||
}
|
||||
bus.emit("application.create", { application: appID, member_name: req.user.name, member_discord_id: req.user.discord_id || null })
|
||||
|
||||
logger.info('app', 'Application Posted', {
|
||||
user: memberID,
|
||||
app: appID
|
||||
})
|
||||
} catch (err) {
|
||||
logger.error(
|
||||
'app',
|
||||
|
||||
@@ -200,7 +200,7 @@ passport.deserializeUser(function (user, cb) {
|
||||
|
||||
t = performance.now();
|
||||
const userResults = await con.query(
|
||||
`SELECT id, name FROM members WHERE id = ?;`,
|
||||
`SELECT id, name, discord_id FROM members WHERE id = ?;`,
|
||||
[memberID]
|
||||
);
|
||||
timings.memberQuery = performance.now() - t;
|
||||
@@ -210,6 +210,7 @@ passport.deserializeUser(function (user, cb) {
|
||||
name: string;
|
||||
roles: Role[];
|
||||
state: MemberState;
|
||||
discord_id?: string;
|
||||
} = userResults[0];
|
||||
|
||||
t = performance.now();
|
||||
@@ -259,6 +260,7 @@ declare global {
|
||||
user: {
|
||||
id: number;
|
||||
name: string;
|
||||
discord_id: string;
|
||||
roles: Role[];
|
||||
state: MemberState;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user