Додан моніторінг застосунку
Додани веб компоненти карточок територій та повідомлень
This commit is contained in:
@@ -44,6 +44,24 @@ class SheepsController {
|
||||
}
|
||||
}
|
||||
|
||||
async getListStand(req, res) {
|
||||
if (req.possibilities.can_view_stand) {
|
||||
const result = await SheepsService.getListStand(req.mode);
|
||||
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'User not found.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'The sheep does not have enough rights.' });
|
||||
}
|
||||
}
|
||||
|
||||
async createSheep(req, res) {
|
||||
const data = req.body;
|
||||
|
||||
|
||||
22
api/middleware/metrics.js
Normal file
22
api/middleware/metrics.js
Normal file
@@ -0,0 +1,22 @@
|
||||
module.exports = (req, res, next) => {
|
||||
const start = performance.now();
|
||||
|
||||
res.on("finish", () => {
|
||||
const duration = performance.now() - start;
|
||||
|
||||
fetch("http://metrics:4005/push", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
type: "rest",
|
||||
path: req.originalUrl,
|
||||
method: req.method,
|
||||
status: res.statusCode,
|
||||
time: duration,
|
||||
timestamp: Date.now()
|
||||
})
|
||||
}).catch(err => console.error(err));
|
||||
});
|
||||
|
||||
next();
|
||||
};
|
||||
@@ -1,6 +1,8 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const metrics = require('../middleware/metrics');
|
||||
|
||||
const authRoutes = require('./auth.routes');
|
||||
const sheepsRoutes = require('./sheeps.routes');
|
||||
const constructorRoutes = require('./constructor.routes');
|
||||
@@ -18,6 +20,9 @@ const pushRoutes = require('./push.routes');
|
||||
const generatorCardsRoutes = require('./generator.cards.routes');
|
||||
const generatorReportTerritoriesRoutes = require('./generator.report.territories.routes');
|
||||
|
||||
|
||||
router.use(metrics);
|
||||
|
||||
router.use('/auth', authRoutes);
|
||||
router.use('/sheeps?', sheepsRoutes);
|
||||
router.use('/constructor', constructorRoutes);
|
||||
|
||||
@@ -15,4 +15,8 @@ router
|
||||
.route('/list')
|
||||
.get(authenticate, SheepsController.getList);
|
||||
|
||||
router
|
||||
.route('/list/stand')
|
||||
.get(authenticate, SheepsController.getListStand);
|
||||
|
||||
module.exports = router;
|
||||
@@ -75,6 +75,7 @@ class SheepService {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getList(mode) {
|
||||
return new Promise((res, rej) => {
|
||||
const sql = `
|
||||
@@ -147,6 +148,82 @@ class SheepService {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getListStand(mode) {
|
||||
return new Promise((res, rej) => {
|
||||
const sql = `
|
||||
SELECT
|
||||
sheeps.*,
|
||||
possibilities.can_add_sheeps,
|
||||
possibilities.can_view_sheeps,
|
||||
possibilities.can_add_territory,
|
||||
possibilities.can_view_territory,
|
||||
possibilities.can_manager_territory,
|
||||
possibilities.can_add_stand,
|
||||
possibilities.can_view_stand,
|
||||
possibilities.can_manager_stand,
|
||||
possibilities.can_add_schedule,
|
||||
possibilities.can_view_schedule
|
||||
FROM
|
||||
sheeps
|
||||
LEFT JOIN
|
||||
possibilities ON possibilities.sheep_id = sheeps.id
|
||||
WHERE
|
||||
possibilities.can_view_stand = '1'
|
||||
ORDER BY
|
||||
sheeps.group_id;
|
||||
`;
|
||||
|
||||
db.all(sql, (err, rows) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return res(false);
|
||||
}
|
||||
|
||||
const fields = [
|
||||
"can_add_sheeps",
|
||||
"can_view_sheeps",
|
||||
"can_add_territory",
|
||||
"can_view_territory",
|
||||
"can_manager_territory",
|
||||
"can_add_stand",
|
||||
"can_view_stand",
|
||||
"can_manager_stand",
|
||||
"can_add_schedule",
|
||||
"can_view_schedule"
|
||||
];
|
||||
|
||||
const result = rows.map(sheep => {
|
||||
const data = {
|
||||
id: sheep.id,
|
||||
group_id: sheep.group_id,
|
||||
name: sheep.name,
|
||||
icon: sheep.icon,
|
||||
uuid: (mode && mode == 2) ? sheep.uuid : null,
|
||||
uuid_manager: (mode && mode == 2) ? sheep.uuid_manager : null,
|
||||
mode: mode ? Number(sheep.mode) : 0,
|
||||
mode_title: sheep.mode_title,
|
||||
possibilities: {}
|
||||
};
|
||||
|
||||
fields.forEach(f => {
|
||||
data.possibilities[f] = false;
|
||||
});
|
||||
|
||||
if (mode && (mode == 1 || mode == 2)) {
|
||||
fields.forEach(f => {
|
||||
data.possibilities[f] = !!sheep[f];
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
});
|
||||
|
||||
res(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
createSheep(data) {
|
||||
const stmt1 = db.prepare('INSERT INTO sheeps(name, group_id, uuid) VALUES (?, ?, ?)');
|
||||
const stmt2 = db.prepare('INSERT INTO possibilities(can_view_territory, sheep_id) VALUES (?, ?)');
|
||||
@@ -175,6 +252,7 @@ class SheepService {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
updateSheep(data) {
|
||||
const stmt1 = db.prepare(`
|
||||
UPDATE
|
||||
@@ -241,6 +319,7 @@ class SheepService {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
deleteSheep(data) {
|
||||
const stmtSelect = db.prepare('SELECT id FROM sheeps WHERE uuid = ?');
|
||||
const stmtDeletePoss = db.prepare('DELETE FROM possibilities WHERE sheep_id = ?');
|
||||
|
||||
Reference in New Issue
Block a user