Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit 042a956

Browse files
danjoadimaanj
authored andcommitted
Fixed: missing await srv.emit
1 parent e65c73d commit 042a956

File tree

8 files changed

+17
-12
lines changed

8 files changed

+17
-12
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
},
2222
"rules": {
2323
"no-console": "off",
24-
"require-atomic-updates": "off"
24+
"require-atomic-updates": "off",
25+
"require-await":"warn"
2526
}
2627
}

bookshop/srv/cat-service.cds

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using { sap.capire.bookshop as my } from '../db/schema';
22
service CatalogService @(path:'/browse') {
33

4-
@readonly entity Books as SELECT from my.Books {*,
4+
@readonly entity Books as SELECT from my.Books { *,
55
author.name as author
66
} excluding { createdBy, modifiedBy };
77

88
@readonly entity ListOfBooks as SELECT from Books
9-
excluding { descr, stock };
9+
excluding { descr };
1010

1111
@requires: 'authenticated-user'
1212
action submitOrder ( book: Books:ID, amount: Integer ) returns { stock: Integer };

bookshop/srv/cat-service.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
const cds = require('@sap/cds')
22
const { Books } = cds.entities ('sap.capire.bookshop')
33

4-
class CatalogService extends cds.ApplicationService { async init(){
4+
class CatalogService extends cds.ApplicationService { init(){
55

66
// Reduce stock of ordered books if available stock suffices
77
this.on ('submitOrder', async req => {
88
const {book,amount} = req.data, tx = cds.tx(req)
99
let {stock} = await tx.read('stock').from(Books,book)
1010
if (stock >= amount) {
1111
await tx.update (Books,book).with ({ stock: stock -= amount })
12-
this.emit ('OrderedBook', { book, amount, buyer:req.user.id })
12+
await this.emit ('OrderedBook', { book, amount, buyer:req.user.id })
1313
return { stock }
1414
}
1515
else return req.error (409,`${amount} exceeds stock for book #${book}`)

common/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
22
"name": "@capire/common",
3-
"version": "1.0.0"
3+
"description": "Provides a pre-built extension package for std @sap/cds/common",
4+
"version": "1.0.0",
5+
"dependencies": {
6+
"@sap/cds": "latest"
7+
}
48
}

fiori/srv/mashup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = async()=>{ // called by server.js
4949
//
5050
// Reduce stock of ordered books for orders are created from Orders admin UI
5151
//
52-
OrdersService.on ('OrderChanged', async (msg) => {
52+
OrdersService.on ('OrderChanged', (msg) => {
5353
console.debug ('> received:', msg.event, msg.data)
5454
const { product, deltaAmount } = msg.data
5555
return UPDATE (Books) .where ('ID =', product)

orders/srv/orders-service.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class OrdersService extends cds.ApplicationService {
1111
const { amount:before } = await cds.tx(req).run (
1212
SELECT.one.from (OrderItems, oi => oi.amount) .where ({up__ID:ID, product_ID})
1313
)
14-
if (amount != before) this.orderChanged (product_ID, amount-before)
14+
if (amount != before) await this.orderChanged (product_ID, amount-before)
1515
}
1616
})
1717

@@ -20,7 +20,7 @@ class OrdersService extends cds.ApplicationService {
2020
const Items = await cds.tx(req).run (
2121
SELECT.from (OrderItems, oi => { oi.product_ID, oi.amount }) .where ({up__ID:ID})
2222
)
23-
if (Items) for (let it of Items) this.orderChanged (it.product_ID, -it.amount)
23+
if (Items) await Promise.all (Items.map(it => this.orderChanged (it.product_ID, -it.amount)))
2424
})
2525

2626
return super.init()

reviews/app/vue/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const reviews = new Vue ({
3737
reviews.message = {}
3838
},
3939

40-
async newReview () {
40+
newReview () {
4141
reviews.review = {}
4242
reviews.message = {}
4343
setTimeout (()=> $('form > input').focus(), 111)

reviews/srv/reviews-service.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const cds = require ('@sap/cds')
2-
module.exports = cds.service.impl (async function(){
2+
module.exports = cds.service.impl (function(){
33

44
// Get the CSN definition for Reviews from the db schema for sub-sequent queries
55
// ( Note: we explicitly specify the namespace to support embedded reuse )
@@ -16,7 +16,7 @@ module.exports = cds.service.impl (async function(){
1616
SELECT.one (['round(avg(rating),2) as rating']) .from (Reviews) .where ({subject})
1717
)
1818
global.it || console.log ('< emitting:', 'reviewed', { subject, rating })
19-
this.emit ('reviewed', { subject, rating })
19+
await this.emit ('reviewed', { subject, rating })
2020
})
2121

2222
// Increment counter for reviews considered helpful

0 commit comments

Comments
 (0)