refactoring requests
This commit is contained in:
committed by
Daniel Hutzel
parent
70b0c85346
commit
34acef85b6
3
media-store/.vscode/settings.json
vendored
3
media-store/.vscode/settings.json
vendored
@@ -3,5 +3,6 @@
|
|||||||
"**/.gitignore": true,
|
"**/.gitignore": true,
|
||||||
"**/.git": true,
|
"**/.git": true,
|
||||||
"**/.vscode": true
|
"**/.vscode": true
|
||||||
}
|
},
|
||||||
|
"files.watcherExclude": {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
using {managed} from '@sap/cds/common';
|
|
||||||
|
|
||||||
namespace sap.capire.media.store;
|
namespace sap.capire.media.store;
|
||||||
|
|
||||||
aspect Named {
|
aspect Named {
|
||||||
@@ -90,7 +88,7 @@ entity InvoiceItems {
|
|||||||
quantity : Integer default 1;
|
quantity : Integer default 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
entity Tracks : managed {
|
entity Tracks {
|
||||||
key ID : Integer;
|
key ID : Integer;
|
||||||
name : String(200);
|
name : String(200);
|
||||||
album : Association to Albums;
|
album : Association to Albums;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const jwt = require("jsonwebtoken");
|
|||||||
const { ACCESS_TOKEN_SECRET } = cds.env;
|
const { ACCESS_TOKEN_SECRET } = cds.env;
|
||||||
class MyUser extends cds.User {
|
class MyUser extends cds.User {
|
||||||
constructor(attr, roles, id) {
|
constructor(attr, roles, id) {
|
||||||
super({ attr, _roles: roles, id });
|
super({ attr, _roles: [...roles, "authenticated-user"], id });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,6 +23,7 @@ module.exports = (req, res, next) => {
|
|||||||
decodedUser.email
|
decodedUser.email
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
req.user = new MyUser({}, ["anonymous"], "");
|
||||||
} finally {
|
} finally {
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,12 +16,6 @@ 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;
|
const { Invoices, InvoiceItems } = db.entities;
|
||||||
|
|
||||||
// this.before("*", (req) => {
|
|
||||||
// if (!req.user.is("customer")) {
|
|
||||||
// req.reject(403);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
this.on("READ", "Invoices", async (req) => {
|
this.on("READ", "Invoices", async (req) => {
|
||||||
return await db.run(req.query.where({ customer_ID: req.user.attr.ID }));
|
return await db.run(req.query.where({ customer_ID: req.user.attr.ID }));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,16 +7,10 @@ service BrowseTracks {
|
|||||||
};
|
};
|
||||||
|
|
||||||
@readonly
|
@readonly
|
||||||
entity MarkedTracks @(restrict : [
|
entity MarkedTracks @(restrict : [{
|
||||||
{
|
|
||||||
grant : ['*', ],
|
grant : ['*', ],
|
||||||
to : 'customer'
|
to : 'customer'
|
||||||
},
|
}]) as projection on my.Tracks;
|
||||||
{
|
|
||||||
grant : '*',
|
|
||||||
to : 'employee'
|
|
||||||
},
|
|
||||||
]) as projection on my.Tracks;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Below entities exposed
|
Below entities exposed
|
||||||
|
|||||||
@@ -16,12 +16,6 @@ const selectTracksByEmail = (email) => `
|
|||||||
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
|
||||||
|
|
||||||
// this.before("READ", "MarkedTracks", (req) => {
|
|
||||||
// if (!req.user.is("customer")) {
|
|
||||||
// req.reject(403);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
this.on("READ", "MarkedTracks", async (req) => {
|
this.on("READ", "MarkedTracks", async (req) => {
|
||||||
const myTrackIds = (await db.run(selectTracksByEmail(req.user.id))).map(
|
const myTrackIds = (await db.run(selectTracksByEmail(req.user.id))).map(
|
||||||
({ ID }) => ID
|
({ ID }) => ID
|
||||||
|
|||||||
Reference in New Issue
Block a user