diff --git a/media-store/db/schema.cds b/media-store/db/schema.cds index 4f9261f5..74dba005 100644 --- a/media-store/db/schema.cds +++ b/media-store/db/schema.cds @@ -74,6 +74,11 @@ entity Invoices { total : Decimal(10, 2); invoiceItems : Association to many InvoiceItems on invoiceItems.invoice = $self; + status : Integer enum { + submitted = 1; + shipped = 2; + canceled = -1; + } default 1; } entity InvoiceItems { @@ -81,7 +86,7 @@ entity InvoiceItems { invoice : Association to Invoices; track : Association to Tracks; unitPrice : Decimal(10, 2); - quantity : Integer; + quantity : Integer default 1; } entity Tracks { diff --git a/media-store/package.json b/media-store/package.json index b34f6229..b74dbd29 100644 --- a/media-store/package.json +++ b/media-store/package.json @@ -7,8 +7,7 @@ "private": true, "dependencies": { "@sap/cds": "^4", - "express": "^4", - "passport": "^0.4.1" + "express": "^4" }, "devDependencies": { "sqlite3": "^5" diff --git a/media-store/srv/invoices-service.cds b/media-store/srv/invoices-service.cds index 60dbb037..32bad092 100644 --- a/media-store/srv/invoices-service.cds +++ b/media-store/srv/invoices-service.cds @@ -3,7 +3,7 @@ using {sap.capire.media.store as my} from '../db/schema'; @(requires : 'authenticated-user') service Invoices { @readonly - entity Invoices as projection on my.Invoices; + entity MyInvoices as projection on my.Invoices; action invoice(tracks : array of { ID : Integer; diff --git a/media-store/srv/invoices-service.js b/media-store/srv/invoices-service.js index 1e874d90..5bd3867f 100644 --- a/media-store/srv/invoices-service.js +++ b/media-store/srv/invoices-service.js @@ -15,7 +15,7 @@ module.exports = async function () { ); }); - this.on("READ", "Invoices", async (req) => { + this.on("READ", "MyInvoices", async (req) => { return await db.run(req.query.where({ customer_ID: req.user.attr.ID })); }); diff --git a/media-store/util/importData.js b/media-store/util/importData.js index 8dbc3e0f..43ebb948 100644 --- a/media-store/util/importData.js +++ b/media-store/util/importData.js @@ -12,6 +12,12 @@ const SRC_STORAGE_NAME = args[FIRST_INDEX]; const TARGET_STORAGE_NAME = args[SECOND_INDEX]; const TARGET_SCHEMA_PATH = args[THIRD_INDEX]; +function getRandomInt(min, max) { + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random() * (max - min + 1)) + min; +} + const camelCaseToSnake = (str) => str.replace( /[a-z][A-Z]/g, @@ -120,6 +126,14 @@ const logProcessArgs = () => { password: "some", })); } + // for mock invoice data + if (srcEntityName === "Invoices") { + columns.push("status"); + srcResultRows = srcResultRows.map((row) => ({ + ...row, + status: getRandomInt(-1, 2), + })); + } const transaction = await targetStorage.tx(); await transaction.run(