cosmetics

This commit is contained in:
Daniel
2019-12-16 22:12:37 +01:00
parent 53989cf609
commit c0e1fb38ac

View File

@@ -81,8 +81,9 @@ admin.before ('CREATE', 'Orders', async (req) => {
// reduce stock on ordered books... // reduce stock on ordered books...
const all = await db.tx(req) .run (Items.map (each => const all = await db.tx(req) .run (Items.map (each =>
UPDATE (Books) .set ('stock -=', each.amount) UPDATE (Books) .where ('ID =', each.book_ID)
.where ('ID =', each.book_ID) .and ('stock >=', each.amount) .and ('stock >=', each.amount)
.set ('stock -=', each.amount)
)) ))
all.forEach ((affectedRows,i) => affectedRows > 0 || req.error (409, all.forEach ((affectedRows,i) => affectedRows > 0 || req.error (409,
`${Items[i].amount} exceeds stock for book #${Items[i].book_ID}` `${Items[i].amount} exceeds stock for book #${Items[i].book_ID}`