Skip to content

Commit 9451e3f

Browse files
committed
Eliminate usages of obsolete cds.tx(req)
1 parent 335d6bb commit 9451e3f

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

orders/srv/orders-service.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,14 @@ class OrdersService extends cds.ApplicationService {
88
this.before ('UPDATE', 'Orders', async function(req) {
99
const { ID, Items } = req.data
1010
if (Items) for (let { product_ID, quantity } of Items) {
11-
const { quantity:before } = await cds.tx(req).run (
12-
SELECT.one.from (OrderItems, oi => oi.quantity) .where ({up__ID:ID, product_ID})
13-
)
11+
const { quantity:before } = await SELECT.one.from (OrderItems, oi => oi.quantity) .where ({up__ID:ID, product_ID})
1412
if (quantity != before) await this.orderChanged (product_ID, quantity-before)
1513
}
1614
})
1715

1816
this.before ('DELETE', 'Orders', async function(req) {
1917
const { ID } = req.data
20-
const Items = await cds.tx(req).run (
21-
SELECT.from (OrderItems, oi => { oi.product_ID, oi.quantity }) .where ({up__ID:ID})
22-
)
18+
const Items = await SELECT.from (OrderItems, oi => { oi.product_ID, oi.quantity }) .where ({up__ID:ID})
2319
if (Items) await Promise.all (Items.map(it => this.orderChanged (it.product_ID, -it.quantity)))
2420
})
2521

reviews/srv/reviews-service.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ module.exports = cds.service.impl (function(){
1212
// Emit an event to inform subscribers about new avg ratings for reviewed subjects
1313
this.after (['CREATE','UPDATE','DELETE'], 'Reviews', async function(_,req) {
1414
const {subject} = req.data
15-
const { count, rating } = await cds.tx(req) .run (
16-
SELECT.one `round(avg(rating),2) as rating, count(*) as count` .from (Reviews) .where ({subject})
17-
)
15+
const { count, rating } = await SELECT.one `round(avg(rating),2) as rating, count(*) as count` .from (Reviews) .where ({subject})
1816
global.it || console.log ('< emitting:', 'reviewed', { subject, count, rating }) // eslint-disable-line no-console
1917
await this.emit ('reviewed', { subject, count, rating })
2018
})
@@ -23,8 +21,7 @@ module.exports = cds.service.impl (function(){
2321
this.on ('like', (req) => {
2422
if (!req.user) return req.reject(400, 'You must be identified to like a review')
2523
const {review} = req.data, {user} = req
26-
const tx = cds.tx(req)
27-
return tx.run ([
24+
return cds.run ([
2825
INSERT.into (Likes) .entries ({review_ID: review, user: user.id}),
2926
UPDATE (Reviews) .set({liked: {'+=': 1}}) .where({ID:review})
3027
]).catch(() => req.reject(400, 'You already liked that review'))
@@ -34,9 +31,8 @@ module.exports = cds.service.impl (function(){
3431
this.on ('unlike', async (req) => {
3532
if (!req.user) return req.reject(400, 'You must be identified to remove a former like of yours')
3633
const {review} = req.data, {user} = req
37-
const tx = cds.tx(req)
38-
const affectedRows = await tx.run (DELETE.from (Likes) .where ({review_ID: review,user: user.id}))
39-
if (affectedRows === 1) return tx.run (UPDATE (Reviews) .set ({liked: {'-=': 1}}) .where ({ID:review}))
34+
const affectedRows = await DELETE.from (Likes) .where ({review_ID: review,user: user.id})
35+
if (affectedRows === 1) return UPDATE (Reviews) .set ({liked: {'-=': 1}}) .where ({ID:review})
4036
})
4137

4238
})

0 commit comments

Comments
 (0)