minor cosmetics for user service

This commit is contained in:
Daniel
2022-03-31 09:39:45 +02:00
committed by Christian Georgi
parent 8cc09fde38
commit 959c07cee3
5 changed files with 14 additions and 22 deletions

View File

@@ -44,9 +44,9 @@ const books = Vue.createApp ({
async fetchUserInfo() {
try {
books.user = (await axios.get('/user/Me')).data
if (!books.user.ID) books.user.ID = 'anonymous'
} catch (err) { books.user = {}; books.user.ID = err.message }
const { data } = await axios.get('/user/me')
books.user = data
} catch (err) { books.user = { id: err.message } }
}
}
}).mount("#app")

View File

@@ -19,7 +19,7 @@
<div id='app'>
<div v-if="user" class="user">
<div>User: {{ user.ID || 'anonymous' }}</div>
<div>User: {{ user.id || 'anonymous' }}</div>
<div>Locale: {{ user.locale }}</div>
<div v-if="user.tenant">Tenant: {{ user.tenant }}</div>
</div>

View File

@@ -1,15 +1,14 @@
/**
* Exposes user information
*/
@requires : 'authenticated-user'
@requires: 'authenticated-user'
service UserService {
/**
* The current user
*/
@odata.singleton
entity Me {
ID : String;
@odata.singleton entity me {
id : String; // user id
locale : String;
tenant : String;
}

View File

@@ -1,11 +1,4 @@
const cds = require('@sap/cds');
const cds = require('@sap/cds')
module.exports = cds.service.impl((srv) => {
srv.on('READ', 'Me', ({ user }) => {
return {
ID: user.id,
locale: user.locale,
tenant: user.tenant,
};
});
});
srv.on('READ', 'me', ({ tenant, user, locale }) => ({ id: user.id, locale, tenant }))
})