minor cosmetics for user service
This commit is contained in:
@@ -44,9 +44,9 @@ const books = Vue.createApp ({
|
|||||||
|
|
||||||
async fetchUserInfo() {
|
async fetchUserInfo() {
|
||||||
try {
|
try {
|
||||||
books.user = (await axios.get('/user/Me')).data
|
const { data } = await axios.get('/user/me')
|
||||||
if (!books.user.ID) books.user.ID = 'anonymous'
|
books.user = data
|
||||||
} catch (err) { books.user = {}; books.user.ID = err.message }
|
} catch (err) { books.user = { id: err.message } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).mount("#app")
|
}).mount("#app")
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
<div id='app'>
|
<div id='app'>
|
||||||
|
|
||||||
<div v-if="user" class="user">
|
<div v-if="user" class="user">
|
||||||
<div>User: {{ user.ID || 'anonymous' }}</div>
|
<div>User: {{ user.id || 'anonymous' }}</div>
|
||||||
<div>Locale: {{ user.locale }}</div>
|
<div>Locale: {{ user.locale }}</div>
|
||||||
<div v-if="user.tenant">Tenant: {{ user.tenant }}</div>
|
<div v-if="user.tenant">Tenant: {{ user.tenant }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
/**
|
/**
|
||||||
* Exposes user information
|
* Exposes user information
|
||||||
*/
|
*/
|
||||||
@requires : 'authenticated-user'
|
@requires: 'authenticated-user'
|
||||||
service UserService {
|
service UserService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current user
|
* The current user
|
||||||
*/
|
*/
|
||||||
@odata.singleton
|
@odata.singleton entity me {
|
||||||
entity Me {
|
id : String; // user id
|
||||||
ID : String;
|
|
||||||
locale : String;
|
locale : String;
|
||||||
tenant : String;
|
tenant : String;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,4 @@
|
|||||||
const cds = require('@sap/cds');
|
const cds = require('@sap/cds')
|
||||||
|
|
||||||
module.exports = cds.service.impl((srv) => {
|
module.exports = cds.service.impl((srv) => {
|
||||||
srv.on('READ', 'Me', ({ user }) => {
|
srv.on('READ', 'me', ({ tenant, user, locale }) => ({ id: user.id, locale, tenant }))
|
||||||
return {
|
})
|
||||||
ID: user.id,
|
|
||||||
locale: user.locale,
|
|
||||||
tenant: user.tenant,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -80,12 +80,12 @@ describe('Misc', () => {
|
|||||||
|
|
||||||
it('serves user info', async () => {
|
it('serves user info', async () => {
|
||||||
{
|
{
|
||||||
const { data } = await GET (`/user/Me`)
|
const { data } = await GET (`/user/me`)
|
||||||
expect(data).to.containSubset({ ID: 'alice', locale:'en', tenant: null })
|
expect(data).to.containSubset({ id: 'alice', locale:'en', tenant: null })
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const { data } = await GET (`/user/Me`, {auth: { username: 'joe' }})
|
const { data } = await GET (`/user/me`, {auth: { username: 'joe' }})
|
||||||
expect(data).to.containSubset({ ID: 'joe', locale:'en', tenant: null })
|
expect(data).to.containSubset({ id: 'joe', locale:'en', tenant: null })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user