Last active
July 31, 2024 00:01
-
-
Save andrew-barnard/b0d24fd740dfbe47f9f57f3d591c9ec6 to your computer and use it in GitHub Desktop.
Custom Handlers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cds = require('@sap/cds') | |
class northbreeze { | |
async selectProduct(req) { | |
const { communityid } = req.data | |
... | |
const { ProductName } = await SELECT.one.from(Products).columns(....) | |
return `${ProductName}` } | |
} | |
module.exports = northbreeze |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Style 1 - Function no extending | |
module.exports = function Sue(){ | |
this.on('sum', ({data:{x,y}}) => x+y) | |
this.on('add', ({data:{x,to}}) => stocks[to] += x) | |
this.on('stock', ({data:{id}}) => stocks[id]) | |
this.on('getStock','Foo', ({params:[id]}) => stocks[id]) | |
this.on('order','Foo', ({params:[id],data:{x}}) => stocks[id] -= x) | |
} | |
// Style 2 - Extending cds.Service ( and sometimes I see extending cds.ApplicationService ) | |
module.exports = class Sue extends cds.Service { | |
sum(x,y) { return x+y } | |
add(x,to) { return stocks[to] += x } | |
stock(id) { return stocks[id] } | |
getStock(Foo,id) { return stocks[id] } | |
order(Foo,id,x) { return stocks[id] -= x } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment