generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathadmin-service.js
More file actions
24 lines (20 loc) · 828 Bytes
/
admin-service.js
File metadata and controls
24 lines (20 loc) · 828 Bytes
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')
let lastCreatedBook
let lastReadBooks
module.exports = class AdminService extends cds.ApplicationService { async init() {
this.after('READ', 'Books', async () => {
// variable from surrounding scope, state is shared between handler calls
lastReadBooks = await cds.run(SELECT.from('Books')) // [!code error]
return lastReadBooks
})
this.on('CREATE', 'Books', newBookHandler)
await super.init()
}
}
/** @type {import('@sap/cds').CRUDEventHandler.On} */
async function newBookHandler (req) {
const { name } = req.data
// variable from surrounding scope, state is shared between handler calls
lastCreatedBook = await cds.run(INSERT.into('Books').entries({ name })) // [!code error]
return lastCreatedBook
}