From ea6e27481071a765dfd701ddb239ed89b92bf426 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 17 Dec 2020 16:37:30 +0100 Subject: [PATCH] Fixed: missing await srv.emit --- .eslintrc | 3 ++- bookshop/srv/cat-service.cds | 4 ++-- bookshop/srv/cat-service.js | 4 ++-- common/package.json | 6 +++++- fiori/srv/mashup.js | 2 +- orders/srv/orders-service.js | 4 ++-- reviews/app/vue/app.js | 2 +- reviews/srv/reviews-service.js | 4 ++-- 8 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.eslintrc b/.eslintrc index da867678..40fe0cb5 100644 --- a/.eslintrc +++ b/.eslintrc @@ -21,6 +21,7 @@ }, "rules": { "no-console": "off", - "require-atomic-updates": "off" + "require-atomic-updates": "off", + "require-await":"warn" } } diff --git a/bookshop/srv/cat-service.cds b/bookshop/srv/cat-service.cds index 606eb05a..f6fb00cd 100644 --- a/bookshop/srv/cat-service.cds +++ b/bookshop/srv/cat-service.cds @@ -1,12 +1,12 @@ using { sap.capire.bookshop as my } from '../db/schema'; service CatalogService @(path:'/browse') { - @readonly entity Books as SELECT from my.Books {*, + @readonly entity Books as SELECT from my.Books { *, author.name as author } excluding { createdBy, modifiedBy }; @readonly entity ListOfBooks as SELECT from Books - excluding { descr, stock }; + excluding { descr }; @requires: 'authenticated-user' action submitOrder ( book: Books:ID, amount: Integer ) returns { stock: Integer }; diff --git a/bookshop/srv/cat-service.js b/bookshop/srv/cat-service.js index 9a955c5e..4676dcd5 100644 --- a/bookshop/srv/cat-service.js +++ b/bookshop/srv/cat-service.js @@ -1,7 +1,7 @@ const cds = require('@sap/cds') const { Books } = cds.entities ('sap.capire.bookshop') -class CatalogService extends cds.ApplicationService { async init(){ +class CatalogService extends cds.ApplicationService { init(){ // Reduce stock of ordered books if available stock suffices this.on ('submitOrder', async req => { @@ -9,7 +9,7 @@ class CatalogService extends cds.ApplicationService { async init(){ let {stock} = await tx.read('stock').from(Books,book) if (stock >= amount) { await tx.update (Books,book).with ({ stock: stock -= amount }) - this.emit ('OrderedBook', { book, amount, buyer:req.user.id }) + await this.emit ('OrderedBook', { book, amount, buyer:req.user.id }) return { stock } } else return req.error (409,`${amount} exceeds stock for book #${book}`) diff --git a/common/package.json b/common/package.json index d5c6dc24..c1998c24 100644 --- a/common/package.json +++ b/common/package.json @@ -1,4 +1,8 @@ { "name": "@capire/common", - "version": "1.0.0" + "description": "Provides a pre-built extension package for std @sap/cds/common", + "version": "1.0.0", + "dependencies": { + "@sap/cds": "latest" + } } diff --git a/fiori/srv/mashup.js b/fiori/srv/mashup.js index 7a46fcc6..e8acf174 100644 --- a/fiori/srv/mashup.js +++ b/fiori/srv/mashup.js @@ -49,7 +49,7 @@ module.exports = async()=>{ // called by server.js // // Reduce stock of ordered books for orders are created from Orders admin UI // - OrdersService.on ('OrderChanged', async (msg) => { + OrdersService.on ('OrderChanged', (msg) => { console.debug ('> received:', msg.event, msg.data) const { product, deltaAmount } = msg.data return UPDATE (Books) .where ('ID =', product) diff --git a/orders/srv/orders-service.js b/orders/srv/orders-service.js index 887ee593..10420410 100644 --- a/orders/srv/orders-service.js +++ b/orders/srv/orders-service.js @@ -11,7 +11,7 @@ class OrdersService extends cds.ApplicationService { const { amount:before } = await cds.tx(req).run ( SELECT.one.from (OrderItems, oi => oi.amount) .where ({up__ID:ID, product_ID}) ) - if (amount != before) this.orderChanged (product_ID, amount-before) + if (amount != before) await this.orderChanged (product_ID, amount-before) } }) @@ -20,7 +20,7 @@ class OrdersService extends cds.ApplicationService { const Items = await cds.tx(req).run ( SELECT.from (OrderItems, oi => { oi.product_ID, oi.amount }) .where ({up__ID:ID}) ) - if (Items) for (let it of Items) this.orderChanged (it.product_ID, -it.amount) + if (Items) await Promise.all (Items.map(it => this.orderChanged (it.product_ID, -it.amount))) }) return super.init() diff --git a/reviews/app/vue/app.js b/reviews/app/vue/app.js index fb115d68..b46a4892 100644 --- a/reviews/app/vue/app.js +++ b/reviews/app/vue/app.js @@ -37,7 +37,7 @@ const reviews = new Vue ({ reviews.message = {} }, - async newReview () { + newReview () { reviews.review = {} reviews.message = {} setTimeout (()=> $('form > input').focus(), 111) diff --git a/reviews/srv/reviews-service.js b/reviews/srv/reviews-service.js index 10979994..21441df6 100644 --- a/reviews/srv/reviews-service.js +++ b/reviews/srv/reviews-service.js @@ -1,5 +1,5 @@ const cds = require ('@sap/cds') -module.exports = cds.service.impl (async function(){ +module.exports = cds.service.impl (function(){ // Get the CSN definition for Reviews from the db schema for sub-sequent queries // ( Note: we explicitly specify the namespace to support embedded reuse ) @@ -16,7 +16,7 @@ module.exports = cds.service.impl (async function(){ SELECT.one (['round(avg(rating),2) as rating']) .from (Reviews) .where ({subject}) ) global.it || console.log ('< emitting:', 'reviewed', { subject, rating }) - this.emit ('reviewed', { subject, rating }) + await this.emit ('reviewed', { subject, rating }) }) // Increment counter for reviews considered helpful