add mocked auth

This commit is contained in:
Dzmitry_Tamashevich@epam.com
2020-10-15 01:24:12 +03:00
committed by Daniel Hutzel
parent 937d9caf2b
commit 49f6b8c060
30 changed files with 151 additions and 271 deletions

View File

@@ -0,0 +1,20 @@
const cds = require("@sap/cds");
module.exports = async function () {
const db = await cds.connect.to("db"); // connect to database service
this.before("*", (req) => {
console.log(
"[USER]:",
req.user.id,
" [LEVEL]: ",
req.user.attr.level,
"[ROLE]",
req.user.is("user") ? "user" : "other"
);
});
this.on("READ", "Invoices", async (req) => {
return await db.run(req.query.where({ customer_ID: req.user.attr.ID }));
});
};