49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
const express = require('express');
|
|
const r = express.Router();
|
|
const ur = express.Router();
|
|
|
|
const pool = require('../db');
|
|
|
|
// Placeholder router for rank-related routes.
|
|
// Implement rank endpoints here, for example:
|
|
// router.get('/', async (req, res) => { /* ... */ });
|
|
// router.post('/change', async (req, res) => { /* ... */ });
|
|
|
|
//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) => {
|
|
try {
|
|
const result = await pool.query('SELECT id, name, short_name, sort_id FROM ranks;');
|
|
res.json(result);
|
|
} catch (err) {
|
|
console.error(err);
|
|
res.status(500).json({ error: 'Internal server error' });
|
|
}
|
|
});
|
|
|
|
module.exports.ranks = r;
|
|
module.exports.memberRanks = ur;
|
|
|
|
// TODO, implement get all ranks route with SQL stirng SELECT id, name, short_name, category, sort_id FROM ranks;
|