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", "name": "approuter",
"dependencies": { "dependencies": {
"@sap/approuter": "^10" "@sap/approuter": "^10"
},
"engines": {
"node": "^16"
} }
}, },
"node_modules/@sap/approuter": { "node_modules/@sap/approuter": {

View File

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

View File

@@ -9,7 +9,8 @@ const books = Vue.createApp ({
return { return {
list: [], list: [],
book: undefined, 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 book.stock = res.data.stock
books.order = { quantity, succeeded: `Successfully ordered ${quantity} item(s).` } books.order = { quantity, succeeded: `Successfully ordered ${quantity} item(s).` }
} catch (e) { } 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 // initially fill list of books
books.fetch() 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 } .rating-stars { color:teal }
.succeeded { color:teal } .succeeded { color:teal }
.failed { color:red } .failed { color:red }
.user {text-align: end; color: grey;}
</style> </style>
</head> </head>
<body class="small-container", style="margin-top: 70px;"> <body class="small-container", style="margin-top: 70px;">
<div id='app'> <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> <h1> Capire Books </h1>
<input type="text" placeholder="Search..." @input="search"> <input type="text" placeholder="Search..." @input="search">

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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