minor cosmetics for user service
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 }))
|
||||
})
|
||||
|
||||
@@ -80,12 +80,12 @@ describe('Misc', () => {
|
||||
|
||||
it('serves user info', async () => {
|
||||
{
|
||||
const { data } = await GET (`/user/Me`)
|
||||
expect(data).to.containSubset({ ID: 'alice', locale:'en', tenant: null })
|
||||
const { data } = await GET (`/user/me`)
|
||||
expect(data).to.containSubset({ id: 'alice', locale:'en', tenant: null })
|
||||
}
|
||||
{
|
||||
const { data } = await GET (`/user/Me`, {auth: { username: 'joe' }})
|
||||
expect(data).to.containSubset({ ID: 'joe', locale:'en', tenant: null })
|
||||
const { data } = await GET (`/user/me`, {auth: { username: 'joe' }})
|
||||
expect(data).to.containSubset({ id: 'joe', locale:'en', tenant: null })
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user