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:
parent
b22df5d962
commit
89d58d047e
@ -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
|
||||
|
@ -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 });
|
||||
}
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user