Using fake Products entity in @capire/orders

This commit is contained in:
Daniel
2020-11-20 12:33:18 +01:00
committed by Daniel Hutzel
parent 932f56812c
commit 8f01bf911e
6 changed files with 25 additions and 18 deletions

View File

@@ -16,10 +16,10 @@ extend Books with {
}
//
// Extend Orders with Books as articles
// Extend Orders with Books as Products
//
using { sap.capire.orders.OrderItems } from '@capire/orders';
extend OrderItems with {
book : Association to Books on article = book.ID
book : Association to Books on product.ID = book.ID
}

View File

@@ -31,7 +31,7 @@ module.exports = async()=>{ // called by server.js
const { title, price } = await db.tx(msg).read (Books, book, b => { b.title, b.price })
return OrdersService.tx(msg).create ('Orders').entries({
OrderNo: 'Order at '+ (new Date).toLocaleString(),
Items: [{ article:`${book}`, title, price, amount }],
Items: [{ product:{ID:`${book}`}, title, price, amount }],
buyer, createdBy: buyer
})
})
@@ -51,8 +51,8 @@ module.exports = async()=>{ // called by server.js
//
OrdersService.on ('OrderChanged', async (msg) => {
console.debug ('> received:', msg.event, msg.data)
const { article, deltaAmount } = msg.data
return UPDATE (Books) .where ('ID =', article)
const { product, deltaAmount } = msg.data
return UPDATE (Books) .where ('ID =', product)
.and ('stock >=', deltaAmount)
.set ('stock -=', deltaAmount)
})