set up viewing of users application history
Some checks failed
Continuous Deployment / Update Deployment (push) Failing after 1m22s
Some checks failed
Continuous Deployment / Update Deployment (push) Failing after 1m22s
This commit is contained in:
@@ -2,7 +2,7 @@ const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
import pool from '../db';
|
||||
import { approveApplication, createApplication, denyApplication, getApplicationByID, getApplicationComments, getApplicationList, getMemberApplication } from '../services/applicationService';
|
||||
import { approveApplication, createApplication, denyApplication, getAllMemberApplications, getApplicationByID, getApplicationComments, getApplicationList, getMemberApplication } from '../services/applicationService';
|
||||
import { MemberState, setUserState } from '../services/memberService';
|
||||
import { getRankByName, insertMemberRank } from '../services/rankService';
|
||||
import { ApplicationFull, CommentRow } from "@app/shared/types/application"
|
||||
@@ -38,6 +38,20 @@ router.get('/all', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/meList', async (req, res) => {
|
||||
|
||||
let userID = req.user.id;
|
||||
|
||||
try {
|
||||
let application = await getAllMemberApplications(userID);
|
||||
|
||||
return res.status(200).json(application);
|
||||
} catch (error) {
|
||||
console.error('Failed to load applications: \n', error);
|
||||
return res.status(500).json(error);
|
||||
}
|
||||
})
|
||||
|
||||
router.get('/me', async (req, res) => {
|
||||
|
||||
let userID = req.user.id;
|
||||
@@ -62,6 +76,33 @@ router.get('/me', async (req, res) => {
|
||||
}
|
||||
})
|
||||
|
||||
// GET /application/:id
|
||||
router.get('/me/:id', async (req: Request, res: Response) => {
|
||||
let appID = Number(req.params.id);
|
||||
let member = req.user.id;
|
||||
try {
|
||||
const application = await getApplicationByID(appID);
|
||||
if (application === undefined)
|
||||
return res.sendStatus(204);
|
||||
console.log(application.member_id, member)
|
||||
if (application.member_id != member) {
|
||||
return res.sendStatus(403);
|
||||
}
|
||||
|
||||
const comments: CommentRow[] = await getApplicationComments(appID);
|
||||
|
||||
const output: ApplicationFull = {
|
||||
application,
|
||||
comments,
|
||||
}
|
||||
return res.status(200).json(output);
|
||||
}
|
||||
catch (err) {
|
||||
console.error('Query failed:', err);
|
||||
return res.status(500).json({ error: 'Failed to load application' });
|
||||
}
|
||||
});
|
||||
|
||||
// GET /application/:id
|
||||
router.get('/:id', async (req, res) => {
|
||||
let appID = req.params.id;
|
||||
|
||||
@@ -19,9 +19,6 @@ export async function getMemberApplication(memberID: number): Promise<Applicatio
|
||||
return app[0];
|
||||
}
|
||||
|
||||
// export async function getAllMemberApplications(memberID: number): Promise<ApplicationListRow[]> {
|
||||
|
||||
// }
|
||||
|
||||
export async function getApplicationByID(appID: number): Promise<ApplicationRow> {
|
||||
const sql =
|
||||
@@ -49,6 +46,19 @@ export async function getApplicationList(): Promise<ApplicationListRow[]> {
|
||||
return rows;
|
||||
}
|
||||
|
||||
export async function getAllMemberApplications(memberID: number): Promise<ApplicationListRow[]> {
|
||||
const sql = `SELECT
|
||||
app.id,
|
||||
app.member_id,
|
||||
app.submitted_at,
|
||||
app.app_status
|
||||
FROM applications AS app WHERE app.member_id = ? ORDER BY submitted_at DESC;`;
|
||||
|
||||
const rows: ApplicationListRow[] = await pool.query(sql, [memberID])
|
||||
return rows;
|
||||
}
|
||||
|
||||
|
||||
export async function approveApplication(id: number) {
|
||||
const sql = `
|
||||
UPDATE applications
|
||||
|
||||
Reference in New Issue
Block a user