reaname services
This commit is contained in:
committed by
Daniel Hutzel
parent
30d5c789bc
commit
49b8f4ef95
@@ -22,9 +22,11 @@ aspect Persone {
|
|||||||
|
|
||||||
entity MediaTypes : Named {}
|
entity MediaTypes : Named {}
|
||||||
|
|
||||||
entity Genres : Named {
|
entity Genres {
|
||||||
tracks : Association to many Tracks
|
key ID : Integer;
|
||||||
on tracks.genre = $self;
|
name : localized String;
|
||||||
|
tracks : Association to many Tracks
|
||||||
|
on tracks.genre = $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
entity Playlists : Named {}
|
entity Playlists : Named {}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using {sap.capire.media.store as my} from '../db/schema';
|
using {sap.capire.media.store as my} from '../db/schema';
|
||||||
|
|
||||||
@(requires : 'authenticated-user')
|
@(requires : 'authenticated-user')
|
||||||
service InvoicesService {
|
service Invoices {
|
||||||
@readonly
|
@readonly
|
||||||
entity Invoices as projection on my.Invoices;
|
entity Invoices as projection on my.Invoices;
|
||||||
|
|
||||||
|
|||||||
13
media-store/srv/manage-tracks-service.cds
Normal file
13
media-store/srv/manage-tracks-service.cds
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using {sap.capire.media.store as my} from '../db/schema';
|
||||||
|
|
||||||
|
@(requires : 'authenticated-user')
|
||||||
|
service ManageTracks {
|
||||||
|
@(restrict : [{
|
||||||
|
grant : [
|
||||||
|
'READ',
|
||||||
|
'WRITE'
|
||||||
|
],
|
||||||
|
to : 'employee'
|
||||||
|
}, ])
|
||||||
|
entity Genres as projection on my.Genres;
|
||||||
|
}
|
||||||
7
media-store/srv/manage-tracks-service.js
Normal file
7
media-store/srv/manage-tracks-service.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
const cds = require("@sap/cds");
|
||||||
|
|
||||||
|
module.exports = async function () {
|
||||||
|
this.before("*", async (req) => {
|
||||||
|
req.user.locale = "fr";
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
using {sap.capire.media.store as my} from '../db/schema';
|
using {sap.capire.media.store as my} from '../db/schema';
|
||||||
|
|
||||||
service UserService {
|
service Users {
|
||||||
|
entity Customers @(restrict : [{
|
||||||
@restrict : [{
|
grant : [
|
||||||
grant : '*',
|
'READ',
|
||||||
|
'WRITE'
|
||||||
|
],
|
||||||
to : 'employee'
|
to : 'employee'
|
||||||
}]
|
}, ]) as projection on my.Customers;
|
||||||
entity Customers as projection on my.Customers;
|
|
||||||
|
|
||||||
@(requires : 'authenticated-user')
|
type Person {
|
||||||
function getUser() returns {
|
|
||||||
lastName : String(20);
|
lastName : String(20);
|
||||||
firstName : String(40);
|
firstName : String(40);
|
||||||
city : String(40);
|
city : String(40);
|
||||||
@@ -20,7 +20,13 @@ service UserService {
|
|||||||
phone : String(24);
|
phone : String(24);
|
||||||
fax : String(24);
|
fax : String(24);
|
||||||
email : String(60);
|
email : String(60);
|
||||||
};
|
}
|
||||||
|
|
||||||
|
@(requires : 'authenticated-user')
|
||||||
|
action updatePerson(person : Person);
|
||||||
|
|
||||||
|
@(requires : 'authenticated-user')
|
||||||
|
function getPerson() returns Person;
|
||||||
|
|
||||||
function mockLogin(email : String(111), password : String(200)) returns {
|
function mockLogin(email : String(111), password : String(200)) returns {
|
||||||
roles : array of String(111);
|
roles : array of String(111);
|
||||||
@@ -28,5 +34,5 @@ service UserService {
|
|||||||
mockedToken : String(500);
|
mockedToken : String(500);
|
||||||
email : my.Persone.email;
|
email : my.Persone.email;
|
||||||
ID : my.Persone.ID
|
ID : my.Persone.ID
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ const cds = require("@sap/cds");
|
|||||||
const USER_LEVELS = { customer: 1, employee: 2 };
|
const USER_LEVELS = { customer: 1, employee: 2 };
|
||||||
|
|
||||||
module.exports = async function () {
|
module.exports = async function () {
|
||||||
const db = await cds.connect.to("db"); // connect to database service
|
const db = await cds.connect.to("db");
|
||||||
const { Employees, Customers } = db.entities;
|
const { Employees, Customers } = db.entities;
|
||||||
|
|
||||||
|
const getUserEntity = (isCustomer) => (isCustomer ? Customers : Employees);
|
||||||
|
|
||||||
this.before("*", (req) => {
|
this.before("*", (req) => {
|
||||||
console.log(
|
console.log(
|
||||||
"[USER]:",
|
"[USER]:",
|
||||||
@@ -17,9 +19,19 @@ module.exports = async function () {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.on("getUser", async (req) => {
|
this.on("updatePerson", async (req) => {
|
||||||
|
await UPDATE(
|
||||||
|
getUserEntity(req.user && req.user._roles && req.user.is("customer"))
|
||||||
|
)
|
||||||
|
.set(req.data.person)
|
||||||
|
.where({ ID: req.user.attr.ID });
|
||||||
|
});
|
||||||
|
|
||||||
|
this.on("getPerson", async (req) => {
|
||||||
return await db.run(
|
return await db.run(
|
||||||
SELECT.one(Customers)
|
SELECT.one(
|
||||||
|
getUserEntity(req.user && req.user._roles && req.user.is("customer"))
|
||||||
|
)
|
||||||
.columns(
|
.columns(
|
||||||
"lastName",
|
"lastName",
|
||||||
"firstName",
|
"firstName",
|
||||||
|
|||||||
@@ -89,7 +89,13 @@ const logProcessArgs = () => {
|
|||||||
const insertQuery = constructInsertQuery(targetEntityName, targetColumns);
|
const insertQuery = constructInsertQuery(targetEntityName, targetColumns);
|
||||||
|
|
||||||
const srcEntityName = camelCaseToSnake(targetEntityName.split(".").pop());
|
const srcEntityName = camelCaseToSnake(targetEntityName.split(".").pop());
|
||||||
let srcResultRows = await srcStorage.read(srcEntityName); // e.g. [ { AlbumId:1, ArtistId:1, Title:'some' }, ... ]
|
let srcResultRows;
|
||||||
|
try {
|
||||||
|
srcResultRows = await srcStorage.read(srcEntityName); // e.g. [ { AlbumId:1, ArtistId:1, Title:'some' }, ... ]
|
||||||
|
} catch (e) {
|
||||||
|
console.log("[ERROR]: while trying to read source table", e.message);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!srcResultRows || srcResultRows.length < ZERO_VALUE) {
|
if (!srcResultRows || srcResultRows.length < ZERO_VALUE) {
|
||||||
console.log(
|
console.log(
|
||||||
`[LOG] Skipping ${targetEntityName}.
|
`[LOG] Skipping ${targetEntityName}.
|
||||||
|
|||||||
Reference in New Issue
Block a user