diff --git a/api/src/routes/applications.ts b/api/src/routes/applications.ts index 3c78aeb..6183c2a 100644 --- a/api/src/routes/applications.ts +++ b/api/src/routes/applications.ts @@ -155,21 +155,13 @@ router.post('/approve/:id', [requireLogin, requireRole("Recruiter")], async (req try { const app = await getApplicationByID(appID); - const result = await approveApplication(appID); - - //guard against failures - if (result.affectedRows != 1) { - throw new Error("Something went wrong approving the application"); - } + await approveApplication(appID, approved_by); //update user profile await setUserState(app.member_id, MemberState.Member); await pool.query('CALL sp_accept_new_recruit_validation(?, ?, ?, ?)', [Number(process.env.CONFIG_ID), app.member_id, approved_by, approved_by]) - // let nextRank = await getRankByName('Recruit') - // await insertMemberRank(app.member_id, nextRank.id); - // //assign user to "pending basic" - // await assignUserToStatus(app.member_id, 1); + res.sendStatus(200); } catch (err) { console.error('Approve failed:', err); @@ -178,12 +170,13 @@ router.post('/approve/:id', [requireLogin, requireRole("Recruiter")], async (req }); // POST /application/deny/:id -router.post('/deny/:id', [requireLogin, requireRole("Recruiter")], async (req, res) => { - const appID = req.params.id; +router.post('/deny/:id', [requireLogin, requireRole("Recruiter")], async (req: Request, res: Response) => { + const appID = Number(req.params.id); + const approver = Number(req.user.id); try { const app = await getApplicationByID(appID); - await denyApplication(appID); + await denyApplication(appID, approver); await setUserState(app.member_id, MemberState.Denied); res.sendStatus(200); } catch (err) { diff --git a/api/src/services/applicationService.ts b/api/src/services/applicationService.ts index dceaad3..5692b4c 100644 --- a/api/src/services/applicationService.ts +++ b/api/src/services/applicationService.ts @@ -31,7 +31,7 @@ export async function getApplicationByID(appID: number): Promise return app[0]; } -export async function getApplicationList(): Promise { +export async function getApplicationList(page: number = 1, pageSize: number = 25): Promise { const sql = `SELECT member.name AS member_name, app.id, @@ -40,9 +40,11 @@ export async function getApplicationList(): Promise { app.app_status FROM applications AS app LEFT JOIN members AS member - ON member.id = app.member_id;` + ON member.id = app.member_id + ORDER BY app.submitted_at DESC + LIMIT ? OFFSET ?;` - const rows: ApplicationListRow[] = await pool.query(sql); + const rows: ApplicationListRow[] = await pool.query(sql, [pageSize, page]); return rows; } @@ -59,30 +61,35 @@ export async function getAllMemberApplications(memberID: number): Promise showCoC.value, async () => { Have you ever served in the military?
- + Yes (checked) / No (unchecked)
diff --git a/ui/src/pages/Application.vue b/ui/src/pages/Application.vue index 6092ab1..98e7ff7 100644 --- a/ui/src/pages/Application.vue +++ b/ui/src/pages/Application.vue @@ -105,12 +105,21 @@ async function postApp(appData) { } async function handleApprove(id) { - console.log("hi"); - await approveApplication(id); + try { + await approveApplication(id); + loadData(await loadApplication(Number(route.params.id), true)) + } catch (error) { + console.error(error); + } } async function handleDeny(id) { - await denyApplication(id); + try { + await denyApplication(id); + loadData(await loadApplication(Number(route.params.id), true)) + } catch (error) { + console.error(error); + } } @@ -164,7 +173,8 @@ async function handleDeny(id) {

Discussion

- +
diff --git a/ui/src/pages/ManageApplications.vue b/ui/src/pages/ManageApplications.vue index bc5a347..907a023 100644 --- a/ui/src/pages/ManageApplications.vue +++ b/ui/src/pages/ManageApplications.vue @@ -11,7 +11,7 @@ import { TableRow, } from '@/components/ui/table' import Button from '@/components/ui/button/Button.vue'; -import { onMounted, ref, watch } from 'vue'; +import { computed, onMounted, ref, watch } from 'vue'; import { useRoute, useRouter } from 'vue-router'; import { CheckIcon, XIcon } from 'lucide-vue-next'; import Application from './Application.vue'; @@ -52,36 +52,26 @@ function formatExact(iso) { return isNaN(d) ? '' : exactFmt.format(d) } -async function handleApprove(id) { - await approveApplication(id); - appList.value = await getAllApplications(); -} - -async function handleDeny(id) { - await denyApplication(id); - appList.value = await getAllApplications(); -} - const router = useRouter(); function openApplication(id) { + if (!id) return; router.push(`/administration/applications/${id}`) - openPanel.value = true; } function closeApplication() { router.push('/administration/applications') - openPanel.value = false; } const route = useRoute(); watch(() => route.params.id, (newId) => { if (newId === undefined) { - openPanel.value = false; } }) -const openPanel = ref(false); +// const openPanel = ref(false); +const openPanel = computed(() => route.params.id !== undefined) + onMounted(async () => { appList.value = await getAllApplications(); @@ -102,7 +92,7 @@ onMounted(async () => { User - Date Submitted + Date Submitted Status @@ -117,20 +107,10 @@ onMounted(async () => { - + {{ formatAgo(app.submitted_at) }} - - - - -