Updated rank change page systems
This commit is contained in:
@@ -4,13 +4,6 @@ const router = express.Router();
|
|||||||
// DB pool (same as used in api/index.js)
|
// DB pool (same as used in api/index.js)
|
||||||
const pool = require('../db');
|
const pool = require('../db');
|
||||||
|
|
||||||
// Keep any in-memory structures if needed (preserved from original file)
|
|
||||||
let applicationData = {
|
|
||||||
app: null,
|
|
||||||
messages: [],
|
|
||||||
status: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
// POST /application
|
// POST /application
|
||||||
router.post('/', async (req, res) => {
|
router.post('/', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -11,7 +11,26 @@ const pool = require('../db');
|
|||||||
|
|
||||||
//insert a new latest role for a user
|
//insert a new latest role for a user
|
||||||
ur.post('/', async (req, res) => {
|
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) => {
|
r.get('/', async (req, res) => {
|
||||||
@@ -25,6 +44,6 @@ r.get('/', async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
module.exports.ranks = r;
|
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;
|
// TODO, implement get all ranks route with SQL stirng SELECT id, name, short_name, category, sort_id FROM ranks;
|
||||||
@@ -1,33 +1,39 @@
|
|||||||
export type Member = { id: number; name: string }
|
export type Rank = {
|
||||||
export type Rank = { id: number; name: string }
|
id: number
|
||||||
|
name: string
|
||||||
// Placeholder: fetch list of members
|
short_name: string
|
||||||
export async function getMembers(): Promise<Member[]> {
|
sortOrder: number
|
||||||
// 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' },
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const addr = "localhost:3000"
|
||||||
|
|
||||||
|
|
||||||
// Placeholder: fetch list of ranks
|
// Placeholder: fetch list of ranks
|
||||||
export async function getRanks(): Promise<Rank[]> {
|
export async function getRanks(): Promise<Rank[]> {
|
||||||
await new Promise((r) => setTimeout(r, 120))
|
const res = await fetch(`http://${addr}/ranks`)
|
||||||
return [
|
|
||||||
{ id: 10, name: 'Private' },
|
if (res.ok) {
|
||||||
{ id: 20, name: 'Corporal' },
|
return res.json()
|
||||||
{ id: 30, name: 'Sergeant' },
|
} else {
|
||||||
{ id: 40, name: 'Lieutenant' },
|
console.error("Something went wrong approving the application")
|
||||||
{ id: 50, name: 'Captain' },
|
}
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Placeholder: submit a rank change
|
// Placeholder: submit a rank change
|
||||||
export async function submitRankChange(memberId: number, rankId: number): Promise<{ ok: boolean }> {
|
export async function submitRankChange(memberId: number, rankId: number): Promise<{ ok: boolean }> {
|
||||||
console.log('Stub submitRankChange', { memberId, rankId })
|
const res = await fetch(`http://${addr}/rank`, {
|
||||||
await new Promise((r) => setTimeout(r, 200))
|
method: "POST",
|
||||||
return { ok: true }
|
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 }
|
||||||
|
}
|
||||||
|
}
|
||||||
18
ui/src/components/ui/dropdown-menu/DropdownMenuShortcut.vue
Normal file
18
ui/src/components/ui/dropdown-menu/DropdownMenuShortcut.vue
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<script setup>
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
class: { type: null, required: false },
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<span
|
||||||
|
data-slot="dropdown-menu-shortcut"
|
||||||
|
:class="
|
||||||
|
cn('text-muted-foreground ml-auto text-xs tracking-widest', props.class)
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
Reference in New Issue
Block a user