Revived the page! He's baaaaack
This commit is contained in:
29
api/src/routes/units.ts
Normal file
29
api/src/routes/units.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import express = require('express');
|
||||
const unitsRouter = express.Router();
|
||||
|
||||
import pool from '../db';
|
||||
import { requireLogin } from '../middleware/auth';
|
||||
import { logger } from '../services/logging/logger';
|
||||
import { Unit } from '@app/shared/types/units';
|
||||
|
||||
unitsRouter.use(requireLogin);
|
||||
|
||||
//get all units
|
||||
unitsRouter.get('/', async (req, res) => {
|
||||
try {
|
||||
const result: Unit[] = await pool.query('SELECT * FROM units WHERE active = 1;');
|
||||
res.json(result);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
'app',
|
||||
'Failed to get all units',
|
||||
{
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
}
|
||||
);
|
||||
res.sendStatus(500);
|
||||
}
|
||||
});
|
||||
|
||||
export const units = unitsRouter;
|
||||
Reference in New Issue
Block a user