cleaner
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
ID;modifiedAt;createdAt;createdBy;modifiedBy;OrderNo;currency_code
|
ID;modifiedAt;createdAt;createdBy;modifiedBy;OrderNo;currency_code;status
|
||||||
da86efd0-4ba1-4078-b7f0-5c9c530297f7;;2019-01-31;ALICE;;1;EUR
|
da86efd0-4ba1-4078-b7f0-5c9c530297f7;;2019-01-31;ALICE;;1;EUR;processing
|
||||||
2f2f2640-6866-4dcf-8f4d-3027aa831cad;;2019-03-25;ALICE;;10;EUR
|
2f2f2640-6866-4dcf-8f4d-3027aa831cad;;2019-03-25;ALICE;;10;EUR;completed
|
||||||
64e718c9-ff99-47f1-8ca3-950c850777d4;;2019-01-30;BOB;;2;EUR
|
64e718c9-ff99-47f1-8ca3-950c850777d4;;2019-01-30;BOB;;2;EUR;processing
|
||||||
|
1af3322d-3cb1-46be-b312-0ae9ec311537;;2019-03-16;BOB;;9;EUR;completed
|
||||||
|
@@ -1,35 +1,50 @@
|
|||||||
namespace sap.capire.bookshop;
|
namespace sap.capire.bookshop;
|
||||||
using { Currency, managed, cuid } from '@sap/cds/common';
|
|
||||||
|
using {
|
||||||
|
Currency,
|
||||||
|
managed,
|
||||||
|
cuid
|
||||||
|
} from '@sap/cds/common';
|
||||||
|
|
||||||
|
type Status : String enum {
|
||||||
|
completed;
|
||||||
|
processing;
|
||||||
|
blocked;
|
||||||
|
}
|
||||||
|
|
||||||
entity Books : managed {
|
entity Books : managed {
|
||||||
key ID : Integer;
|
key ID : Integer;
|
||||||
title : localized String(111);
|
title : localized String(111);
|
||||||
descr : localized String(1111);
|
descr : localized String(1111);
|
||||||
author : Association to Authors;
|
author : Association to Authors;
|
||||||
stock : Integer;
|
stock : Integer;
|
||||||
price : Decimal(9,2);
|
price : Decimal(9, 2);
|
||||||
currency : Currency;
|
currency : Currency;
|
||||||
}
|
}
|
||||||
|
|
||||||
entity Authors : managed {
|
entity Authors : managed {
|
||||||
key ID : Integer;
|
key ID : Integer;
|
||||||
name : String(111);
|
name : String(111);
|
||||||
dateOfBirth : Date;
|
dateOfBirth : Date;
|
||||||
dateOfDeath : Date;
|
dateOfDeath : Date;
|
||||||
placeOfBirth : String;
|
placeOfBirth : String;
|
||||||
placeOfDeath : String;
|
placeOfDeath : String;
|
||||||
books : Association to many Books on books.author = $self;
|
books : Association to many Books
|
||||||
|
on books.author = $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
entity Orders : cuid, managed {
|
entity Orders : cuid, managed {
|
||||||
OrderNo : String @title:'Order Number'; //> readable key
|
OrderNo : String @title : 'Order Number'; //> readable key
|
||||||
Items : Composition of many OrderItems on Items.parent = $self;
|
status : Status;
|
||||||
total : Decimal(9,2) @readonly;
|
Items : Composition of many OrderItems
|
||||||
|
on Items.parent = $self;
|
||||||
|
total : Decimal(9, 2)@readonly;
|
||||||
currency : Currency;
|
currency : Currency;
|
||||||
}
|
}
|
||||||
|
|
||||||
entity OrderItems : cuid {
|
entity OrderItems : cuid {
|
||||||
parent : Association to Orders;
|
parent : Association to Orders;
|
||||||
book : Association to Books;
|
book : Association to Books;
|
||||||
amount : Integer;
|
amount : Integer;
|
||||||
netAmount : Decimal(9,2);
|
netAmount : Decimal(9, 2);
|
||||||
}
|
}
|
||||||
@@ -9,13 +9,15 @@ module.exports = cds.service.impl(async function () {
|
|||||||
this.on('READ', BusinessPartners, req => bupaSrv.tx(req).run(req.query))
|
this.on('READ', BusinessPartners, req => bupaSrv.tx(req).run(req.query))
|
||||||
|
|
||||||
bupaSrv.on('BusinessPartner/Changed', async msg => {
|
bupaSrv.on('BusinessPartner/Changed', async msg => {
|
||||||
console.log('>> Received', msg.data)
|
console.log('>> Received BusinessPartner/Changed', msg.data)
|
||||||
const BUSINESSPARTNER = msg.data.KEY[0].BUSINESSPARTNER
|
const BUSINESSPARTNER = msg.data.KEY[0].BUSINESSPARTNER
|
||||||
const orders = await cds.tx(msg).run(SELECT('ID').from(Orders).where({ createdBy: BUSINESSPARTNER }))
|
const tx = cds.tx(msg)
|
||||||
|
const orders = await tx.run(SELECT('ID').from(Orders).where({ createdBy: BUSINESSPARTNER, status: 'processing' }))
|
||||||
if (!orders.length) return
|
if (!orders.length) return
|
||||||
const businessPartner = await bupaSrv.tx(msg).run(SELECT.one(BusinessPartners).where({ ID: BUSINESSPARTNER }))
|
const businessPartner = await bupaSrv.tx(msg).run(SELECT.one(BusinessPartners).where({ ID: BUSINESSPARTNER }))
|
||||||
if (!businessPartner || !businessPartner.BusinessPartnerIsBlocked) return
|
if (!businessPartner || !businessPartner.BusinessPartnerIsBlocked) return
|
||||||
orders.forEach(order => this.emit('OrderBlocked', order) && console.log('>> Emitted', order))
|
await Promise.all(orders.map(order => tx.run(UPDATE(Orders).where(order).set({ status: 'blocked' }))))
|
||||||
|
orders.forEach(order => this.emit('OrderBlocked', order) && console.log('>> Emitted OrderBlocked', order))
|
||||||
})
|
})
|
||||||
|
|
||||||
/** Add some discount for overstocked books */
|
/** Add some discount for overstocked books */
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ module.exports = srv => {
|
|||||||
KEY: [{ BUSINESSPARTNER: req.data.BusinessPartner }]
|
KEY: [{ BUSINESSPARTNER: req.data.BusinessPartner }]
|
||||||
}
|
}
|
||||||
srv.emit('BusinessPartner/Changed', payload)
|
srv.emit('BusinessPartner/Changed', payload)
|
||||||
console.log('<< Emitted', payload)
|
console.log('<< Emitted BusinessPartner/Changed', payload)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user