reaname services
This commit is contained in:
committed by
Daniel Hutzel
parent
30d5c789bc
commit
49b8f4ef95
@@ -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;
|
||||
|
||||
|
||||
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';
|
||||
|
||||
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
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user