add env vars. change db kind
This commit is contained in:
committed by
Daniel Hutzel
parent
05550a14b1
commit
7045914e57
1
media-store/app/.env.development
Normal file
1
media-store/app/.env.development
Normal file
@@ -0,0 +1 @@
|
|||||||
|
API=http://localhost:4004/
|
||||||
@@ -1,10 +1,14 @@
|
|||||||
import { isEmpty } from "lodash";
|
import { isEmpty } from "lodash";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
const BROWSE_TRACKS_SERVICE = `api/browse-tracks`;
|
// in dev mode using provided api
|
||||||
const INVOICES_SERVICE = `api/browse-invoices`;
|
// in prod mode using proxy
|
||||||
const USER_SERVICE = `api/users`;
|
const API = process.env.API || "api/";
|
||||||
const MANAGE_STORE = `api/manage-store`;
|
|
||||||
|
const BROWSE_TRACKS_SERVICE = `${API}browse-tracks`;
|
||||||
|
const INVOICES_SERVICE = `${API}browse-invoices`;
|
||||||
|
const USER_SERVICE = `${API}users`;
|
||||||
|
const MANAGE_STORE = `${API}manage-store`;
|
||||||
|
|
||||||
const constructGenresQuery = (genreIds) => {
|
const constructGenresQuery = (genreIds) => {
|
||||||
return !isEmpty(genreIds)
|
return !isEmpty(genreIds)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
"ACCESS_TOKEN_SECRET": "secret",
|
"ACCESS_TOKEN_SECRET": "secret",
|
||||||
"requires": {
|
"requires": {
|
||||||
"db": {
|
"db": {
|
||||||
"kind": "hana"
|
"kind": "sql"
|
||||||
},
|
},
|
||||||
"auth": {
|
"auth": {
|
||||||
"impl": "srv/auth.js"
|
"impl": "srv/auth.js"
|
||||||
|
|||||||
@@ -1,30 +1,28 @@
|
|||||||
const cds = require("@sap/cds");
|
const cds = require("@sap/cds");
|
||||||
|
|
||||||
const selectTracksByEmail = (email) => `
|
|
||||||
select tracks.ID
|
|
||||||
from sap_capire_media_store_Tracks tracks
|
|
||||||
join sap_capire_media_store_Invoices invoices
|
|
||||||
on tracks.ID = invoiceItems.track_ID
|
|
||||||
join sap_capire_media_store_InvoiceItems invoiceItems
|
|
||||||
on invoices.ID = invoiceItems.invoice_ID
|
|
||||||
join sap_capire_media_store_Customers customers
|
|
||||||
on customers.ID = invoices.customer_ID
|
|
||||||
where (customers.email='${email}' and invoices.status='2')
|
|
||||||
or (customers.email='${email}' and invoices.status='1')
|
|
||||||
`;
|
|
||||||
|
|
||||||
module.exports = async function () {
|
module.exports = async function () {
|
||||||
const db = await cds.connect.to("db"); // connect to database service
|
const db = await cds.connect.to("db"); // connect to database service
|
||||||
|
|
||||||
|
const { Invoices, InvoiceItems } = db.entities;
|
||||||
|
|
||||||
this.on("READ", "MarkedTracks", async (req) => {
|
this.on("READ", "MarkedTracks", async (req) => {
|
||||||
const myTrackIds = (await db.run(selectTracksByEmail(req.user.id))).map(
|
const invoiceItemEntries = await db.run(
|
||||||
({ ID }) => ID
|
SELECT.from(InvoiceItems)
|
||||||
|
.columns("track_ID")
|
||||||
|
.where(
|
||||||
|
"invoice_ID in",
|
||||||
|
SELECT("ID").from(Invoices).where({
|
||||||
|
customer_ID: req.user.attr.ID,
|
||||||
|
})
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
const trackIds = invoiceItemEntries.map(({ track_ID }) => track_ID);
|
||||||
|
|
||||||
const result = [];
|
const result = [];
|
||||||
await db.foreach(req.query, (track) => {
|
await db.foreach(req.query, (track) => {
|
||||||
result.push({
|
result.push({
|
||||||
...track,
|
...track,
|
||||||
alreadyOrdered: myTrackIds.includes(track.ID),
|
alreadyOrdered: trackIds.includes(track.ID),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user