refactoring code
This commit is contained in:
committed by
Daniel Hutzel
parent
ecdc32bad1
commit
e08b1c6246
@@ -3,24 +3,10 @@ const cds = require("@sap/cds");
|
||||
module.exports = async function () {
|
||||
const db = await cds.connect.to("db"); // connect to database service
|
||||
|
||||
const { Albums, Tracks, Artists } = db.entities;
|
||||
|
||||
this.before("CREATE", "Tracks", async (req) => {
|
||||
let { ID: lastTrackId } = await db.run(
|
||||
SELECT.one(Tracks).columns("ID").orderBy({ ID: "desc" })
|
||||
this.before("CREATE", "*", async (req) => {
|
||||
let { ID: lastEntityID } = await db.run(
|
||||
SELECT.one(req.entity).columns("ID").orderBy({ ID: "desc" })
|
||||
);
|
||||
req.data = { ...req.data, ID: ++lastTrackId };
|
||||
});
|
||||
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 };
|
||||
req.data = { ...req.data, ID: ++lastEntityID };
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user