add custom authentication checks
This commit is contained in:
committed by
Daniel Hutzel
parent
3cf02cb567
commit
70b0c85346
@@ -3,24 +3,24 @@ const cds = require("@sap/cds");
|
||||
module.exports = async function () {
|
||||
const db = await cds.connect.to("db"); // connect to database service
|
||||
|
||||
const { Genres, Albums } = db.entities;
|
||||
const { Albums, Tracks, Artists } = db.entities;
|
||||
|
||||
this.before("*", (req) => {
|
||||
console.log(
|
||||
"[USER]:",
|
||||
req.user.id,
|
||||
" [LEVEL]: ",
|
||||
req.user.attr.level,
|
||||
"[ROLE]",
|
||||
req.user.is("user") ? "user" : "other"
|
||||
this.before("CREATE", "Tracks", async (req) => {
|
||||
let { ID: lastTrackId } = await db.run(
|
||||
SELECT.one(Tracks).columns("ID").orderBy({ ID: "desc" })
|
||||
);
|
||||
req.data = { ...req.data, ID: ++lastTrackId };
|
||||
});
|
||||
|
||||
this.on("addTrack", async (req) => {
|
||||
const { albumTitle, genreName, name: trackName, composer } = req.data;
|
||||
|
||||
const genre = await db.run(SELECT.one(Genres).where({ name: genreName }));
|
||||
const album = await db.run(SELECT.one(Albums).where({ title: albumTitle }));
|
||||
// todo impl
|
||||
this.before("CREATE", "Artists", async (req) => {
|
||||
let { ID: lastArtistId } = await db.run(
|
||||
SELECT.one(Artists).columns("ID").orderBy({ ID: "desc" })
|
||||
);
|
||||
req.data = { ...req.data, ID: ++lastArtistId };
|
||||
});
|
||||
this.before("CREATE", "Albums", async (req) => {
|
||||
let { ID: lastAlbumId } = await db.run(
|
||||
SELECT.one(Albums).columns("ID").orderBy({ ID: "desc" })
|
||||
);
|
||||
req.data = { ...req.data, ID: ++lastAlbumId };
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user