#12 audit and history

This commit is contained in:
2026-02-05 17:02:27 +02:00
parent 6e95ac7999
commit 758fc6be42
7 changed files with 34 additions and 10 deletions
+8 -2
View File
@@ -14,7 +14,7 @@ class GamesController{
*/
init(app){
const router = express.Router();
const { game } = app;
const { game, am } = app;
/**
* API: PUT /api/game/ Create or update game, създаване/обновяване на игрова дефиниция
@@ -24,11 +24,14 @@ class GamesController{
router.put('/', async (req, res)=>{
try{
let data = req.body;
let object = await game[data.id? 'update' : 'create'](req, data)
let action = data.id ? 'update' : 'create';
let object = await game[action](req, data)
res.json({status: 'OK', object});
am.audit(req, `game-${action}`, object.id);
}catch(err){
console.error(err);
res.status(500).json({status: 'ERR', err});
am.audit(req, `game-alter-error`, req.body?.id, {q: req.body, e: err});
}
});
@@ -41,6 +44,7 @@ class GamesController{
router.post('/', async (req, res)=>{
let result = await game.list(req.body);
res.json(result);
am.audit(req, `game-list`, null, {q: req.body});
})
/**
@@ -53,6 +57,7 @@ class GamesController{
router.get('/:id', async (req, res)=>{
let object = await game.read(parseInt(req.params.id));
res.json(object);
am.audit(req, `game-read`, object.id);
})
/**
@@ -64,6 +69,7 @@ class GamesController{
router.delete('/:id', async (req, res)=>{
await game.remove(req.params.id);
res.json({status: 'OK'});
am.audit(req, `game-delete`, req.params.id);
})
app.webServer.xapp.use(this.route, router);