Compare commits
5 Commits
performanc
...
trying-esm
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
518429e2a0 | ||
|
|
02000f4a94 | ||
|
|
8f5c33f4f5 | ||
|
|
a893184736 | ||
|
|
9370d0544e |
@@ -10,7 +10,7 @@ const books = Vue.createApp ({
|
||||
list: [],
|
||||
book: undefined,
|
||||
order: { quantity:1, succeeded:'', failed:'' },
|
||||
user: {}
|
||||
user: undefined
|
||||
}
|
||||
},
|
||||
|
||||
@@ -42,19 +42,25 @@ const books = Vue.createApp ({
|
||||
}
|
||||
},
|
||||
|
||||
async fetchUserInfo() {
|
||||
async login() {
|
||||
try {
|
||||
const { data } = await axios.get('/user/me')
|
||||
books.user = data
|
||||
const { data:user } = await axios.post('/user/login',{})
|
||||
if (user.id !== 'anonymous') books.user = user
|
||||
} catch (err) { books.user = { id: err.message } }
|
||||
}
|
||||
},
|
||||
|
||||
async getUserInfo() {
|
||||
try {
|
||||
const { data:user } = await axios.get('/user/me')
|
||||
if (user.id !== 'anonymous') books.user = user
|
||||
} catch (err) { books.user = { id: err.message } }
|
||||
},
|
||||
}
|
||||
}).mount("#app")
|
||||
|
||||
// initially fill list of books
|
||||
books.fetch()
|
||||
books.getUserInfo()
|
||||
books.fetch() // initially fill list of books
|
||||
|
||||
books.fetchUserInfo()
|
||||
document.addEventListener('keydown', (event) => {
|
||||
// hide user info on request
|
||||
if (event.key === 'u') books.user = undefined
|
||||
|
||||
@@ -18,11 +18,17 @@
|
||||
<body class="small-container", style="margin-top: 70px;">
|
||||
<div id='app'>
|
||||
|
||||
<div v-if="user" class="user">
|
||||
<div>User: {{ user.id || 'anonymous' }}</div>
|
||||
<div>Locale: {{ user.locale }}</div>
|
||||
<form class="user" @submit.prevent="login">
|
||||
<div v-if="user">
|
||||
<div v-if="user.tenant">Tenant: {{ user.tenant }}</div>
|
||||
<div> User: {{ user.id }}</div>
|
||||
<div>Locale: {{ user.locale }}</div>
|
||||
</div>
|
||||
<div v-else>
|
||||
<input type="submit" value="Login" class="muted-button">
|
||||
<!-- <a href="/user/login()">Login</a> -->
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<h1> Capire Books </h1>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* currencies, if not obtained through @capire/common.
|
||||
*/
|
||||
|
||||
module.exports = async (db)=>{
|
||||
export default async (db)=>{
|
||||
|
||||
const has_common = db.model.definitions['sap.common.Currencies'].elements.numcode
|
||||
if (has_common) return
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
const { CatalogService } = require('./srv/cat-service')
|
||||
module.exports = { CatalogService }
|
||||
import { CatalogService } from './srv/cat-service.js'
|
||||
export { CatalogService }
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"name": "@capire/bookshop",
|
||||
"version": "1.0.0",
|
||||
"description": "A simple self-contained bookshop service.",
|
||||
"type": "module",
|
||||
"files": [
|
||||
"app",
|
||||
"srv",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const cds = require('@sap/cds')
|
||||
import cds from '@sap/cds'
|
||||
|
||||
module.exports = cds.service.impl (function(){
|
||||
export default cds.service.impl (function(){
|
||||
this.before ('NEW','Authors', genid)
|
||||
this.before ('NEW','Books', genid)
|
||||
})
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const cds = require('@sap/cds')
|
||||
import cds from '@sap/cds'
|
||||
|
||||
class CatalogService extends cds.ApplicationService { init(){
|
||||
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 => {
|
||||
@@ -24,5 +24,3 @@ class CatalogService extends cds.ApplicationService { init(){
|
||||
|
||||
return super.init()
|
||||
}}
|
||||
|
||||
module.exports = { CatalogService }
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
const cds = require('@sap/cds')
|
||||
module.exports = cds.service.impl((srv) => {
|
||||
srv.on('READ', 'me', ({ tenant, user, locale }) => ({ id: user.id, locale, tenant }))
|
||||
})
|
||||
import cds from '@sap/cds'
|
||||
|
||||
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')
|
||||
})
|
||||
}}
|
||||
|
||||
12
package-lock.json
generated
12
package-lock.json
generated
@@ -1172,9 +1172,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@sap/cds": {
|
||||
"version": "5.9.5",
|
||||
"resolved": "https://registry.npmjs.org/@sap/cds/-/cds-5.9.5.tgz",
|
||||
"integrity": "sha512-H/LIB7WnJ3JKzywnfYd9fOLDKVQokO6/JMUUXbCx+VllYuIQFwClwZ+uYQDgWYSrHePRpuOP5TxLFuMXvhdaag==",
|
||||
"version": "5.9.6",
|
||||
"resolved": "https://registry.npmjs.org/@sap/cds/-/cds-5.9.6.tgz",
|
||||
"integrity": "sha512-zzDoRrgAbRXUQ2n+BrDErtAyylMgcJxgWhsiJvjiZVMxAucJMPp9V+WlRsaGwSm8O6STC6NHcv9PWQ7500y9EQ==",
|
||||
"dependencies": {
|
||||
"@sap-cloud-sdk/core": "^1.41",
|
||||
"@sap-cloud-sdk/util": "^1.41",
|
||||
@@ -8086,9 +8086,9 @@
|
||||
}
|
||||
},
|
||||
"@sap/cds": {
|
||||
"version": "5.9.5",
|
||||
"resolved": "https://registry.npmjs.org/@sap/cds/-/cds-5.9.5.tgz",
|
||||
"integrity": "sha512-H/LIB7WnJ3JKzywnfYd9fOLDKVQokO6/JMUUXbCx+VllYuIQFwClwZ+uYQDgWYSrHePRpuOP5TxLFuMXvhdaag==",
|
||||
"version": "5.9.6",
|
||||
"resolved": "https://registry.npmjs.org/@sap/cds/-/cds-5.9.6.tgz",
|
||||
"integrity": "sha512-zzDoRrgAbRXUQ2n+BrDErtAyylMgcJxgWhsiJvjiZVMxAucJMPp9V+WlRsaGwSm8O6STC6NHcv9PWQ7500y9EQ==",
|
||||
"requires": {
|
||||
"@sap-cloud-sdk/core": "^1.41",
|
||||
"@sap-cloud-sdk/util": "^1.41",
|
||||
|
||||
Reference in New Issue
Block a user