-
Notifications
You must be signed in to change notification settings - Fork 3
/
bupa.js
24 lines (22 loc) · 997 Bytes
/
bupa.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const cds = require('@sap/cds'), { UPDATE } = cds.ql
module.exports = srv => {
/*
* inefficient handler updating readAt and readBy for each row using individual UPDATEs
*/
srv.after('READ', 'A_BusinessPartnerAddress', async function (addresses) {
const { timestamp: readAt, user: { id: readBy } } = cds.context
for (const address of addresses) {
const { AddressID, BusinessPartner } = address
await UPDATE('db.A_BusinessPartnerAddress', { AddressID, BusinessPartner }).set({ readAt, readBy })
}
})
/*
* efficient handler updating readAt and readBy for each row using a single UPDATE
*/
// srv.after('READ', 'A_BusinessPartnerAddress', async function (addresses) {
// const { timestamp: readAt, user: { id: readBy } } = cds.context
// await UPDATE('db.A_BusinessPartnerAddress')
// .set({ readAt, readBy })
// .where(`concat(AddressID,':',BusinessPartner) in`, addresses.map(a => `${a.AddressID}:${a.BusinessPartner}`))
// })
}