#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
@@ -14,7 +14,7 @@ class ScenariosController{
*/
init(app){
const router = express.Router();
const { scenario } = app;
const { scenario, am } = app;
/**
* API: PUT /api/scenario/ Create or update scenario, създаване/обновяване на игрови сценарий
@@ -24,11 +24,14 @@ class ScenariosController{
router.put('/', async (req, res)=>{
try{
let data = req.body;
let object = await scenario[data.id? 'update' : 'create'](req, data)
let action = data.id ? 'update' : 'create';
let object = await scenario[action](req, data)
res.json({status: 'OK', object});
am.audit(req, `scenario-${action}`, object.id);
}catch(err){
console.error(err);
res.status(500).json({status: 'ERR', err});
am.audit(req, `scenario-alter-error`, req.body?.id, {q: req.body, e: err});
}
});
@@ -41,6 +44,7 @@ class ScenariosController{
router.post('/', async (req, res)=>{
let result = await scenario.list(req.body);
res.json(result);
am.audit(req, `scenario-list`, null, {q: req.body});
})
/**
@@ -53,6 +57,7 @@ class ScenariosController{
router.get('/:id', async (req, res)=>{
let object = await scenario.read(parseInt(req.params.id));
res.json(object);
am.audit(req, `scenario-read`, object.id);
})
/**
@@ -64,6 +69,7 @@ class ScenariosController{
router.delete('/:id', async (req, res)=>{
await scenario.remove(req.params.id);
res.json({status: 'OK'});
am.audit(req, `scenario-delete`, req.params.id);
})
app.webServer.xapp.use(this.route, router);