From 456c29a731544afa6b36e27302b3738ee884fe26 Mon Sep 17 00:00:00 2001 From: ajdj100 Date: Mon, 15 Sep 2025 10:38:50 -0400 Subject: [PATCH] Updated rank change page systems --- api/routes/applications.js | 7 --- api/routes/ranks.js | 21 ++++++- ui/src/api/rank.ts | 56 ++++++++++--------- .../ui/dropdown-menu/DropdownMenuShortcut.vue | 18 ++++++ 4 files changed, 69 insertions(+), 33 deletions(-) create mode 100644 ui/src/components/ui/dropdown-menu/DropdownMenuShortcut.vue diff --git a/api/routes/applications.js b/api/routes/applications.js index 939bbbd..32530e9 100644 --- a/api/routes/applications.js +++ b/api/routes/applications.js @@ -4,13 +4,6 @@ const router = express.Router(); // DB pool (same as used in api/index.js) const pool = require('../db'); -// Keep any in-memory structures if needed (preserved from original file) -let applicationData = { - app: null, - messages: [], - status: null, -}; - // POST /application router.post('/', async (req, res) => { try { diff --git a/api/routes/ranks.js b/api/routes/ranks.js index 1b54896..a674ac0 100644 --- a/api/routes/ranks.js +++ b/api/routes/ranks.js @@ -11,7 +11,26 @@ const pool = require('../db'); //insert a new latest role for a user ur.post('/', async (req, res) => { + try { + const App = req.body?.App || {}; + // TODO: replace with current user ID + const memberId = 1; + + const sql = `INSERT INTO applications (member_id, app_version, app_data) VALUES (?, ?, ?);`; + const appVersion = 1; + + const params = [memberId, appVersion, JSON.stringify(App)] + + console.log(params) + + await pool.query(sql, params); + + res.sendStatus(201); + } catch (err) { + console.error('Insert failed:', err); + res.status(500).json({ error: 'Failed to save application' }); + } }); r.get('/', async (req, res) => { @@ -25,6 +44,6 @@ r.get('/', async (req, res) => { }); module.exports.ranks = r; -module.exports.userRanks = ur; +module.exports.memberRanks = ur; // TODO, implement get all ranks route with SQL stirng SELECT id, name, short_name, category, sort_id FROM ranks; \ No newline at end of file diff --git a/ui/src/api/rank.ts b/ui/src/api/rank.ts index 8e377d0..14718df 100644 --- a/ui/src/api/rank.ts +++ b/ui/src/api/rank.ts @@ -1,33 +1,39 @@ -export type Member = { id: number; name: string } -export type Rank = { id: number; name: string } - -// Placeholder: fetch list of members -export async function getMembers(): Promise { - // Simulate async delay - await new Promise((r) => setTimeout(r, 150)) - return [ - { id: 1, name: 'Alice Anderson' }, - { id: 2, name: 'Bob Brown' }, - { id: 3, name: 'Charlie Clark' }, - { id: 4, name: 'Dana Diaz' }, - ] +export type Rank = { + id: number + name: string + short_name: string + sortOrder: number } +const addr = "localhost:3000" + + // Placeholder: fetch list of ranks export async function getRanks(): Promise { - await new Promise((r) => setTimeout(r, 120)) - return [ - { id: 10, name: 'Private' }, - { id: 20, name: 'Corporal' }, - { id: 30, name: 'Sergeant' }, - { id: 40, name: 'Lieutenant' }, - { id: 50, name: 'Captain' }, - ] + const res = await fetch(`http://${addr}/ranks`) + + if (res.ok) { + return res.json() + } else { + console.error("Something went wrong approving the application") + } + } // Placeholder: submit a rank change export async function submitRankChange(memberId: number, rankId: number): Promise<{ ok: boolean }> { - console.log('Stub submitRankChange', { memberId, rankId }) - await new Promise((r) => setTimeout(r, 200)) - return { ok: true } -} + const res = await fetch(`http://${addr}/rank`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ memberId, rankId }), + }) + + if (res.ok) { + return { ok: true } + } else { + console.error("Failed to submit rank change") + return { ok: false } + } +} \ No newline at end of file diff --git a/ui/src/components/ui/dropdown-menu/DropdownMenuShortcut.vue b/ui/src/components/ui/dropdown-menu/DropdownMenuShortcut.vue new file mode 100644 index 0000000..07b92ec --- /dev/null +++ b/ui/src/components/ui/dropdown-menu/DropdownMenuShortcut.vue @@ -0,0 +1,18 @@ + + +