Додана сторінка "Стенд"

Додане повідомлення про оновлення застосунку
Оновлен Service Worker
Перероблен WebSocket APІ
This commit is contained in:
2025-10-19 00:55:30 +03:00
parent 6ec6523d71
commit 3f08f3f6c9
46 changed files with 2651 additions and 2691 deletions

View File

@@ -11,7 +11,7 @@ function updateApartment(user, data) {
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) {
db.run(sql, [Number(data.status), data.description, user.id, data.updated_at, data.id], function (err) {
if (err) return reject(err);
if (this.changes === 0) return reject(new Error("Apartment not found"));
@@ -20,7 +20,7 @@ function updateApartment(user, data) {
(apartments_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) {
db.run(insertSql, [Number(data.id), Number(data.status), data.description, user.id, Date.now()], function (err) {
if (err) return reject(err);
resolve({ update: "ok", id: data.id, historyId: this.lastID });
});

View File

@@ -11,7 +11,7 @@ function updateBuilding(user, data) {
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) {
db.run(sql, [Number(data.status), data.description, user.id, data.updated_at, data.id], function (err) {
if (err) return reject(err);
if (this.changes === 0) return reject(new Error("Building not found"));
@@ -20,7 +20,7 @@ function updateBuilding(user, data) {
(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) {
db.run(insertSql, [Number(data.id), Number(data.status), data.description, user.id, Date.now()], function (err) {
if (err) return reject(err);
resolve({ update: "ok", id: data.id, historyId: this.lastID });
});

View File

@@ -1,26 +1,61 @@
const db = require("../config/db");
function lockingStand(user, data) {
return new Promise((resolve, reject) => {
const sheepId = Number(data.sheep_id) || null;
if (!user.possibilities.can_view_stand) {
return reject(new Error("Forbidden: no rights to view stand"));
}
if ((sheepId !== user.id && sheepId !== null) && !user.possibilities.can_manager_stand) {
return reject(new Error("Forbidden: no rights to view stand"));
}
resolve({ update: "ok", id: data.id });
});
}
function unlockingStand(user, data) {
return new Promise((resolve, reject) => {
const sheepId = Number(data.sheep_id) || null;
if (!user.possibilities.can_view_stand) {
return reject(new Error("Forbidden: no rights to view stand"));
}
if ((sheepId !== user.id && sheepId !== null) && !user.possibilities.can_manager_stand) {
return reject(new Error("Forbidden: no rights to view stand"));
}
resolve({ update: "ok", id: data.id });
});
}
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 sheepId = Number(data.sheep_id) || null;
if (!user.possibilities.can_view_stand) {
return reject(new Error("Forbidden: no rights to view stand"));
}
if ((sheepId !== user.id && sheepId !== null) && !user.possibilities.can_manager_stand) {
return reject(new Error("Forbidden: no rights to view stand"));
}
const sql = `
UPDATE buildings
SET status = ?, description = ?, sheep_id = ?, updated_at = ?
UPDATE stand_schedule
SET sheep_id = ?, updated_at = ?
WHERE id = ?`;
db.run(sql, [Number(data.status), data.description, data.sheep_id, data.updated_at, data.id], function (err) {
db.run(sql, [sheepId, Date.now(), data.id], function (err) {
if (err) return reject(err);
if (this.changes === 0) return reject(new Error("Building not found"));
if (this.changes === 0) return reject(new Error("Stand not found"));
const insertSql = `
INSERT INTO buildings_history
(buildings_id, status, description, sheep_id, created_at)
VALUES (?, ?, ?, ?, ?)`;
INSERT INTO stand_schedule_history
(stand_schedule_id, sheep_id, created_at)
VALUES (?, ?, ?)`;
db.run(insertSql, [Number(data.id), Number(data.status), data.description, data.sheep_id, Date.now()], function (err) {
db.run(insertSql, [Number(data.id), sheepId, Date.now()], function (err) {
if (err) return reject(err);
resolve({ update: "ok", id: data.id, historyId: this.lastID });
});
@@ -28,4 +63,4 @@ function updateStand(user, data) {
});
}
module.exports = { updateStand };
module.exports = { lockingStand, unlockingStand, updateStand };