rebuild sample to self cont

This commit is contained in:
Wolfgang Koch
2021-04-30 11:13:14 +02:00
parent 0d8abf71cb
commit c458bf0f47
48 changed files with 335 additions and 1154 deletions

View File

@@ -0,0 +1,12 @@
const cds = require('@sap/cds')
module.exports = cds.service.impl (function(){
this.before ('NEW','Authors', genid)
this.before ('NEW','Books', genid)
})
/** Generate primary keys for target entity in request */
async function genid (req) {
const {ID} = await cds.tx(req).run (SELECT.one.from(req.target).columns('max(ID) as ID'))
req.data.ID = ID - ID % 100 + 100 + 1
}