Fixed hardcoded value in application comment poster

This commit is contained in:
2025-12-08 16:15:34 -05:00
parent 6a55846f19
commit 4ab803ec72
4 changed files with 33 additions and 29 deletions

View File

@@ -2,11 +2,12 @@ const express = require('express');
const router = express.Router();
import pool from '../db';
import { approveApplication, createApplication, getApplicationByID, getApplicationComments, getApplicationList, getMemberApplication } from '../services/applicationService';
import { approveApplication, createApplication, denyApplication, 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"
import { assignUserToStatus } from '../services/statusService';
import { Request, Response } from 'express';
// POST /application
router.post('/', async (req, res) => {
@@ -64,7 +65,6 @@ router.get('/me', async (req, res) => {
// GET /application/:id
router.get('/:id', async (req, res) => {
let appID = req.params.id;
console.log("HELLO")
try {
const application = await getApplicationByID(appID);
if (application === undefined)
@@ -92,9 +92,6 @@ router.post('/approve/:id', async (req, res) => {
const app = await getApplicationByID(appID);
const result = await approveApplication(appID);
console.log("START");
console.log(app, result);
//guard against failures
if (result.affectedRows != 1) {
throw new Error("Something went wrong approving the application");
@@ -119,26 +116,11 @@ router.post('/approve/:id', async (req, res) => {
router.post('/deny/:id', async (req, res) => {
const appID = req.params.id;
const sql = `
UPDATE applications
SET denied_at = NOW()
WHERE id = ?
AND approved_at IS NULL
AND denied_at IS NULL
`;
try {
const result = await pool.execute(sql, appID);
console.log(result);
if (result.affectedRows === 0) {
res.status(400).json('Something went wrong denying the application');
}
if (result.affectedRows == 1) {
res.sendStatus(200);
}
const app = await getApplicationByID(appID);
await denyApplication(appID);
await setUserState(app.member_id, MemberState.Denied);
res.sendStatus(200);
} catch (err) {
console.error('Approve failed:', err);
res.status(500).json({ error: 'Failed to deny application' });
@@ -146,10 +128,12 @@ router.post('/deny/:id', async (req, res) => {
});
// POST /application/:id/comment
router.post('/:id/comment', async (req, res) => {
router.post('/:id/comment', async (req: Request, res: Response) => {
const appID = req.params.id;
const data = req.body.message;
const user = 1;
const user = req.user;
console.log(user)
const sql = `INSERT INTO application_comments(
application_id,
@@ -161,7 +145,7 @@ VALUES(?, ?, ?);`
try {
const conn = await pool.getConnection();
const result = await conn.query(sql, [appID, user, data])
const result = await conn.query(sql, [appID, user.id, data])
console.log(result)
if (result.affectedRows !== 1) {
conn.release();

View File

@@ -1,5 +1,6 @@
import { ApplicationListRow, ApplicationRow, CommentRow } from "@app/shared/types/application";
import pool from "../db";
import { error } from "console";
export async function createApplication(memberID: number, appVersion: number, app: string) {
const sql = `INSERT INTO applications (member_id, app_version, app_data) VALUES (?, ?, ?);`;
@@ -44,7 +45,7 @@ export async function getApplicationList(): Promise<ApplicationListRow[]> {
return rows;
}
export async function approveApplication(id) {
export async function approveApplication(id: number) {
const sql = `
UPDATE applications
SET approved_at = NOW()
@@ -57,6 +58,24 @@ export async function approveApplication(id) {
return result;
}
export async function denyApplication(id: number) {
const sql = `
UPDATE applications
SET denied_at = NOW()
WHERE id = ?
AND approved_at IS NULL
AND denied_at IS NULL
`;
const result = await pool.execute(sql, id);
if (result.affectedRows == 1) {
return
} else {
throw new Error(`"Something went wrong denying application with ID ${id}`);
}
}
export async function getApplicationComments(appID: number): Promise<CommentRow[]> {
return await pool.query(`SELECT app.id AS comment_id,
app.post_content,

View File

@@ -104,6 +104,7 @@ export async function postChatMessage(message: any, post_id: number) {
const response = await fetch(`${addr}/application/${post_id}/comment`, {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(out),
})

View File

@@ -164,7 +164,7 @@ async function handleDeny(id) {
</div>
<ApplicationForm :read-only="readOnly" :data="appData" @submit="(e) => { postApp(e) }" class="mb-7 pb-15">
</ApplicationForm>
<div v-if="!newApp">
<div v-if="!newApp" class="pb-15">
<h3 class="scroll-m-20 text-2xl font-semibold tracking-tight mb-4">Discussion</h3>
<ApplicationChat :messages="chatData" @post="postComment"></ApplicationChat>
</div>