finalized application acceptance system and started making types shared across front and backend
This commit is contained in:
71
api/src/services/applicationService.ts
Normal file
71
api/src/services/applicationService.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { ApplicationListRow, ApplicationRow, CommentRow } from "@app/shared/types/application";
|
||||
import pool from "../db";
|
||||
|
||||
export async function createApplication(memberID: number, appVersion: number, app: string) {
|
||||
const sql = `INSERT INTO applications (member_id, app_version, app_data) VALUES (?, ?, ?);`;
|
||||
const params = [memberID, appVersion, JSON.stringify(app)]
|
||||
return await pool.query(sql, params);
|
||||
}
|
||||
|
||||
export async function getMemberApplication(memberID: number): Promise<ApplicationRow> {
|
||||
const sql = `SELECT app.*,
|
||||
member.name AS member_name
|
||||
FROM applications AS app
|
||||
INNER JOIN members AS member ON member.id = app.member_id
|
||||
WHERE app.member_id = ?;`;
|
||||
|
||||
let app: ApplicationRow[] = await pool.query(sql, [memberID]);
|
||||
return app[0];
|
||||
}
|
||||
|
||||
export async function getApplicationByID(appID: number): Promise<ApplicationRow> {
|
||||
const sql =
|
||||
`SELECT app.*,
|
||||
member.name AS member_name
|
||||
FROM applications AS app
|
||||
INNER JOIN members AS member ON member.id = app.member_id
|
||||
WHERE app.id = ?;`;
|
||||
let app: ApplicationRow[] = await pool.query(sql, [appID]);
|
||||
return app[0];
|
||||
}
|
||||
|
||||
export async function getApplicationList(): Promise<ApplicationListRow[]> {
|
||||
const sql = `SELECT
|
||||
member.name AS member_name,
|
||||
app.id,
|
||||
app.member_id,
|
||||
app.submitted_at,
|
||||
app.app_status
|
||||
FROM applications AS app
|
||||
LEFT JOIN members AS member
|
||||
ON member.id = app.member_id;`
|
||||
|
||||
const rows: ApplicationListRow[] = await pool.query(sql);
|
||||
return rows;
|
||||
}
|
||||
|
||||
export async function approveApplication(id) {
|
||||
const sql = `
|
||||
UPDATE applications
|
||||
SET approved_at = NOW()
|
||||
WHERE id = ?
|
||||
AND approved_at IS NULL
|
||||
AND denied_at IS NULL
|
||||
`;
|
||||
|
||||
const result = await pool.execute(sql, id);
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function getApplicationComments(appID: number): Promise<CommentRow[]> {
|
||||
return await pool.query(`SELECT app.id AS comment_id,
|
||||
app.post_content,
|
||||
app.poster_id,
|
||||
app.post_time,
|
||||
app.last_modified,
|
||||
member.name AS poster_name
|
||||
FROM application_comments AS app
|
||||
INNER JOIN members AS member ON member.id = app.poster_id
|
||||
WHERE app.application_id = ?;`,
|
||||
[appID]);
|
||||
}
|
||||
Reference in New Issue
Block a user