refactoring requests

This commit is contained in:
Dzmitry_Tamashevich@epam.com
2020-11-05 00:19:23 +03:00
committed by Daniel Hutzel
parent 70b0c85346
commit 34acef85b6
6 changed files with 7 additions and 25 deletions

View File

@@ -3,5 +3,6 @@
"**/.gitignore": true,
"**/.git": true,
"**/.vscode": true
}
},
"files.watcherExclude": {}
}

View File

@@ -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;

View File

@@ -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();
}

View File

@@ -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 }));
});

View File

@@ -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

View File

@@ -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