reaname services

This commit is contained in:
Dzmitry_Tamashevich@epam.com
2020-10-23 12:04:03 +03:00
committed by Daniel Hutzel
parent 30d5c789bc
commit 49b8f4ef95
7 changed files with 64 additions and 18 deletions

View File

@@ -22,9 +22,11 @@ aspect Persone {
entity MediaTypes : Named {}
entity Genres : Named {
tracks : Association to many Tracks
on tracks.genre = $self;
entity Genres {
key ID : Integer;
name : localized String;
tracks : Association to many Tracks
on tracks.genre = $self;
}
entity Playlists : Named {}

View File

@@ -1,7 +1,7 @@
using {sap.capire.media.store as my} from '../db/schema';
@(requires : 'authenticated-user')
service InvoicesService {
service Invoices {
@readonly
entity Invoices as projection on my.Invoices;

View 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;
}

View File

@@ -0,0 +1,7 @@
const cds = require("@sap/cds");
module.exports = async function () {
this.before("*", async (req) => {
req.user.locale = "fr";
});
};

View File

@@ -1,15 +1,15 @@
using {sap.capire.media.store as my} from '../db/schema';
service UserService {
@restrict : [{
grant : '*',
service Users {
entity Customers @(restrict : [{
grant : [
'READ',
'WRITE'
],
to : 'employee'
}]
entity Customers as projection on my.Customers;
}, ]) as projection on my.Customers;
@(requires : 'authenticated-user')
function getUser() returns {
type Person {
lastName : String(20);
firstName : String(40);
city : String(40);
@@ -20,7 +20,13 @@ service UserService {
phone : String(24);
fax : String(24);
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 {
roles : array of String(111);
@@ -28,5 +34,5 @@ service UserService {
mockedToken : String(500);
email : my.Persone.email;
ID : my.Persone.ID
}
};
}

View File

@@ -3,9 +3,11 @@ const cds = require("@sap/cds");
const USER_LEVELS = { customer: 1, employee: 2 };
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 getUserEntity = (isCustomer) => (isCustomer ? Customers : Employees);
this.before("*", (req) => {
console.log(
"[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(
SELECT.one(Customers)
SELECT.one(
getUserEntity(req.user && req.user._roles && req.user.is("customer"))
)
.columns(
"lastName",
"firstName",

View File

@@ -89,7 +89,13 @@ const logProcessArgs = () => {
const insertQuery = constructInsertQuery(targetEntityName, targetColumns);
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) {
console.log(
`[LOG] Skipping ${targetEntityName}.