diff --git a/bookshop/srv/cat-service.js b/bookshop/srv/cat-service.js index a9c629c0..e6b53a77 100644 --- a/bookshop/srv/cat-service.js +++ b/bookshop/srv/cat-service.js @@ -9,7 +9,7 @@ class CatalogService extends cds.ApplicationService { init(){ const {book,quantity} = req.data if (quantity < 1) return req.reject (400,`quantity has to be 1 or more`) let {stock} = await SELECT `stock` .from (Books,book) - if (quantity > stock) return req.reject (409,`${quantity} exceeds stock for book #${book}`) + if (quantity > stock) return req.reject (409, "ORDER_EXCEEDS_STOCK", [quantity, book]) await UPDATE (Books,book) .with ({ stock: stock -= quantity }) await this.emit ('OrderedBook', { book, quantity, buyer:req.user.id }) return { stock } diff --git a/bookshop/srv/i18n/messages_en.properties b/bookshop/srv/i18n/messages_en.properties new file mode 100644 index 00000000..c9c2641c --- /dev/null +++ b/bookshop/srv/i18n/messages_en.properties @@ -0,0 +1 @@ +ORDER_EXCEEDS_STOCK={0} exceeds stock for book #{1} \ No newline at end of file