From ed3ecd502fcb80c7cf7455a3055cd0e551819221 Mon Sep 17 00:00:00 2001 From: D065023 Date: Fri, 29 Nov 2019 12:24:22 +0100 Subject: [PATCH] async style --- packages/bookshop/srv/cat-service.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/bookshop/srv/cat-service.js b/packages/bookshop/srv/cat-service.js index 150e076a..00049cc2 100644 --- a/packages/bookshop/srv/cat-service.js +++ b/packages/bookshop/srv/cat-service.js @@ -12,14 +12,14 @@ module.exports = cds.service.impl(function () { }) /** Add some discount for overstocked books */ -function _addDiscount2 (each, discount) { +function _addDiscount2(each, discount) { each.title += ` -- ${discount}% discount!` } /** Reduce stock of ordered books if available stock suffices */ -async function _reduceStock (req) { +async function _reduceStock(req) { const { Items: OrderItems } = req.data - return cds + const all = await cds .transaction(req) .run(() => OrderItems.map(order => @@ -29,15 +29,13 @@ async function _reduceStock (req) { .and('stock >=', order.amount) ) ) - .then(all => - all.forEach((affectedRows, i) => { - if (affectedRows === 0) - req.error( - 409, - `${OrderItems[i].amount} exceeds stock for book #${ - OrderItems[i].book_ID - }` - ) - }) - ) + all.forEach((affectedRows, i) => { + if (affectedRows === 0) + req.error( + 409, + `${OrderItems[i].amount} exceeds stock for book #${ + OrderItems[i].book_ID + }` + ) + }) }