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