Merge branch 'master' into temporal

This commit is contained in:
Daniel
2021-04-10 13:08:31 +02:00
5 changed files with 37 additions and 27 deletions

37
.vscode/launch.json vendored
View File

@@ -4,28 +4,31 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{
"name": "Attach by Process ID",
"processId": "${command:PickProcess}",
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node"
},
{ {
"name": "bookshop", "name": "bookshop",
"command": "cds watch bookshop", "command": "npx cds watch bookshop",
"request": "launch",
"type": "node-terminal", "type": "node-terminal",
"skipFiles": ["<node_internals>/**"] "request": "launch",
"skipFiles": [
"<node_internals>/**",
"**/node_modules/**",
"**/cds/lib/lazy.js",
"**/cds/lib/req/cls.js",
"**/odata-v4/okra/**"
]
}, },
{ {
"name": "Fiori app", "name": "Fiori App",
"command": "cds watch fiori", "command": "npx cds watch fiori",
"request": "launch",
"type": "node-terminal", "type": "node-terminal",
"skipFiles": ["<node_internals>/**"] "request": "launch",
"skipFiles": [
"<node_internals>/**",
"**/node_modules/**",
"**/cds/lib/lazy.js",
"**/cds/lib/req/cls.js",
"**/odata-v4/okra/**"
]
} }
], ],
"inputs": [ "inputs": [
@@ -33,7 +36,7 @@
"type": "pickString", "type": "pickString",
"id": "sample", "id": "sample",
"description": "Which sample do you want to start?", "description": "Which sample do you want to start?",
"options": ["bookshop", "fiori", "reviews", "reviews/test/bookshop"], "options": [ "bookshop", "fiori", "reviews", "reviews" ],
"default": "bookshop" "default": "bookshop"
} }
] ]

11
.vscode/settings.json vendored
View File

@@ -4,5 +4,14 @@
"**/.gitignore": true, "**/.gitignore": true,
"**/.vscode": true, "**/.vscode": true,
"LICENSES/**": true "LICENSES/**": true
} },
"debug.javascript.terminalOptions": {
"skipFiles": [
"<node_internals>/**",
"**/node_modules/**",
"**/cds/lib/lazy.js",
"**/cds/lib/req/cls.js",
"**/odata-v4/okra/**"
]
},
} }

View File

@@ -4,7 +4,7 @@
"description": "A simple self-contained bookshop service.", "description": "A simple self-contained bookshop service.",
"dependencies": { "dependencies": {
"@capire/common": "*", "@capire/common": "*",
"@sap/cds": ">=4", "@sap/cds": "^5.0.4",
"express": "^4.17.1", "express": "^4.17.1",
"passport": "0.4.1" "passport": "0.4.1"
}, },

View File

@@ -5,10 +5,10 @@ class CatalogService extends cds.ApplicationService { init(){
// Reduce stock of ordered books if available stock suffices // Reduce stock of ordered books if available stock suffices
this.on ('submitOrder', async req => { this.on ('submitOrder', async req => {
const {book,amount} = req.data, tx = cds.tx(req) const {book,amount} = req.data
let {stock} = await tx.read('stock').from(Books,book) let {stock} = await SELECT `stock` .from (Books,book)
if (stock >= amount) { if (stock >= amount) {
await tx.update (Books,book).with ({ stock: stock -= amount }) await UPDATE (Books,book) .with (`stock -=`, amount)
await this.emit ('OrderedBook', { book, amount, buyer:req.user.id }) await this.emit ('OrderedBook', { book, amount, buyer:req.user.id })
return { stock } return { stock }
} }
@@ -17,9 +17,7 @@ class CatalogService extends cds.ApplicationService { init(){
// Add some discount for overstocked books // Add some discount for overstocked books
this.after ('READ','ListOfBooks', each => { this.after ('READ','ListOfBooks', each => {
if (each.stock > 111) { if (each.stock > 111) each.title += ` -- 11% discount!`
each.title += ` -- 11% discount!`
}
}) })
return super.init() return super.init()

View File

@@ -20,11 +20,11 @@ describe('Messaging', ()=>{
let N=0, received=[], M=0 let N=0, received=[], M=0
it ('should add messaging event handlers', ()=>{ it ('should add messaging event handlers', ()=>{
srv.on('reviewed', (msg,next)=> { received.push(msg); return next() }) srv.on('reviewed', (msg)=> received.push(msg))
}) })
it ('should add more messaging event handlers', ()=>{ it ('should add more messaging event handlers', ()=>{
srv.on('reviewed', (_,next)=> { ++M; return next() }) srv.on('reviewed', ()=> ++M)
}) })
it ('should add review', async ()=>{ it ('should add review', async ()=>{