Merged from main

This commit is contained in:
Daniel
2022-05-31 14:54:11 +02:00
6 changed files with 41 additions and 25 deletions

View File

@@ -2,7 +2,7 @@ import cds from '@sap/cds'
export class CatalogService extends cds.ApplicationService { init(){
const { Books } = cds.entities ('sap.capire.bookshop')
const { Books } = this.entities ('sap.capire.bookshop')
// Reduce stock of ordered books if available stock suffices
this.on ('submitOrder', async req => {

View File

@@ -1,9 +1,7 @@
/**
* Exposes user information
*/
@requires: 'authenticated-user'
service UserService {
/**
* The current user
*/
@@ -13,4 +11,5 @@ service UserService {
tenant : String;
}
action login() returns me;
}

View File

@@ -1,4 +1,9 @@
import cds from '@sap/cds'
export default cds.service.impl((srv) => {
srv.on('READ', 'me', ({ tenant, user, locale }) => ({ id: user.id, locale, tenant }))
})
export default class UserService extends cds.Service { init(){
this.on('READ', 'me', ({ tenant, user, locale }) => ({ id: user.id, locale, tenant }))
this.on('login', (req) => {
if (req.user._is_anonymous)
req._.res.set('WWW-Authenticate','Basic realm="Users"').sendStatus(401)
else return this.read('me')
})
}}