59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
import express = require('express');
|
|
const statusR = express.Router();
|
|
const memberStatusR = express.Router();
|
|
|
|
import pool from '../db';
|
|
import { requireLogin } from '../middleware/auth';
|
|
import { logger } from '../services/logging/logger';
|
|
|
|
statusR.use(requireLogin);
|
|
memberStatusR.use(requireLogin);
|
|
|
|
//insert a new latest rank for a user
|
|
memberStatusR.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' });
|
|
// }
|
|
res.status(501).json({ error: 'Not implemented' });
|
|
});
|
|
|
|
//get all statuses
|
|
statusR.get('/', async (req, res) => {
|
|
try {
|
|
const result = await pool.query('SELECT * FROM statuses;');
|
|
res.json(result);
|
|
} catch (error) {
|
|
logger.error(
|
|
'app',
|
|
'Failed to get all statuses',
|
|
{
|
|
error: error instanceof Error ? error.message : String(error),
|
|
stack: error instanceof Error ? error.stack : undefined,
|
|
}
|
|
);
|
|
res.sendStatus(500);
|
|
}
|
|
});
|
|
|
|
export const status = statusR;
|
|
export const memberStatus = memberStatusR;
|
|
|
|
|
|
// TODO, implement get all ranks route with SQL stirng SELECT id, name, short_name, category, sort_id FROM ranks;
|