Переработаны роутеры приложения

Переписано APi WebSocket для работы с новыми роутерами
This commit is contained in:
2025-10-03 17:11:31 +03:00
parent d75fb7ec3d
commit 6ec6523d71
54 changed files with 2593 additions and 3749 deletions

View 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 };