Compare commits
12 Commits
adding-que
...
enable-fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae20e682be | ||
|
|
53527aac50 | ||
|
|
04f9f2a06f | ||
|
|
fff62e68f1 | ||
|
|
bd65af43eb | ||
|
|
6f9133cd4f | ||
|
|
441c82b4c9 | ||
|
|
fa7cff4123 | ||
|
|
1b69064752 | ||
|
|
ada05cf279 | ||
|
|
4b78a8b637 | ||
|
|
ade170367b |
@@ -40,7 +40,8 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script src="https://sapui5.hana.ondemand.com/test-resources/sap/ushell/bootstrap/sandbox.js"></script>
|
<script src="https://sapui5.hana.ondemand.com/test-resources/sap/ushell/bootstrap/sandbox.js"></script>
|
||||||
<script src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
|
<!-- <script src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js" -->
|
||||||
|
<script src="https://sapui5.hana.ondemand.com/1.78.6/resources/sap-ui-core.js"
|
||||||
data-sap-ui-libs="sap.m, sap.ushell, sap.collaboration, sap.ui.layout"
|
data-sap-ui-libs="sap.m, sap.ushell, sap.collaboration, sap.ui.layout"
|
||||||
data-sap-ui-compatVersion="edge"
|
data-sap-ui-compatVersion="edge"
|
||||||
data-sap-ui-theme="sap_fiori_3"
|
data-sap-ui-theme="sap_fiori_3"
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ module.exports = cds.service.impl(function() {
|
|||||||
|
|
||||||
// Reduce stock of ordered books if available stock suffices
|
// Reduce stock of ordered books if available stock suffices
|
||||||
this.before ('CREATE', 'Orders', (req) => {
|
this.before ('CREATE', 'Orders', (req) => {
|
||||||
const { Items: OrderItems } = req.data
|
const { Items: items } = req.data
|
||||||
return cds.transaction(req) .run (()=> OrderItems.map (order =>
|
return cds.transaction(req) .run (items.map (item =>
|
||||||
UPDATE (Books) .where ('ID =', order.book_ID)
|
UPDATE (Books) .where ('ID =', item.book_ID)
|
||||||
.and ('stock >=', order.amount)
|
.and ('stock >=', item.amount)
|
||||||
.set ('stock -=', order.amount)
|
.set ('stock -=', item.amount)
|
||||||
)) .then (all => all.forEach ((affectedRows,i) => {
|
)) .then (all => all.forEach ((affectedRows,i) => {
|
||||||
if (affectedRows === 0) req.error (409,
|
if (affectedRows === 0) req.error (409,
|
||||||
`${OrderItems[i].amount} exceeds stock for book #${OrderItems[i].book_ID}`
|
`${items[i].amount} exceeds stock for book #${items[i].book_ID}`
|
||||||
)
|
)
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,37 +3,30 @@
|
|||||||
// This is an example of using a project-local server.js to intercept
|
// This is an example of using a project-local server.js to intercept
|
||||||
// the default bootstrapping process.
|
// the default bootstrapping process.
|
||||||
//
|
//
|
||||||
|
|
||||||
const cds = require ('@sap/cds')
|
const cds = require ('@sap/cds')
|
||||||
|
|
||||||
// Mashup services after all are served...
|
// Connect CatalogService and ReviewsService when all are served...
|
||||||
cds.once('served', async()=>{
|
cds.once('served', async ({CatalogService}) => {
|
||||||
|
|
||||||
// react on event messages from reviews service
|
// reflect entity definitions used below...
|
||||||
|
const { Books } = cds.entities('sap.capire.bookshop')
|
||||||
|
const { Reviews } = cds.entities('ReviewsService')
|
||||||
|
|
||||||
|
// prepend the following handler so it overrides the default handler
|
||||||
|
CatalogService.prepend (srv => srv.on ('READ', 'Books/reviews', (req) => {
|
||||||
|
console.debug ('> delegating request to ReviewsService')
|
||||||
|
const [id] = req.params, { columns, limit } = req.query.SELECT
|
||||||
|
return SELECT(columns).from(Reviews).limit(limit).where({subject:String(id)})
|
||||||
|
}))
|
||||||
|
|
||||||
|
// subscribe to events emitted by ReviewsService
|
||||||
const ReviewsService = await cds.connect.to ('ReviewsService')
|
const ReviewsService = await cds.connect.to ('ReviewsService')
|
||||||
const db = await cds.connect.to ('db')
|
|
||||||
|
|
||||||
// reflect entities required below...
|
|
||||||
const { Books } = db.entities('sap.capire.bookshop')
|
|
||||||
const { Reviews } = ReviewsService.entities
|
|
||||||
|
|
||||||
ReviewsService.on ('reviewed', (msg) => {
|
ReviewsService.on ('reviewed', (msg) => {
|
||||||
console.debug ('> received:', msg.event, msg.data)
|
console.debug ('> received:', msg.event, msg.data)
|
||||||
const { subject, rating } = msg.data
|
const { subject, rating } = msg.data
|
||||||
const tx = db.tx (msg) // TODO: db.tx(msg) fully implemented?
|
return UPDATE(Books,subject).with({rating})
|
||||||
return tx.update (Books,subject) .with ({rating})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// delegate requests to read reviews to ReviewsService
|
|
||||||
const CatalogService = await cds.connect.to ('CatalogService')
|
|
||||||
CatalogService.impl (srv => srv.on ('READ', 'Books/reviews', (req) => {
|
|
||||||
console.debug ('> delegating to ReviewsService')
|
|
||||||
const [ id ] = req.params
|
|
||||||
const tx = ReviewsService.tx(req)
|
|
||||||
return tx.read (Reviews) .where ({ subject: String(id) })
|
|
||||||
.columns (req.query.SELECT.columns)
|
|
||||||
}))
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Other bootstrapping events you could hook in to...
|
// Other bootstrapping events you could hook in to...
|
||||||
@@ -42,14 +35,9 @@ cds.on('bootstrap',(app) => {/* ... */})
|
|||||||
cds.on('loaded', (model) => {/* ... */})
|
cds.on('loaded', (model) => {/* ... */})
|
||||||
cds.on('connect', (srv) => {/* ... */})
|
cds.on('connect', (srv) => {/* ... */})
|
||||||
cds.on('serving', (srv) => {/* ... */})
|
cds.on('serving', (srv) => {/* ... */})
|
||||||
|
cds.once('served', (all) => {/* ... */})
|
||||||
cds.once('listening', ({server,url}) => {/* ... */})
|
cds.once('listening', ({server,url}) => {/* ... */})
|
||||||
|
|
||||||
|
|
||||||
// Delegate bootstrapping to built-in server.js
|
// Delegate bootstrapping to built-in server.js
|
||||||
module.exports = cds.server
|
module.exports = cds.server
|
||||||
|
|
||||||
// Monkey-patching older releases
|
|
||||||
if (cds.version < '3.33.4') cds.once('listening', ()=> cds.emit('served'))
|
|
||||||
|
|
||||||
// Launch server if started directly from command-line
|
|
||||||
if (!module.parent) cds.server()
|
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ GET {{bookshop}}/browse/Books(201)/reviews?
|
|||||||
|
|
||||||
### Alternative OData URL
|
### Alternative OData URL
|
||||||
GET {{bookshop}}/browse/Books/201/reviews?
|
GET {{bookshop}}/browse/Books/201/reviews?
|
||||||
&$select=rating,date,reviewer,title
|
&$select=rating,date,title
|
||||||
|
&$top=3
|
||||||
|
|
||||||
###
|
###
|
||||||
GET {{bookshop}}/browse/Books(201)?
|
GET {{bookshop}}/browse/Books(201)?
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
cds.requires.messaging.kind = file-based-messaging
|
cds.requires.messaging.kind = file-based-messaging
|
||||||
|
cds.odata.skipValidation = true
|
||||||
PORT = 5005
|
PORT = 5005
|
||||||
@@ -261,7 +261,7 @@ describe('cds.ql → cqn', () => {
|
|||||||
// same for works distinct
|
// same for works distinct
|
||||||
})
|
})
|
||||||
|
|
||||||
test.skip('where ( ... cql | {x:y} )', () => {
|
test('where ( ... cql | {x:y} )', () => {
|
||||||
const args = [`foo`, "'bar'", 3]
|
const args = [`foo`, "'bar'", 3]
|
||||||
const ID = 11
|
const ID = 11
|
||||||
|
|
||||||
@@ -278,7 +278,6 @@ describe('cds.ql → cqn', () => {
|
|||||||
from: { ref: ['Foo'] },
|
from: { ref: ['Foo'] },
|
||||||
where: cdr
|
where: cdr
|
||||||
? [
|
? [
|
||||||
// '(', //> this one is not required
|
|
||||||
{ ref: ['ID'] },
|
{ ref: ['ID'] },
|
||||||
'=',
|
'=',
|
||||||
{ val: ID },
|
{ val: ID },
|
||||||
@@ -287,7 +286,7 @@ describe('cds.ql → cqn', () => {
|
|||||||
'in',
|
'in',
|
||||||
{ val: args },
|
{ val: args },
|
||||||
'and',
|
'and',
|
||||||
'(', //> this one is missing, and that's changing the logic -> that's a BUG
|
'(',
|
||||||
{ ref: ['x'] },
|
{ ref: ['x'] },
|
||||||
'like',
|
'like',
|
||||||
{ val: '%x%' },
|
{ val: '%x%' },
|
||||||
@@ -298,7 +297,6 @@ describe('cds.ql → cqn', () => {
|
|||||||
')',
|
')',
|
||||||
]
|
]
|
||||||
: [
|
: [
|
||||||
'(', //> this one is not required
|
|
||||||
{ ref: ['ID'] },
|
{ ref: ['ID'] },
|
||||||
'=',
|
'=',
|
||||||
{ val: ID },
|
{ val: ID },
|
||||||
@@ -307,7 +305,7 @@ describe('cds.ql → cqn', () => {
|
|||||||
'in',
|
'in',
|
||||||
{ val: args },
|
{ val: args },
|
||||||
'and',
|
'and',
|
||||||
// '(', //> this one is missing, and that's changing the logic -> that's a BUG
|
'(',
|
||||||
{ ref: ['x'] },
|
{ ref: ['x'] },
|
||||||
'like',
|
'like',
|
||||||
{ val: '%x%' },
|
{ val: '%x%' },
|
||||||
@@ -337,11 +335,31 @@ describe('cds.ql → cqn', () => {
|
|||||||
{ val: 'bar' },
|
{ val: 'bar' },
|
||||||
',',
|
',',
|
||||||
{ val: 3 },
|
{ val: 3 },
|
||||||
')',
|
')'
|
||||||
],
|
]
|
||||||
},
|
}
|
||||||
})
|
})
|
||||||
expect(SELECT.from(Foo).where(`ID=`, ID, `and x in`, args)).to.eql(cqn)
|
|
||||||
|
const cqnFluent = {
|
||||||
|
SELECT: {
|
||||||
|
from: { ref: ['Foo'] },
|
||||||
|
where: [
|
||||||
|
{ ref: ['ID'] },
|
||||||
|
'=',
|
||||||
|
{ val: ID },
|
||||||
|
'and',
|
||||||
|
{ ref: ['x'] },
|
||||||
|
'in',
|
||||||
|
{ list: [
|
||||||
|
{ val: 'foo' },
|
||||||
|
{ val: 'bar' },
|
||||||
|
{ val: 3 }
|
||||||
|
] }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(SELECT.from(Foo).where(`ID=`, ID, `and x in`, args)).to.eql(cqnFluent)
|
||||||
expect(SELECT.from(Foo).where(`ID=${ID} and x in (${args})`)).to.eql(cqn)
|
expect(SELECT.from(Foo).where(`ID=${ID} and x in (${args})`)).to.eql(cqn)
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ describe('Localized Data', () => {
|
|||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
xit('supports @cds.localized:false', async ()=>{
|
it('supports @cds.localized:false', async ()=>{
|
||||||
const { data } = await GET(`/browse/BooksSans?&$select=title,localized_title&$expand=currency&$filter=locale eq 'de' or locale eq null`, {
|
const { data } = await GET(`/browse/BooksSans?&$select=title,localized_title&$expand=currency&$filter=locale eq 'de' or locale eq null`, {
|
||||||
headers: { 'Accept-Language': 'de' },
|
headers: { 'Accept-Language': 'de' },
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user