#12 audit and history
This commit is contained in:
@@ -16,7 +16,7 @@ class GameObjectsController{
|
||||
* @param {App} app The application instance, апликация
|
||||
*/
|
||||
init(app){
|
||||
const { gameObject } = app;
|
||||
const { gameObject, am } = app;
|
||||
const router = express.Router();
|
||||
|
||||
/**
|
||||
@@ -27,11 +27,14 @@ class GameObjectsController{
|
||||
router.put('/', multipartMiddleware, async (req, res)=>{
|
||||
try{
|
||||
let data = req.body;
|
||||
let object = await gameObject[data.id? 'update' : 'create'](req, data)
|
||||
let action = data.id ? 'update' : 'create';
|
||||
let object = await gameObject[action](req, data)
|
||||
res.json({status: 'OK', object});
|
||||
am.audit(req, `game-object-${action}`, object.id);
|
||||
}catch(err){
|
||||
console.error(err);
|
||||
res.status(500).json({status: 'ERR', err});
|
||||
am.audit(req, `game-object-alter-error`, req.body?.id, {q: req.body, e: err});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -44,6 +47,7 @@ class GameObjectsController{
|
||||
router.post('/', async (req, res)=>{
|
||||
let result = await gameObject.list(req.body);
|
||||
res.json(result);
|
||||
am.audit(req, `game-object-list`, null, {q: req.body});
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -56,6 +60,7 @@ class GameObjectsController{
|
||||
router.get('/:id', async (req, res)=>{
|
||||
let object = await gameObject.read(parseInt(req.params.id));
|
||||
res.json(object);
|
||||
am.audit(req, `game-object-read`, object.id);
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -67,6 +72,7 @@ class GameObjectsController{
|
||||
router.delete('/:id', async (req, res)=>{
|
||||
await gameObject.remove(req.params.id);
|
||||
res.json({status: 'OK'});
|
||||
am.audit(req, `game-object-delete`, req.params.id);
|
||||
})
|
||||
|
||||
app.webServer.xapp.use(this.route, router);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user