feat: update database, added unique for userId, so now the shop can have reports of the same date more than just from 1 user

This commit is contained in:
Angie 2025-08-01 02:38:30 +02:00
parent b22df5d962
commit 89d58d047e
2 changed files with 14 additions and 3 deletions

View File

@ -78,7 +78,7 @@ async function initDatabase() {
FOREIGN KEY (storeId) REFERENCES stores (id),
FOREIGN KEY (userId) REFERENCES users (id),
FOREIGN KEY (verifiedBy) REFERENCES users (id),
UNIQUE(storeId, reportDate)
UNIQUE(storeId, reportDate, userId)
)`);
// 4. Backfill plaintext passwords for all existing users

View File

@ -66,8 +66,19 @@ router.post(
finalCash,
],
function (err) {
console.error("DB error:", err);
if (err) return res.status(500).json({ error: "Database error" });
if (err) {
if (
err.message &&
err.message.toLowerCase().includes("unique constraint failed")
) {
return res.status(409).json({
error:
"Отчет за этот магазин и дату уже был отправлен этим пользователем.",
});
}
console.error("DB error:", err);
return res.status(500).json({ error: "Database error" });
}
res.status(201).json({ id: this.lastID });
}
);