Moved to chinook + added .env

This commit is contained in:
Daniel
2020-12-16 10:58:53 +01:00
committed by Daniel Hutzel
parent 5cec82fa00
commit 69e510a407
136 changed files with 6 additions and 5 deletions

View File

@@ -0,0 +1,33 @@
const cds = require("@sap/cds");
const SHIPPED_STATUS = 1;
module.exports = async function () {
const db = await cds.connect.to("db"); // connect to database service
const { Invoices, InvoiceItems } = db.entities;
this.on("READ", "MarkedTracks", async (req) => {
const invoiceItemEntries = await db.run(
SELECT.from(InvoiceItems)
.columns("track_ID")
.where(
"invoice_ID in",
SELECT("ID").from(Invoices).where({
customer_ID: req.user.attr.ID,
status: SHIPPED_STATUS,
})
)
);
const trackIds = invoiceItemEntries.map(({ track_ID }) => track_ID);
const result = [];
await db.foreach(req.query, (track) => {
result.push({
...track,
alreadyOrdered: trackIds.includes(track.ID),
});
});
return result;
});
};