This commit is contained in:
Christian Georgi
2022-03-23 20:30:02 +01:00
parent 7f9474244b
commit 1f8a78fe8a
11 changed files with 1872 additions and 45 deletions

View File

@@ -1 +0,0 @@
Hello World

View File

@@ -7,6 +7,9 @@
"name": "approuter",
"dependencies": {
"@sap/approuter": "^10"
},
"engines": {
"node": "^16"
}
},
"node_modules/@sap/approuter": {

View File

@@ -3,6 +3,9 @@
"dependencies": {
"@sap/approuter": "^10"
},
"engines": {
"node": "^16"
},
"scripts": {
"start": "node node_modules/@sap/approuter/approuter.js"
}

View File

@@ -9,7 +9,8 @@ const books = Vue.createApp ({
return {
list: [],
book: undefined,
order: { quantity:1, succeeded:'', failed:'' }
order: { quantity:1, succeeded:'', failed:'' },
user: {}
}
},
@@ -37,7 +38,7 @@ const books = Vue.createApp ({
book.stock = res.data.stock
books.order = { quantity, succeeded: `Successfully ordered ${quantity} item(s).` }
} catch (e) {
books.order = { quantity, failed: e.response.data.error.message }
books.order = { quantity, failed: e.response.data.error ? e.response.data.error.message : e.response.data }
}
}
@@ -46,3 +47,12 @@ const books = Vue.createApp ({
// initially fill list of books
books.fetch()
// show user info on request
document.addEventListener('keydown', async (event) => {
if (event.key === 'u') {
try {
books.user = (await axios.get('/user/User')).data
} catch (err) { }
}
})

View File

@@ -11,12 +11,19 @@
.rating-stars { color:teal }
.succeeded { color:teal }
.failed { color:red }
.user {text-align: end; color: grey;}
</style>
</head>
<body class="small-container", style="margin-top: 70px;">
<div id='app'>
<div v-if="user.ID && user.ID !== 'anonymous'" class="user">
<div>User: {{ user.ID }}</div>
<div>Locale: {{ user.locale }}</div>
<div>Tenant: {{ user.tenant }}</div>
</div>
<h1> Capire Books </h1>
<input type="text" placeholder="Search..." @input="search">

View File

@@ -1,19 +1,19 @@
{
"welcomeFile": "/app/index.html",
"authenticationMethod": "route",
"routes": [
{
"source": "^/app/(.*)$",
"cacheControl": "no-cache, no-store, must-revalidate",
"target": "$1",
"localDir": ".",
"authenticationType": "xsuaa"
"authenticationType": "xsuaa",
"cacheControl": "no-cache, no-store, must-revalidate"
},
{
"source": "^/api/(.*)$",
"source": "^/(.*)$",
"target": "$1",
"destination": "srv-api",
"authenticationType": "xsuaa",
"target": "$1"
"csrfProtection": false
}
]
}

View File

@@ -9,7 +9,6 @@ build-parameters:
before-all:
- builder: custom
commands:
- npm ci
- npx -p @sap/cds-dk cds build --production
modules:

File diff suppressed because it is too large Load Diff

View File

@@ -10,7 +10,7 @@
"index.js"
],
"dependencies": {
"@sap/cds": "file:/Users/d031150/SAPDevelop/cdx/dev/cds",
"@sap/cds": "^5",
"@sap/cds-mtx": "^2",
"@sap/xssec": "^3",
"express": "^4.17.1",
@@ -25,15 +25,20 @@
"cds": {
"requires": {
"db": {
"kind": "hana-mt"
"kind": "sql"
},
"auth": {
"kind": "xsuaa"
},
"approuter": {
"kind": "cloudfoundry"
},
"multitenancy": true
"[production]": {
"db": {
"kind": "hana-mt"
},
"auth": {
"kind": "xsuaa"
},
"multitenancy": true,
"approuter": {
"kind": "cloudfoundry"
}
}
},
"mtx": {
"element-prefix": "Z_",

View File

@@ -0,0 +1,11 @@
@requires : 'authenticated-user'
service UserService {
@odata.singleton
entity User {
ID : String;
locale : String;
tenant : String;
}
}

View File

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