Переработаны роутеры приложения
Переписано APi WebSocket для работы с новыми роутерами
This commit is contained in:
31
ws/services/stand.service.js
Normal file
31
ws/services/stand.service.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const db = require("../config/db");
|
||||
|
||||
function updateStand(user, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!user.possibilities.can_manager_territory) {
|
||||
return reject(new Error("Forbidden: no rights to manage territory"));
|
||||
}
|
||||
|
||||
const sql = `
|
||||
UPDATE buildings
|
||||
SET status = ?, description = ?, sheep_id = ?, updated_at = ?
|
||||
WHERE id = ?`;
|
||||
|
||||
db.run(sql, [Number(data.status), data.description, data.sheep_id, data.updated_at, data.id], function (err) {
|
||||
if (err) return reject(err);
|
||||
if (this.changes === 0) return reject(new Error("Building not found"));
|
||||
|
||||
const insertSql = `
|
||||
INSERT INTO buildings_history
|
||||
(buildings_id, status, description, sheep_id, created_at)
|
||||
VALUES (?, ?, ?, ?, ?)`;
|
||||
|
||||
db.run(insertSql, [Number(data.id), Number(data.status), data.description, data.sheep_id, Date.now()], function (err) {
|
||||
if (err) return reject(err);
|
||||
resolve({ update: "ok", id: data.id, historyId: this.lastID });
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { updateStand };
|
||||
Reference in New Issue
Block a user