Compare commits
2 Commits
new-capire
...
multimodul
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61d6c0d58f | ||
|
|
4179493ce7 |
31
.eslintrc
Normal file
31
.eslintrc
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"extends": [
|
||||||
|
"plugin:@sap/cds/recommended",
|
||||||
|
"eslint:recommended"
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
"browser": true,
|
||||||
|
"es2022": true,
|
||||||
|
"node": true,
|
||||||
|
"jest": true,
|
||||||
|
"mocha": true
|
||||||
|
},
|
||||||
|
"globals": {
|
||||||
|
"SELECT": true,
|
||||||
|
"INSERT": true,
|
||||||
|
"UPSERT": true,
|
||||||
|
"UPDATE": true,
|
||||||
|
"DELETE": true,
|
||||||
|
"CREATE": true,
|
||||||
|
"DROP": true,
|
||||||
|
"CDL": true,
|
||||||
|
"CQL": true,
|
||||||
|
"cds": true
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"no-console": "off",
|
||||||
|
"require-atomic-updates": "off",
|
||||||
|
"require-await":"warn",
|
||||||
|
"no-unused-vars": ["warn", { "argsIgnorePattern": "_" }]
|
||||||
|
}
|
||||||
|
}
|
||||||
3
.github/dependabot.yml
vendored
3
.github/dependabot.yml
vendored
@@ -15,6 +15,3 @@ updates:
|
|||||||
- dependency-name: "chai"
|
- dependency-name: "chai"
|
||||||
# chai 5 doesn't work atm w/ cds.test, TODO fix that in cds.test
|
# chai 5 doesn't work atm w/ cds.test, TODO fix that in cds.test
|
||||||
versions: ["5.x"]
|
versions: ["5.x"]
|
||||||
- dependency-name: "chai-as-promised"
|
|
||||||
# chai-as-promised 8 doesn't work atm w/ cds.test, TODO fix that in cds.test
|
|
||||||
versions: ["8.x"]
|
|
||||||
|
|||||||
18
.github/workflows/node.js.yml
vendored
18
.github/workflows/node.js.yml
vendored
@@ -11,28 +11,18 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [22.x, 20.x, 18.x]
|
node-version: [20.x, 18.x]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v2
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
- name: Use Node.js ${{ matrix.node-version }}
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node-version }}
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm test
|
- run: npm test
|
||||||
|
|
||||||
lint:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 22.x
|
|
||||||
- run: npm ci
|
|
||||||
- run: npm run lint
|
|
||||||
|
|||||||
10
.vscode/settings.json
vendored
10
.vscode/settings.json
vendored
@@ -13,5 +13,13 @@
|
|||||||
"**/cds/lib/req/cds-context.js",
|
"**/cds/lib/req/cds-context.js",
|
||||||
"**/odata-v4/okra/**"
|
"**/odata-v4/okra/**"
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
"eslint.probe": [
|
||||||
|
"cds",
|
||||||
|
"csn",
|
||||||
|
"csv",
|
||||||
|
"csv (semicolon)",
|
||||||
|
"tsv",
|
||||||
|
"tab"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ Find here a collection of samples for the [SAP Cloud Application Programming Mod
|
|||||||
|
|
||||||
### Preliminaries
|
### Preliminaries
|
||||||
|
|
||||||
1. Ensure you have the latest LTS version of Node.js installed (see [Getting Started](https://cap.cloud.sap/docs/get-started/jumpstart))
|
1. Ensure you have the latest LTS version of Node.js installed (see [Getting Started](https://cap.cloud.sap/docs/get-started/))
|
||||||
2. Install [**@sap/cds-dk**](https://cap.cloud.sap/docs/get-started/) globally:
|
2. Install [**@sap/cds-dk**](https://cap.cloud.sap/docs/get-started/) globally:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@@ -36,7 +36,7 @@ cd samples
|
|||||||
In the samples folder run:
|
In the samples folder run:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
npm ci
|
npm install
|
||||||
```
|
```
|
||||||
|
|
||||||
### Run
|
### Run
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ const books = Vue.createApp ({
|
|||||||
search: ({target:{value:v}}) => books.fetch(v && '&$search='+v),
|
search: ({target:{value:v}}) => books.fetch(v && '&$search='+v),
|
||||||
|
|
||||||
async fetch (etc='') {
|
async fetch (etc='') {
|
||||||
const {data} = await GET(`/Books?${etc}`)
|
const {data} = await GET(`/ListOfBooks?$expand=genre,currency${etc}`)
|
||||||
books.list = data.value
|
books.list = data.value
|
||||||
},
|
},
|
||||||
|
|
||||||
async inspect (eve) {
|
async inspect (eve) {
|
||||||
const book = books.book = books.list [eve.currentTarget.rowIndex-1]
|
const book = books.book = books.list [eve.currentTarget.rowIndex-1]
|
||||||
const res = await GET(`/Book/${book.ID}?$select=descr,stock,image`)
|
const res = await GET(`/Books/${book.ID}?$select=descr,stock,image`)
|
||||||
Object.assign (book, res.data)
|
Object.assign (book, res.data)
|
||||||
books.order = { quantity:1 }
|
books.order = { quantity:1 }
|
||||||
setTimeout (()=> $('form > input').focus(), 111)
|
setTimeout (()=> $('form > input').focus(), 111)
|
||||||
@@ -77,7 +77,7 @@ function csrfToken (request) {
|
|||||||
document.csrfToken = token
|
document.csrfToken = token
|
||||||
request.headers['x-csrf-token'] = document.csrfToken
|
request.headers['x-csrf-token'] = document.csrfToken
|
||||||
return request
|
return request
|
||||||
}).catch(() => {
|
}).catch(_ => {
|
||||||
document.csrfToken = null // set mark to not try again
|
document.csrfToken = null // set mark to not try again
|
||||||
return request
|
return request
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -45,11 +45,11 @@
|
|||||||
<tr v-for="book in list" v-bind:id="book.ID" v-on:click="inspect">
|
<tr v-for="book in list" v-bind:id="book.ID" v-on:click="inspect">
|
||||||
<td>{{ book.title }}</td>
|
<td>{{ book.title }}</td>
|
||||||
<td>{{ book.author }}</td>
|
<td>{{ book.author }}</td>
|
||||||
<td>{{ book.genre }}</td>
|
<td>{{ book.genre.name }}</td>
|
||||||
<td class="rating-stars">
|
<td class="rating-stars">
|
||||||
{{ ('★'.repeat(Math.round(book.rating))+'☆☆☆☆☆').slice(0,5) }} ({{ book.numberOfReviews }})
|
{{ ('★'.repeat(Math.round(book.rating))+'☆☆☆☆☆').slice(0,5) }} ({{ book.numberOfReviews }})
|
||||||
</td>
|
</td>
|
||||||
<td>{{ book.currency }} {{ book.price }}</td>
|
<td>{{ book.currency && book.currency.symbol }} {{ book.price }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
const cds = require('@sap/cds')
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In order to keep basic bookshop sample as simple as possible, we don't add
|
* In order to keep basic bookshop sample as simple as possible, we don't add
|
||||||
* reuse dependencies. This db/init.js ensures we still have a minimum set of
|
* reuse dependencies. This db/init.js ensures we still have a minimum set of
|
||||||
@@ -8,7 +6,7 @@ const cds = require('@sap/cds')
|
|||||||
|
|
||||||
// NOTE: We use cds.on('served') to delay the UPSERTs after the db init
|
// NOTE: We use cds.on('served') to delay the UPSERTs after the db init
|
||||||
// to run after all INSERTs from .csv files happened.
|
// to run after all INSERTs from .csv files happened.
|
||||||
module.exports = cds.on('served', ()=>
|
module.exports = cds.on('served', ()=> cds.run(
|
||||||
UPSERT.into ('sap.common.Currencies') .columns (
|
UPSERT.into ('sap.common.Currencies') .columns (
|
||||||
[ 'code', 'symbol', 'name' ]
|
[ 'code', 'symbol', 'name' ]
|
||||||
) .rows (
|
) .rows (
|
||||||
@@ -18,4 +16,4 @@ module.exports = cds.on('served', ()=>
|
|||||||
[ 'ILS', '₪', 'Shekel' ],
|
[ 'ILS', '₪', 'Shekel' ],
|
||||||
[ 'JPY', '¥', 'Yen' ],
|
[ 'JPY', '¥', 'Yen' ],
|
||||||
)
|
)
|
||||||
)
|
))
|
||||||
|
|||||||
2
bookshop/index.js
Normal file
2
bookshop/index.js
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
const { CatalogService } = require('./srv/cat-service')
|
||||||
|
module.exports = { CatalogService }
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
"@cap-js/sqlite": "*"
|
"@cap-js/sqlite": "*"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sap/cds": ">=7",
|
"@sap/cds": "^7",
|
||||||
"express": "^4.17.1"
|
"express": "^4.17.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using { sap.capire.bookshop as my } from '../db/schema';
|
using { sap.capire.bookshop as my } from '../db/schema';
|
||||||
service AdminService @(requires:'admin', path:'/admin') {
|
service AdminService @(requires:'admin', path:'/admin') {
|
||||||
entity Books as projection on my.Books;
|
entity Books as projection on my.Books;
|
||||||
// entity Authors as projection on my.Authors;
|
entity Authors as projection on my.Authors;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
const cds = require('@sap/cds')
|
const cds = require('@sap/cds/lib')
|
||||||
|
|
||||||
module.exports = class AdminService extends cds.ApplicationService { init(){
|
module.exports = class AdminService extends cds.ApplicationService { init(){
|
||||||
this.before (['NEW','CREATE'],'Authors', genid)
|
this.before ('NEW','Authors', genid)
|
||||||
this.before (['NEW','CREATE'],'Books', genid)
|
this.before ('NEW','Books', genid)
|
||||||
return super.init()
|
return super.init()
|
||||||
}}
|
}}
|
||||||
|
|
||||||
/** Generate primary keys for target entity in request */
|
/** Generate primary keys for target entity in request */
|
||||||
async function genid (req) {
|
async function genid (req) {
|
||||||
if (req.data.ID) return
|
|
||||||
const {id} = await SELECT.one.from(req.target).columns('max(ID) as id')
|
const {id} = await SELECT.one.from(req.target).columns('max(ID) as id')
|
||||||
req.data.ID = id + 4 // Note: that is not safe! ok for this sample only.
|
req.data.ID = id - id % 100 + 100 + 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,20 +2,15 @@ using { sap.capire.bookshop as my } from '../db/schema';
|
|||||||
service CatalogService @(path:'/browse') {
|
service CatalogService @(path:'/browse') {
|
||||||
|
|
||||||
/** For displaying lists of Books */
|
/** For displaying lists of Books */
|
||||||
@readonly entity Books as projection on Book excluding { descr };
|
@readonly entity ListOfBooks as projection on Books
|
||||||
|
excluding { descr };
|
||||||
|
|
||||||
/** For display in details pages */
|
/** For display in details pages */
|
||||||
@readonly entity Book as projection on my.Books { *,
|
@readonly entity Books as projection on my.Books { *,
|
||||||
currency.name as currencyName, // flattened
|
author.name as author
|
||||||
currency.symbol as currency, // flattened
|
} excluding { createdBy, modifiedBy };
|
||||||
author.name as author, // flattened
|
|
||||||
genre.name as genre, // flattened
|
|
||||||
} excluding {
|
|
||||||
createdBy, modifiedBy, // as end users shouldn't see them
|
|
||||||
localized, texts, // as end users don't need them
|
|
||||||
};
|
|
||||||
|
|
||||||
@requires: 'authenticated-user'
|
@requires: 'authenticated-user'
|
||||||
action submitOrder ( book: Book:ID, quantity: Integer ) returns { stock: Integer };
|
action submitOrder ( book: Books:ID, quantity: Integer ) returns { stock: Integer };
|
||||||
event OrderedBook : { book: Book:ID; quantity: Integer; buyer: String };
|
event OrderedBook : { book: Books:ID; quantity: Integer; buyer: String };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
const cds = require('@sap/cds')
|
module.exports = class CatalogService extends cds.ApplicationService { init() {
|
||||||
|
|
||||||
class CatalogService extends cds.ApplicationService { init() {
|
|
||||||
|
|
||||||
const { Books } = cds.entities('sap.capire.bookshop')
|
const { Books } = cds.entities('sap.capire.bookshop')
|
||||||
const { Books:Book } = this.entities
|
const { ListOfBooks } = this.entities
|
||||||
|
|
||||||
// Add some discount for overstocked books
|
// Add some discount for overstocked books
|
||||||
this.after('each', Book, book => {
|
this.after('each', ListOfBooks, book => {
|
||||||
if (book.stock > 111) book.title += ` -- 11% discount!`
|
if (book.stock > 111) book.title += ` -- 11% discount!`
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -34,5 +32,3 @@ class CatalogService extends cds.ApplicationService { init() {
|
|||||||
// Delegate requests to the underlying generic service
|
// Delegate requests to the underlying generic service
|
||||||
return super.init()
|
return super.init()
|
||||||
}}
|
}}
|
||||||
|
|
||||||
module.exports = CatalogService
|
|
||||||
|
|||||||
@@ -3,15 +3,15 @@
|
|||||||
# Genres
|
# Genres
|
||||||
#
|
#
|
||||||
|
|
||||||
GET http://localhost:4004/odata/v4/test/Genres?
|
GET http://localhost:4004/test/Genres?
|
||||||
###
|
###
|
||||||
|
|
||||||
GET http://localhost:4004/odata/v4/test/Genres?
|
GET http://localhost:4004/test/Genres?
|
||||||
&$filter=parent_ID eq null&$select=name
|
&$filter=parent_ID eq null&$select=name
|
||||||
&$expand=children($select=name)
|
&$expand=children($select=name)
|
||||||
###
|
###
|
||||||
|
|
||||||
POST http://localhost:4004/odata/v4/test/Genres?
|
POST http://localhost:4004/test/Genres?
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
{ "ID":100, "name":"Some Sample Genres...", "children":[
|
{ "ID":100, "name":"Some Sample Genres...", "children":[
|
||||||
@@ -26,13 +26,13 @@ Content-Type: application/json
|
|||||||
]}
|
]}
|
||||||
###
|
###
|
||||||
|
|
||||||
GET http://localhost:4004/odata/v4/test/Genres(100)?
|
GET http://localhost:4004/test/Genres(100)?
|
||||||
# &$expand=children
|
# &$expand=children
|
||||||
# &$expand=children($expand=children($expand=children($expand=children)))
|
# &$expand=children($expand=children($expand=children($expand=children)))
|
||||||
###
|
###
|
||||||
|
|
||||||
DELETE http://localhost:4004/odata/v4/test/Genres(103)
|
DELETE http://localhost:4004/test/Genres(103)
|
||||||
###
|
###
|
||||||
|
|
||||||
DELETE http://localhost:4004/odata/v4/test/Genres(100)
|
DELETE http://localhost:4004/test/Genres(100)
|
||||||
###
|
###
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
@server = http://localhost:4004
|
@server = http://localhost:4004
|
||||||
@me = Authorization: Basic {{$processEnv USER}}:
|
@me = Authorization: Basic {{$processEnv USER}}:
|
||||||
@alice = Authorization: Basic alice:
|
|
||||||
|
|
||||||
|
|
||||||
### ------------------------------------------------------------------------
|
### ------------------------------------------------------------------------
|
||||||
@@ -17,11 +16,11 @@ GET {{server}}/browse/$metadata
|
|||||||
|
|
||||||
### ------------------------------------------------------------------------
|
### ------------------------------------------------------------------------
|
||||||
# Browse Books as any user
|
# Browse Books as any user
|
||||||
GET {{server}}/admin/Books?
|
GET {{server}}/browse/ListOfBooks?
|
||||||
# &$select=title,stock
|
# &$select=title,stock
|
||||||
&$expand=genre
|
&$expand=genre
|
||||||
# &sap-language=de
|
# &sap-language=de
|
||||||
{{alice}}
|
{{me}}
|
||||||
|
|
||||||
|
|
||||||
### ------------------------------------------------------------------------
|
### ------------------------------------------------------------------------
|
||||||
@@ -31,13 +30,13 @@ GET {{server}}/admin/Authors?
|
|||||||
# &$expand=books($select=title;$expand=currency)
|
# &$expand=books($select=title;$expand=currency)
|
||||||
# &$filter=ID eq 101
|
# &$filter=ID eq 101
|
||||||
# &sap-language=de
|
# &sap-language=de
|
||||||
{{alice}}
|
Authorization: Basic alice:
|
||||||
|
|
||||||
### ------------------------------------------------------------------------
|
### ------------------------------------------------------------------------
|
||||||
# Create Author
|
# Create Author
|
||||||
POST {{server}}/admin/Authors
|
POST {{server}}/admin/Authors
|
||||||
Content-Type: application/json;IEEE754Compatible=true
|
Content-Type: application/json;IEEE754Compatible=true
|
||||||
{{alice}}
|
Authorization: Basic alice:
|
||||||
|
|
||||||
{
|
{
|
||||||
"ID": 112,
|
"ID": 112,
|
||||||
@@ -50,7 +49,7 @@ Content-Type: application/json;IEEE754Compatible=true
|
|||||||
# Create book
|
# Create book
|
||||||
POST {{server}}/admin/Books
|
POST {{server}}/admin/Books
|
||||||
Content-Type: application/json;IEEE754Compatible=true
|
Content-Type: application/json;IEEE754Compatible=true
|
||||||
{{alice}}
|
Authorization: Basic alice:
|
||||||
|
|
||||||
{
|
{
|
||||||
"ID": 2,
|
"ID": 2,
|
||||||
@@ -68,7 +67,7 @@ Content-Type: application/json;IEEE754Compatible=true
|
|||||||
# Put image to books
|
# Put image to books
|
||||||
PUT {{server}}/admin/Books(2)/image
|
PUT {{server}}/admin/Books(2)/image
|
||||||
Content-Type: image/png
|
Content-Type: image/png
|
||||||
{{alice}}
|
Authorization: Basic alice:
|
||||||
|
|
||||||
data:image/png;base64,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
|
data:image/png;base64,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
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
Books = Bücher
|
|
||||||
Book = Buch
|
|
||||||
Title = Titel
|
|
||||||
Description = Beschreibung
|
|
||||||
Stock = Bestand
|
|
||||||
Image = Bild
|
|
||||||
Price = Preis
|
|
||||||
Currency = Währung
|
|
||||||
|
|
||||||
Authors = Autoren
|
|
||||||
Author = Autor
|
|
||||||
AuthorID = ID des Autors
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
Books = Books
|
|
||||||
Book = Book
|
|
||||||
ID = ID
|
|
||||||
Title = Title
|
|
||||||
Description = Description
|
|
||||||
Stock = Stock
|
|
||||||
Image = Image
|
|
||||||
Price = Price
|
|
||||||
Currency = Currency
|
|
||||||
|
|
||||||
Authors = Authors
|
|
||||||
Author = Author
|
|
||||||
AuthorID = Author''s ID
|
|
||||||
Name = Name
|
|
||||||
DateOfBirth = Date of Birth
|
|
||||||
DateOfDeath = Date of Death
|
|
||||||
PlaceOfBirth = Place of Birth
|
|
||||||
PlaceOfDeath = Place of Death
|
|
||||||
|
|
||||||
Genres = Genres
|
|
||||||
Genre = Genre
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
Books = Livres
|
|
||||||
Book = Livre
|
|
||||||
Title = Titre
|
|
||||||
Description = Description
|
|
||||||
Stock = Action
|
|
||||||
Image = Image
|
|
||||||
Price = Prix
|
|
||||||
Currency = Devise
|
|
||||||
|
|
||||||
Authors = Auteurs
|
|
||||||
Author = Auteur
|
|
||||||
AuthorID = ID de l''auteur
|
|
||||||
Name = Nom
|
|
||||||
DateOfBirth = Date de naissance
|
|
||||||
DateOfDeath = Date de décès
|
|
||||||
PlaceOfBirth = Lieu de naissance
|
|
||||||
PlaceOfDeath = Lieu de décès
|
|
||||||
|
|
||||||
Genres = Genre
|
|
||||||
Genre = Genre
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
400 = Ungültige Anfrage
|
|
||||||
401 = Nicht autorisiert
|
|
||||||
403 = Verboten
|
|
||||||
404 = Nicht gefunden
|
|
||||||
405 = Methode nicht zulässig
|
|
||||||
406 = Nicht akzeptabel
|
|
||||||
407 = Proxy-Authentifizierung erforderlich
|
|
||||||
408 = Anfrage-Timeout
|
|
||||||
409 = Konflikt
|
|
||||||
410 = Weg
|
|
||||||
411 = Erforderliche Länge
|
|
||||||
412 = Vorbedingung fehlgeschlagen
|
|
||||||
413 = Nutzlast zu groß
|
|
||||||
414 = URI zu lang
|
|
||||||
415 = Nicht unterstützter Medientyp
|
|
||||||
416 = Bereich nicht erfüllbar
|
|
||||||
417 = Erwartung fehlgeschlagen
|
|
||||||
422 = Nicht verarbeitbarer Inhalt
|
|
||||||
424 = Fehlgeschlagene Abhängigkeit
|
|
||||||
428 = Vorbedingung erforderlich
|
|
||||||
429 = Zu viele Anfragen
|
|
||||||
431 = Anfrage-Headerfelder zu groß
|
|
||||||
451 = Aus rechtlichen Gründen nicht verfügbar
|
|
||||||
500 = Interner Serverfehler
|
|
||||||
501 = Der Server unterstützt die zur Erfüllung der Anfrage erforderliche Funktionalität nicht
|
|
||||||
502 = Ungültiges Gateway
|
|
||||||
503 = Dienst nicht verfügbar
|
|
||||||
504 = Gateway-Timeout
|
|
||||||
|
|
||||||
ASSERT_RANGE = Wert {0} liegt nicht im angegebenen Bereich [{1}, {2}]
|
|
||||||
ASSERT_FORMAT = Wert "{0}" liegt nicht im angegebenen Format "{1}"
|
|
||||||
ASSERT_ARRAY = Wert muss ein Array sein
|
|
||||||
ASSERT_ENUM = Wert {0} ist gemäß Enumerationsdeklaration {{1}} ungültig
|
|
||||||
ASSERT_NOT_NULL = Wert ist erforderlich
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
400 = Bad Request
|
|
||||||
401 = Unauthorized
|
|
||||||
403 = Forbidden
|
|
||||||
404 = Not Found
|
|
||||||
405 = Method Not Allowed
|
|
||||||
406 = Not Acceptable
|
|
||||||
407 = Proxy Authentication Required
|
|
||||||
408 = Request Timeout
|
|
||||||
409 = Conflict
|
|
||||||
410 = Gone
|
|
||||||
411 = Length Required
|
|
||||||
412 = Precondition Failed
|
|
||||||
413 = Payload Too Large
|
|
||||||
414 = URI Too Long
|
|
||||||
415 = Unsupported Media Type
|
|
||||||
416 = Range Not Satisfiable
|
|
||||||
417 = Expectation Failed
|
|
||||||
422 = Unprocessable Content
|
|
||||||
424 = Failed Dependency
|
|
||||||
428 = Precondition Required
|
|
||||||
429 = Too Many Requests
|
|
||||||
431 = Request Header Fields Too Large
|
|
||||||
451 = Unavailable For Legal Reasons
|
|
||||||
500 = Internal Server Error
|
|
||||||
501 = The server does not support the functionality required to fulfill the request
|
|
||||||
502 = Bad Gateway
|
|
||||||
503 = Service Unavailable
|
|
||||||
504 = Gateway Timeout
|
|
||||||
|
|
||||||
ASSERT_RANGE = Value {0} is not in specified range [{1}, {2}]
|
|
||||||
ASSERT_FORMAT = Value "{0}" is not in specified format "{1}"
|
|
||||||
ASSERT_ARRAY = Value must be an array
|
|
||||||
ASSERT_ENUM = Value {0} is invalid according to enum declaration {{1}}
|
|
||||||
ASSERT_NOT_NULL = Value is required
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
400 = Requête incorrecte
|
|
||||||
401 = Non autorisée
|
|
||||||
403 = Interdite
|
|
||||||
404 = Introuvable
|
|
||||||
405 = Méthode non autorisée
|
|
||||||
406 = Non acceptable
|
|
||||||
407 = Authentification proxy requise
|
|
||||||
408 = Délai d''expiration de la requête
|
|
||||||
409 = Conflit
|
|
||||||
410 = Disparu
|
|
||||||
411 = Longueur requise
|
|
||||||
412 = Échec de la condition préalable
|
|
||||||
413 = Charge utile trop importante
|
|
||||||
414 = URI trop longue
|
|
||||||
415 = Type de média non pris en charge
|
|
||||||
416 = Plage non satisfaisante
|
|
||||||
417 = Échec de l''attente
|
|
||||||
422 = Contenu non traitable
|
|
||||||
424 = Dépendance échouée
|
|
||||||
428 = Condition préalable requise
|
|
||||||
429 = Trop de requêtes
|
|
||||||
431 = Champs d''en-tête de requête trop importants
|
|
||||||
451 = Indisponible pour des raisons juridiques
|
|
||||||
500 = Erreur interne du serveur
|
|
||||||
501 = Le serveur ne prend pas en charge la fonctionnalité requise pour répondre à la requête
|
|
||||||
502 = Passerelle incorrecte
|
|
||||||
503 = Service indisponible
|
|
||||||
504 = Délai d''attente de la passerelle
|
|
||||||
|
|
||||||
ASSERT_RANGE = La valeur {0} n''est pas dans la plage spécifiée [{1}, {2}]
|
|
||||||
ASSERT_FORMAT = La valeur "{0}" n''est pas au format spécifié "{1}"
|
|
||||||
ASSERT_ARRAY = La valeur doit être un tableau
|
|
||||||
ASSERT_ENUM = La valeur {0} n''est pas valide selon la déclaration d''énumération {{1}}
|
|
||||||
ASSERT_NOT_NULL = La valeur est obligatoire
|
|
||||||
43
bookstore/mta.yaml
Normal file
43
bookstore/mta.yaml
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
_schema-version: '3.1'
|
||||||
|
ID: capire.bookstore
|
||||||
|
version: 1.0.0
|
||||||
|
description: "A simple CAP project."
|
||||||
|
parameters:
|
||||||
|
enable-parallel-deployments: true
|
||||||
|
build-parameters:
|
||||||
|
before-all:
|
||||||
|
- builder: custom
|
||||||
|
commands:
|
||||||
|
- npm ci
|
||||||
|
- npx cds build --production
|
||||||
|
modules:
|
||||||
|
- name: bookstore-srv
|
||||||
|
type: nodejs
|
||||||
|
path: gen/srv
|
||||||
|
parameters:
|
||||||
|
buildpack: nodejs_buildpack
|
||||||
|
readiness-health-check-type: http
|
||||||
|
readiness-health-check-http-endpoint: /health
|
||||||
|
build-parameters:
|
||||||
|
builder: npm
|
||||||
|
provides:
|
||||||
|
- name: srv-api # required by consumers of CAP services (e.g. approuter)
|
||||||
|
properties:
|
||||||
|
srv-url: ${default-url}
|
||||||
|
requires:
|
||||||
|
- name: bookstore-destination
|
||||||
|
- name: bookstore-messaging
|
||||||
|
- name: samples-db
|
||||||
|
|
||||||
|
resources:
|
||||||
|
- name: bookstore-destination
|
||||||
|
type: org.cloudfoundry.managed-service
|
||||||
|
parameters:
|
||||||
|
service: destination
|
||||||
|
service-plan: lite
|
||||||
|
- name: bookstore-messaging
|
||||||
|
type: org.cloudfoundry.managed-service
|
||||||
|
parameters:
|
||||||
|
service: enterprise-messaging
|
||||||
|
service-plan: default
|
||||||
|
path: ./event-mesh.json
|
||||||
@@ -21,14 +21,32 @@
|
|||||||
"model": "@capire/orders"
|
"model": "@capire/orders"
|
||||||
},
|
},
|
||||||
"messaging": {
|
"messaging": {
|
||||||
"[development]": { "kind": "file-based-messaging" },
|
"[development]": {
|
||||||
"[hybrid]": { "kind": "enterprise-messaging-shared" },
|
"kind": "file-based-messaging"
|
||||||
"[production]": { "kind": "enterprise-messaging" }
|
|
||||||
},
|
},
|
||||||
|
"[hybrid]": {
|
||||||
|
"kind": "enterprise-messaging-shared"
|
||||||
|
},
|
||||||
|
"[production]": {
|
||||||
|
"kind": "enterprise-messaging"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"db": { "kind": "sql" },
|
||||||
|
"[multimodule]": {
|
||||||
"db": {
|
"db": {
|
||||||
"kind": "sql"
|
"kind": "sqlite",
|
||||||
|
"impl": "@cap-js/sqlite",
|
||||||
|
"credentials": {
|
||||||
|
"url": "../db.sqlite"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"log": { "service": true }
|
"log": {
|
||||||
|
"service": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@sap/cds-dk": "^7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,15 +5,10 @@ cds.once('served', require('./srv/mashup'))
|
|||||||
|
|
||||||
// Add routes to UIs from imported packages
|
// Add routes to UIs from imported packages
|
||||||
cds.once('bootstrap',(app)=>{
|
cds.once('bootstrap',(app)=>{
|
||||||
try {
|
|
||||||
app.serve ('/bookshop') .from ('@capire/bookshop','app/vue')
|
app.serve ('/bookshop') .from ('@capire/bookshop','app/vue')
|
||||||
app.serve ('/reviews') .from ('@capire/reviews','app/vue')
|
app.serve ('/reviews') .from ('@capire/reviews','app/vue')
|
||||||
app.serve ('/orders') .from('@capire/orders','app/orders')
|
app.serve ('/orders') .from('@capire/orders','app/orders')
|
||||||
app.serve ('/data') .from('@capire/data-viewer','app/viewer')
|
app.serve ('/data') .from('@capire/data-viewer','app/viewer')
|
||||||
} catch (err) {
|
|
||||||
if (err.code === 'MODULE_NOT_FOUND') throw new Error('Run "npm ci" to install the required dependencies', { cause: err })
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Add Swagger UI
|
// Add Swagger UI
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ module.exports = async()=>{ // called by server.js
|
|||||||
// Note: prepend is neccessary to intercept generic default handler
|
// Note: prepend is neccessary to intercept generic default handler
|
||||||
//
|
//
|
||||||
CatalogService.prepend (srv => srv.on ('READ', 'Books/reviews', (req) => {
|
CatalogService.prepend (srv => srv.on ('READ', 'Books/reviews', (req) => {
|
||||||
console.debug ('> delegating request to ReviewsService') // eslint-disable-line no-console
|
console.debug ('> delegating request to ReviewsService')
|
||||||
const [id] = req.params, { columns, limit } = req.query.SELECT
|
const [id] = req.params, { columns, limit } = req.query.SELECT
|
||||||
return ReviewsService.read ('Reviews',columns).limit(limit).where({subject:String(id)})
|
return ReviewsService.read ('Reviews',columns).limit(limit).where({subject:String(id)})
|
||||||
}))
|
}))
|
||||||
@@ -40,7 +40,7 @@ module.exports = async()=>{ // called by server.js
|
|||||||
// Update Books' average ratings when ReviewsService signals updated reviews
|
// Update Books' average ratings when ReviewsService signals updated reviews
|
||||||
//
|
//
|
||||||
ReviewsService.on ('reviewed', (msg) => {
|
ReviewsService.on ('reviewed', (msg) => {
|
||||||
console.debug ('> received:', msg.event, msg.data) // eslint-disable-line no-console
|
console.debug ('> received:', msg.event, msg.data)
|
||||||
const { subject, count, rating } = msg.data
|
const { subject, count, rating } = msg.data
|
||||||
return UPDATE(Books,subject).with({ numberOfReviews:count, rating })
|
return UPDATE(Books,subject).with({ numberOfReviews:count, rating })
|
||||||
})
|
})
|
||||||
@@ -49,7 +49,7 @@ module.exports = async()=>{ // called by server.js
|
|||||||
// Reduce stock of ordered books for orders are created from Orders admin UI
|
// Reduce stock of ordered books for orders are created from Orders admin UI
|
||||||
//
|
//
|
||||||
OrdersService.on ('OrderChanged', (msg) => {
|
OrdersService.on ('OrderChanged', (msg) => {
|
||||||
console.debug ('> received:', msg.event, msg.data) // eslint-disable-line no-console
|
console.debug ('> received:', msg.event, msg.data)
|
||||||
const { product, deltaQuantity } = msg.data
|
const { product, deltaQuantity } = msg.data
|
||||||
return UPDATE (Books) .where ('ID =', product)
|
return UPDATE (Books) .where ('ID =', product)
|
||||||
.and ('stock >=', deltaQuantity)
|
.and ('stock >=', deltaQuantity)
|
||||||
|
|||||||
@@ -12,12 +12,11 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
GET {{reviews-service}}/Reviews
|
GET {{reviews-service}}/Reviews
|
||||||
Authorization: Basic me:
|
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
||||||
POST {{reviews-service}}/Reviews
|
POST {{reviews-service}}/Reviews
|
||||||
Authorization: Basic me:
|
Authorization: Basic {{$processEnv USER}}:
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
{"subject":"201", "title":"boo", "rating":3 }
|
{"subject":"201", "title":"boo", "rating":3 }
|
||||||
@@ -51,23 +50,23 @@ Accept-Language: de
|
|||||||
#
|
#
|
||||||
@newOrderID = e939604c-ab83-4d4f-bdb6-95fe30b3773e
|
@newOrderID = e939604c-ab83-4d4f-bdb6-95fe30b3773e
|
||||||
|
|
||||||
GET {{bookshop}}/odata/v4/orders/Orders
|
GET {{bookshop}}/orders/Orders
|
||||||
|
|
||||||
### Create order, still inactive
|
### Create order, still inactive
|
||||||
POST {{bookshop}}/odata/v4/orders/Orders
|
POST {{bookshop}}/orders/Orders
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
{"ID": "{{newOrderID}}"}
|
{"ID": "{{newOrderID}}"}
|
||||||
|
|
||||||
### Get inactive order. We have to specify `IsActiveEntity`.
|
### Get inactive order. We have to specify `IsActiveEntity`.
|
||||||
GET {{bookshop}}/odata/v4/orders/Orders(ID={{newOrderID}},IsActiveEntity=false)
|
GET {{bookshop}}/orders/Orders(ID={{newOrderID}},IsActiveEntity=false)
|
||||||
|
|
||||||
### Activate order using `.../<servicename>.draftActivate`
|
### Activate order using `.../<servicename>.draftActivate`
|
||||||
POST {{bookshop}}/odata/v4/orders/Orders(ID={{newOrderID}},IsActiveEntity=false)/OrdersService.draftActivate
|
POST {{bookshop}}/orders/Orders(ID={{newOrderID}},IsActiveEntity=false)/OrdersService.draftActivate
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
### Get active order
|
### Get active order
|
||||||
GET {{bookshop}}/odata/v4/orders/Orders(ID={{newOrderID}},IsActiveEntity=true)
|
GET {{bookshop}}/orders/Orders(ID={{newOrderID}},IsActiveEntity=true)
|
||||||
|
|
||||||
### Create author
|
### Create author
|
||||||
POST {{bookshop}}/admin/Authors
|
POST {{bookshop}}/admin/Authors
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
// dummy to auto-load the plugin
|
|
||||||
@@ -4,12 +4,5 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sap/cds": "*"
|
"@sap/cds": "*"
|
||||||
},
|
|
||||||
"cds": {
|
|
||||||
"requires": {
|
|
||||||
"@capire/common/data": {
|
|
||||||
"model": "@capire/common"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class DataService extends cds.ApplicationService { init(){
|
|||||||
.sort((e1, e2) => e1.name.localeCompare(e2.name))
|
.sort((e1, e2) => e1.name.localeCompare(e2.name))
|
||||||
.map(e => {
|
.map(e => {
|
||||||
const columns = Object.entries(e.elements)
|
const columns = Object.entries(e.elements)
|
||||||
.filter(([,el]) => !(el instanceof cds.Association)) // exclude assocs+compositions
|
.filter(([_, el]) => !(el instanceof cds.Association)) // exclude assocs+compositions
|
||||||
.map(([name, el]) => { return { name, type: el.type, isKey:!!el.key }})
|
.map(([name, el]) => { return { name, type: el.type, isKey:!!el.key }})
|
||||||
return { name: e.name, columns }
|
return { name: e.name, columns }
|
||||||
})
|
})
|
||||||
@@ -49,7 +49,6 @@ class DataService extends cds.ApplicationService { init(){
|
|||||||
|
|
||||||
module.exports = { DataService }
|
module.exports = { DataService }
|
||||||
|
|
||||||
/** @returns {cds.Service} */
|
|
||||||
function findDataSource(dataSourceName, entityName) {
|
function findDataSource(dataSourceName, entityName) {
|
||||||
for (let srv of Object.values(cds.services)) { // all connected services
|
for (let srv of Object.values(cds.services)) { // all connected services
|
||||||
if (!srv.name) continue // FIXME intermediate/pending in cds.services ?
|
if (!srv.name) continue // FIXME intermediate/pending in cds.services ?
|
||||||
|
|||||||
5
db/sqlite/index.cds
Normal file
5
db/sqlite/index.cds
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
using from '@capire/bookstore';
|
||||||
|
using from '@capire/common';
|
||||||
|
using from '@capire/orders';
|
||||||
|
using from '@capire/reviews';
|
||||||
|
using from '@capire/fiori';
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
import cds from '@sap/cds/eslint.config.mjs'
|
|
||||||
export default [ ...cds.recommended ]
|
|
||||||
|
|
||||||
//
|
|
||||||
// The above is the recommended minimalistic eslint config, just using
|
|
||||||
// recommended defaults provided by cds. Alternatively, go for enhanced
|
|
||||||
// project-specific options, but only if really required, like this:
|
|
||||||
//
|
|
||||||
// export default [ ...cds.recommended, {
|
|
||||||
// rules: {
|
|
||||||
// 'complexity': [ 'warn', 66 ],
|
|
||||||
// 'require-await': 'warn',
|
|
||||||
// 'no-await-in-loop': 'warn',
|
|
||||||
// },
|
|
||||||
// }, {
|
|
||||||
// ignores: [
|
|
||||||
// '**/webapp/**'
|
|
||||||
// ]
|
|
||||||
// }]
|
|
||||||
//
|
|
||||||
43
fiori/app/_i18n/i18n.properties
Normal file
43
fiori/app/_i18n/i18n.properties
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
Books = Books
|
||||||
|
Book = Book
|
||||||
|
ID = ID
|
||||||
|
Title = Title
|
||||||
|
Author = Author
|
||||||
|
AuthorID = Author ID
|
||||||
|
Stock = Stock
|
||||||
|
Name = Name
|
||||||
|
Description = Description
|
||||||
|
Image = Image
|
||||||
|
AuthorName = Author's Name
|
||||||
|
DateOfBirth = Date of Birth
|
||||||
|
DateOfDeath = Date of Death
|
||||||
|
PlaceOfBirth = Place of Birth
|
||||||
|
PlaceOfDeath = Place of Death
|
||||||
|
Age = Age
|
||||||
|
Lifetime = Lifetime
|
||||||
|
Authors = Authors
|
||||||
|
|
||||||
|
Order = Order
|
||||||
|
Orders = Orders
|
||||||
|
OrderNo = Order Number
|
||||||
|
OrderItems = Order Items
|
||||||
|
Customer = Customer
|
||||||
|
Product = Product
|
||||||
|
ProductID = Product ID
|
||||||
|
ProductTitle = Product Title
|
||||||
|
UnitPrice = Unit Price
|
||||||
|
Quantity = Quantity
|
||||||
|
|
||||||
|
Price = Price
|
||||||
|
Currency = Currency
|
||||||
|
Date = Date
|
||||||
|
Rating = Rating
|
||||||
|
NumberOfReviews = Number of Reviews
|
||||||
|
|
||||||
|
Genre = Genre
|
||||||
|
Genres = Genres
|
||||||
|
SubGenres = Sub Genres
|
||||||
|
|
||||||
|
NumCode = Numeric Code
|
||||||
|
MinorUnit = Minor Unit
|
||||||
|
Exponent = Exponent
|
||||||
@@ -1,5 +1,14 @@
|
|||||||
|
Books = Bücher
|
||||||
|
Book = Buch
|
||||||
|
ID = ID
|
||||||
|
Title = Titel
|
||||||
|
Authors = Autoren
|
||||||
|
Author = Autor
|
||||||
|
AuthorID = ID des Autors
|
||||||
AuthorName = Name des Autors
|
AuthorName = Name des Autors
|
||||||
Age = Alter
|
Age = Alter
|
||||||
rder = Bestellung
|
Name = Name
|
||||||
|
Stock = Bestand
|
||||||
|
Order = Bestellung
|
||||||
Orders = Bestellungen
|
Orders = Bestellungen
|
||||||
Price = Preis
|
Price = Preis
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
Age = Age
|
|
||||||
Lifetime = Lifetime
|
|
||||||
|
|
||||||
SubGenres = Sub Genres
|
|
||||||
|
|
||||||
NumCode = Numeric Code
|
|
||||||
MinorUnit = Minor Unit
|
|
||||||
Exponent = Exponent
|
|
||||||
@@ -4,10 +4,10 @@ using CatalogService from '@capire/bookstore';
|
|||||||
//
|
//
|
||||||
// Books Object Page
|
// Books Object Page
|
||||||
//
|
//
|
||||||
annotate CatalogService.Book with @(UI : {
|
annotate CatalogService.Books with @(UI : {
|
||||||
HeaderInfo : {
|
HeaderInfo : {
|
||||||
TypeName : '{i18n>Book}',
|
TypeName : 'Book',
|
||||||
TypeNamePlural : '{i18n>Books}',
|
TypeNamePlural : 'Books',
|
||||||
Description : {Value : author}
|
Description : {Value : author}
|
||||||
},
|
},
|
||||||
HeaderFacets : [{
|
HeaderFacets : [{
|
||||||
@@ -24,7 +24,7 @@ annotate CatalogService.Book with @(UI : {
|
|||||||
FieldGroup #Price : {Data : [
|
FieldGroup #Price : {Data : [
|
||||||
{Value : price},
|
{Value : price},
|
||||||
{
|
{
|
||||||
Value : currencyName,
|
Value : currency.symbol,
|
||||||
Label : '{i18n>Currency}'
|
Label : '{i18n>Currency}'
|
||||||
},
|
},
|
||||||
]},
|
]},
|
||||||
@@ -35,11 +35,11 @@ annotate CatalogService.Book with @(UI : {
|
|||||||
//
|
//
|
||||||
// Books List Page
|
// Books List Page
|
||||||
//
|
//
|
||||||
annotate CatalogService.Book with @(UI : {
|
annotate CatalogService.Books with @(UI : {
|
||||||
SelectionFields : [
|
SelectionFields : [
|
||||||
ID,
|
ID,
|
||||||
price,
|
price,
|
||||||
currencyName
|
currency_code
|
||||||
],
|
],
|
||||||
LineItem : [
|
LineItem : [
|
||||||
{
|
{
|
||||||
@@ -50,10 +50,8 @@ annotate CatalogService.Book with @(UI : {
|
|||||||
Value : author,
|
Value : author,
|
||||||
Label : '{i18n>Author}'
|
Label : '{i18n>Author}'
|
||||||
},
|
},
|
||||||
{Value : genre},
|
{Value : genre.name},
|
||||||
{Value : price},
|
{Value : price},
|
||||||
{Value : currencyName},
|
{Value : currency.symbol},
|
||||||
]
|
]
|
||||||
}) {
|
}, );
|
||||||
currencyName @Common.Label : '{i18n>Currency}';
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ annotate my.Books with @(
|
|||||||
ID,
|
ID,
|
||||||
author_ID,
|
author_ID,
|
||||||
price,
|
price,
|
||||||
|
currency_code
|
||||||
],
|
],
|
||||||
LineItem : [
|
LineItem : [
|
||||||
{ Value: ID, Label: '{i18n>Title}' },
|
{ Value: ID, Label: '{i18n>Title}' },
|
||||||
@@ -25,6 +26,7 @@ annotate my.Books with @(
|
|||||||
{ Value: genre.name },
|
{ Value: genre.name },
|
||||||
{ Value: stock },
|
{ Value: stock },
|
||||||
{ Value: price },
|
{ Value: price },
|
||||||
|
{ Value: currency.symbol },
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
@@ -61,7 +63,7 @@ annotate my.Books with {
|
|||||||
title @title: '{i18n>Title}';
|
title @title: '{i18n>Title}';
|
||||||
genre @title: '{i18n>Genre}' @Common: { Text: genre.name, TextArrangement: #TextOnly };
|
genre @title: '{i18n>Genre}' @Common: { Text: genre.name, TextArrangement: #TextOnly };
|
||||||
author @title: '{i18n>Author}' @Common: { Text: author.name, TextArrangement: #TextOnly };
|
author @title: '{i18n>Author}' @Common: { Text: author.name, TextArrangement: #TextOnly };
|
||||||
price @title: '{i18n>Price}' @Measures.ISOCurrency : currency;
|
price @title: '{i18n>Price}' @Measures.ISOCurrency : currency_code;
|
||||||
stock @title: '{i18n>Stock}';
|
stock @title: '{i18n>Stock}';
|
||||||
descr @title: '{i18n>Description}' @UI.MultiLineText;
|
descr @title: '{i18n>Description}' @UI.MultiLineText;
|
||||||
image @title: '{i18n>Image}';
|
image @title: '{i18n>Image}';
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<!doctype html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
@@ -10,22 +10,21 @@
|
|||||||
<script>
|
<script>
|
||||||
window["sap-ushell-config"] = {
|
window["sap-ushell-config"] = {
|
||||||
defaultRenderer: "fiori2",
|
defaultRenderer: "fiori2",
|
||||||
applications: {},
|
applications: {}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script id="sap-ushell-bootstrap" src="https://ui5.sap.com/test-resources/sap/ushell/bootstrap/sandbox.js"></script>
|
<script id="sap-ushell-bootstrap" src="https://sapui5.hana.ondemand.com/test-resources/sap/ushell/bootstrap/sandbox.js"></script>
|
||||||
<script id="sap-ui-bootstrap" src="https://ui5.sap.com/resources/sap-ui-core.js"
|
<script id="sap-ui-bootstrap" src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
|
||||||
data-sap-ui-libs="sap.m, sap.ushell, sap.collaboration, sap.ui.layout" data-sap-ui-compatVersion="edge"
|
data-sap-ui-libs="sap.m, sap.ushell, sap.collaboration, sap.ui.layout"
|
||||||
data-sap-ui-theme="sap_horizon"></script>
|
data-sap-ui-compatVersion="edge"
|
||||||
|
data-sap-ui-theme="sap_horizon"
|
||||||
|
data-sap-ui-frameOptions="allow"
|
||||||
|
></script>
|
||||||
<script>
|
<script>
|
||||||
sap.ui.getCore().attachInit(() =>
|
sap.ui.getCore().attachInit(()=> sap.ushell.Container.createRenderer().placeAt("content"))
|
||||||
sap.ushell.Container.createRenderer().placeAt("content")
|
|
||||||
);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
<body class="sapUiBody" id="content"></body>
|
||||||
<body class="sapUiBody" id="content">
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
12
fiori/app/router/package.json
Normal file
12
fiori/app/router/package.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "approuter",
|
||||||
|
"dependencies": {
|
||||||
|
"@sap/approuter": "^16.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^20.0.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "node node_modules/@sap/approuter/approuter.js"
|
||||||
|
}
|
||||||
|
}
|
||||||
22
fiori/app/router/xs-app.json
Normal file
22
fiori/app/router/xs-app.json
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"welcomeFile": "app/index.html",
|
||||||
|
"routes": [
|
||||||
|
{
|
||||||
|
"source": "^/app/(.*)$",
|
||||||
|
"target": "$1",
|
||||||
|
"localDir": ".",
|
||||||
|
"cacheControl": "no-cache, no-store, must-revalidate"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"source": "^/appconfig/",
|
||||||
|
"localDir": ".",
|
||||||
|
"cacheControl": "no-cache, no-store, must-revalidate"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"source": "^/(.*)$",
|
||||||
|
"target": "$1",
|
||||||
|
"destination": "srv-api",
|
||||||
|
"csrfProtection": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1 +1,2 @@
|
|||||||
using from './db/common';
|
using from './db/common';
|
||||||
|
using from './app/services';
|
||||||
69
fiori/mta.yaml
Normal file
69
fiori/mta.yaml
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
_schema-version: '3.1'
|
||||||
|
ID: capire.fiori
|
||||||
|
version: 1.0.0
|
||||||
|
description: "A simple CAP project."
|
||||||
|
parameters:
|
||||||
|
enable-parallel-deployments: true
|
||||||
|
build-parameters:
|
||||||
|
before-all:
|
||||||
|
- builder: custom
|
||||||
|
commands:
|
||||||
|
- npm ci
|
||||||
|
- npx cds build --production
|
||||||
|
modules:
|
||||||
|
- name: fiori-srv
|
||||||
|
type: nodejs
|
||||||
|
path: gen/srv
|
||||||
|
parameters:
|
||||||
|
buildpack: nodejs_buildpack
|
||||||
|
readiness-health-check-type: http
|
||||||
|
readiness-health-check-http-endpoint: /health
|
||||||
|
build-parameters:
|
||||||
|
builder: npm
|
||||||
|
provides:
|
||||||
|
- name: srv-api # required by consumers of CAP services (e.g. approuter)
|
||||||
|
properties:
|
||||||
|
srv-url: ${default-url}
|
||||||
|
requires:
|
||||||
|
- name: fiori-auth
|
||||||
|
- name: fiori-destination
|
||||||
|
- name: fiori-messaging
|
||||||
|
- name: samples-db
|
||||||
|
|
||||||
|
- name: fiori
|
||||||
|
type: approuter.nodejs
|
||||||
|
path: app/router
|
||||||
|
parameters:
|
||||||
|
keep-existing-routes: true
|
||||||
|
disk-quota: 256M
|
||||||
|
memory: 256M
|
||||||
|
requires:
|
||||||
|
- name: srv-api
|
||||||
|
group: destinations
|
||||||
|
properties:
|
||||||
|
name: srv-api # must be used in xs-app.json as well
|
||||||
|
url: ~{srv-url}
|
||||||
|
forwardAuthToken: true
|
||||||
|
- name: fiori-auth
|
||||||
|
|
||||||
|
resources:
|
||||||
|
- name: fiori-auth
|
||||||
|
type: org.cloudfoundry.managed-service
|
||||||
|
parameters:
|
||||||
|
service: xsuaa
|
||||||
|
service-plan: application
|
||||||
|
path: ./xs-security.json
|
||||||
|
config:
|
||||||
|
xsappname: fiori-${org}-${space}
|
||||||
|
tenant-mode: dedicated
|
||||||
|
- name: fiori-destination
|
||||||
|
type: org.cloudfoundry.managed-service
|
||||||
|
parameters:
|
||||||
|
service: destination
|
||||||
|
service-plan: lite
|
||||||
|
- name: fiori-messaging
|
||||||
|
type: org.cloudfoundry.managed-service
|
||||||
|
parameters:
|
||||||
|
service: enterprise-messaging
|
||||||
|
service-plan: default
|
||||||
|
path: ./event-mesh.json
|
||||||
@@ -38,6 +38,15 @@
|
|||||||
"db": {
|
"db": {
|
||||||
"kind": "sql"
|
"kind": "sql"
|
||||||
},
|
},
|
||||||
|
"[multimodule]": {
|
||||||
|
"db": {
|
||||||
|
"kind": "sqlite",
|
||||||
|
"impl": "@cap-js/sqlite",
|
||||||
|
"credentials": {
|
||||||
|
"url": "../db.sqlite"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"db-ext": {
|
"db-ext": {
|
||||||
"[development]": {
|
"[development]": {
|
||||||
"model": "db/sqlite"
|
"model": "db/sqlite"
|
||||||
|
|||||||
8
fiori/server.js
Normal file
8
fiori/server.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
// install OData v2 adapter
|
||||||
|
const cds = require("@sap/cds")
|
||||||
|
const proxy = require('@cap-js-community/odata-v2-adapter')
|
||||||
|
const opts = global.it ? { target:'auto' } : {} // for tests, set 'auto' to detect port dynamically
|
||||||
|
cds.on('bootstrap', app => app.use(proxy(opts))) // install proxy
|
||||||
|
// cds.log('cov2ap','silent') // suppress anoying log outpout, e.g. for `npm run mocha -- --reporter nyan`
|
||||||
|
|
||||||
|
module.exports = require('@capire/bookstore/server.js')
|
||||||
22
fiori/xs-security.json
Normal file
22
fiori/xs-security.json
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"scopes": [
|
||||||
|
{
|
||||||
|
"name": "$XSAPPNAME.emcallback",
|
||||||
|
"description": "Enterprise-Messaging Callback Access",
|
||||||
|
"grant-as-authority-to-apps": [
|
||||||
|
"$XSSERVICENAME(fiori-messaging)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "$XSAPPNAME.emmanagement",
|
||||||
|
"description": "Enterprise-Messaging Management Access"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"attributes": [],
|
||||||
|
"role-templates": [],
|
||||||
|
"authorities-inheritance": false,
|
||||||
|
"authorities": [
|
||||||
|
"$XSAPPNAME.emmanagement",
|
||||||
|
"$XSAPPNAME.mtcallback"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -3,10 +3,40 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "npx jest --silent",
|
"test": "npx jest --silent",
|
||||||
"start": "cds-serve srv/world.cds",
|
"start": "cds serve srv/world.cds",
|
||||||
"start:ts": "cds-ts serve srv/world.cds"
|
"start:ts": "cds-ts serve srv/world.cds"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sap/cds": ">=5.0.4"
|
"@sap/cds": ">=5.0.4"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/jest": "*",
|
||||||
|
"@types/node": "*",
|
||||||
|
"typescript": ">=4.3.5"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"extends": "eslint:recommended",
|
||||||
|
"env": {
|
||||||
|
"es2020": true,
|
||||||
|
"node": true,
|
||||||
|
"jest": true,
|
||||||
|
"mocha": true
|
||||||
|
},
|
||||||
|
"globals": {
|
||||||
|
"SELECT": true,
|
||||||
|
"INSERT": true,
|
||||||
|
"UPDATE": true,
|
||||||
|
"DELETE": true,
|
||||||
|
"CREATE": true,
|
||||||
|
"DROP": true,
|
||||||
|
"CDL": true,
|
||||||
|
"CQL": true,
|
||||||
|
"CXL": true,
|
||||||
|
"cds": true
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"no-console": "off",
|
||||||
|
"require-atomic-updates": "off"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
service say {
|
service say @(path: '/say') {
|
||||||
function hello (to:String) returns String;
|
function hello (to:String) returns String;
|
||||||
}
|
}
|
||||||
13
hello/test/hello-world-test.js
Normal file
13
hello/test/hello-world-test.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
const cds = require ('@sap/cds')
|
||||||
|
describe('Hello world!', () => {
|
||||||
|
|
||||||
|
beforeAll (()=> process.env.CDS_TYPESCRIPT = true)
|
||||||
|
afterAll (()=> delete process.env.CDS_TYPESCRIPT)
|
||||||
|
const {GET} = cds.test.in(__dirname,'../srv').run('serve', 'world.cds')
|
||||||
|
|
||||||
|
it('should say hello with class impl', async () => {
|
||||||
|
const {data} = await GET`/say/hello(to='world')`
|
||||||
|
expect(data.value).toMatch(/Hello world.*typescript.*/i)
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
@@ -1,5 +1 @@
|
|||||||
GET http://localhost:4004/odata/v4/say/hello
|
GET http://localhost:4004/say/hello(to='world')
|
||||||
###
|
|
||||||
|
|
||||||
GET http://localhost:4004/odata/v4/say/hello(to='me')
|
|
||||||
###
|
|
||||||
|
|||||||
@@ -13,5 +13,10 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "cds-serve",
|
"start": "cds-serve",
|
||||||
"watch": "cds watch"
|
"watch": "cds watch"
|
||||||
|
},
|
||||||
|
"cds": {
|
||||||
|
"requires": {
|
||||||
|
"db": "sql"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const cds = require ('@sap/cds')
|
const cds = require ('@sap/cds/lib')
|
||||||
const LOG = cds.log('cds.log')
|
const LOG = cds.log('cds.log')
|
||||||
|
|
||||||
module.exports = class LogService extends cds.Service {
|
module.exports = class LogService extends cds.Service {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using { sap.capire.media as db } from '../db/data-model';
|
using { sap.capire.media as db } from '../db/data-model';
|
||||||
namespace sap.capire.media;
|
namespace sap.capire.media;
|
||||||
|
|
||||||
@path: '/media-server'
|
|
||||||
service MediaServer {
|
service MediaServer {
|
||||||
entity Media as projection on db.Media ;
|
entity Media as projection on db.Media ;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ module.exports = srv => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
srv.on('UPDATE', 'Media', (req, next) => {
|
srv.on('UPDATE', 'Media', (req, next) => {
|
||||||
const url = req.path
|
const url = req._.req.path
|
||||||
if (url.includes('content')) {
|
if (url.includes('content')) {
|
||||||
const id = req.data.id
|
const id = req.data.id
|
||||||
const obj = mediaDB.get(id)
|
const obj = mediaDB.get(id)
|
||||||
@@ -32,7 +32,7 @@ module.exports = srv => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
srv.on('READ', 'Media', (req, next) => {
|
srv.on('READ', 'Media', (req, next) => {
|
||||||
const url = req.path
|
const url = req._.req.path
|
||||||
if (url.includes('content')) {
|
if (url.includes('content')) {
|
||||||
const id = req.data.id
|
const id = req.data.id
|
||||||
const mediaObj = mediaDB.get(id)
|
const mediaObj = mediaDB.get(id)
|
||||||
|
|||||||
27
mta.yaml
Normal file
27
mta.yaml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
_schema-version: '3.1'
|
||||||
|
ID: capire.samples
|
||||||
|
version: 2.0.0
|
||||||
|
description: "A monorepo with several samples for CAP."
|
||||||
|
parameters:
|
||||||
|
enable-parallel-deployments: true
|
||||||
|
build-parameters:
|
||||||
|
before-all:
|
||||||
|
- builder: custom
|
||||||
|
commands:
|
||||||
|
- npm ci
|
||||||
|
- npx cds build --production --ws
|
||||||
|
modules:
|
||||||
|
- name: samples-db-deployer
|
||||||
|
type: hdb
|
||||||
|
path: gen/db
|
||||||
|
parameters:
|
||||||
|
buildpack: nodejs_buildpack
|
||||||
|
requires:
|
||||||
|
- name: samples-db
|
||||||
|
|
||||||
|
resources:
|
||||||
|
- name: samples-db
|
||||||
|
type: com.sap.xs.hdi-container
|
||||||
|
parameters:
|
||||||
|
service: hana
|
||||||
|
service-plan: hdi-shared
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
Order = Bestellung
|
|
||||||
Orders = Bestellungen
|
|
||||||
Price = Preis
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
Order = Order
|
|
||||||
Orders = Orders
|
|
||||||
OrderNo = Order Number
|
|
||||||
OrderItems = Order Items
|
|
||||||
Customer = Customer
|
|
||||||
Product = Product
|
|
||||||
ProductID = Product ID
|
|
||||||
ProductTitle = Product Title
|
|
||||||
UnitPrice = Unit Price
|
|
||||||
Quantity = Quantity
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
Order = Order
|
|
||||||
Orders = Orders
|
|
||||||
OrderNo = Numéro de commande
|
|
||||||
OrderItems = Articles de la commande
|
|
||||||
Customer = Client
|
|
||||||
Product = Produit
|
|
||||||
ProductID = ID du produit
|
|
||||||
ProductTitle = Titre du produit
|
|
||||||
UnitPrice = Prix unitaire
|
|
||||||
Quantity = Quantité
|
|
||||||
12
orders/app/router/package.json
Normal file
12
orders/app/router/package.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "approuter",
|
||||||
|
"dependencies": {
|
||||||
|
"@sap/approuter": "^16.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^20.0.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "node node_modules/@sap/approuter/approuter.js"
|
||||||
|
}
|
||||||
|
}
|
||||||
22
orders/app/router/xs-app.json
Normal file
22
orders/app/router/xs-app.json
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"welcomeFile": "app/index.html",
|
||||||
|
"routes": [
|
||||||
|
{
|
||||||
|
"source": "^/app/(.*)$",
|
||||||
|
"target": "$1",
|
||||||
|
"localDir": ".",
|
||||||
|
"cacheControl": "no-cache, no-store, must-revalidate"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"source": "^/appconfig/",
|
||||||
|
"localDir": ".",
|
||||||
|
"cacheControl": "no-cache, no-store, must-revalidate"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"source": "^/(.*)$",
|
||||||
|
"target": "$1",
|
||||||
|
"destination": "srv-api",
|
||||||
|
"csrfProtection": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ using { Currency, User, managed, cuid } from '@sap/cds/common';
|
|||||||
namespace sap.capire.orders;
|
namespace sap.capire.orders;
|
||||||
|
|
||||||
entity Orders : cuid, managed {
|
entity Orders : cuid, managed {
|
||||||
OrderNo : String(44) @title:'Order Number'; //> readable key
|
OrderNo : String(22) @title:'Order Number'; //> readable key
|
||||||
Items : Composition of many {
|
Items : Composition of many {
|
||||||
key ID : UUID;
|
key ID : UUID;
|
||||||
product : Association to Products;
|
product : Association to Products;
|
||||||
|
|||||||
55
orders/mta.yaml
Normal file
55
orders/mta.yaml
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
_schema-version: '3.1'
|
||||||
|
ID: capire.orders
|
||||||
|
version: 1.0.0
|
||||||
|
description: "A simple CAP project."
|
||||||
|
parameters:
|
||||||
|
enable-parallel-deployments: true
|
||||||
|
build-parameters:
|
||||||
|
before-all:
|
||||||
|
- builder: custom
|
||||||
|
commands:
|
||||||
|
- npm ci
|
||||||
|
- npx cds build --production
|
||||||
|
modules:
|
||||||
|
- name: orders-srv
|
||||||
|
type: nodejs
|
||||||
|
path: gen/srv
|
||||||
|
parameters:
|
||||||
|
buildpack: nodejs_buildpack
|
||||||
|
readiness-health-check-type: http
|
||||||
|
readiness-health-check-http-endpoint: /health
|
||||||
|
build-parameters:
|
||||||
|
builder: npm
|
||||||
|
provides:
|
||||||
|
- name: srv-api # required by consumers of CAP services (e.g. approuter)
|
||||||
|
properties:
|
||||||
|
srv-url: ${default-url}
|
||||||
|
requires:
|
||||||
|
- name: orders-auth
|
||||||
|
|
||||||
|
- name: orders
|
||||||
|
type: approuter.nodejs
|
||||||
|
path: app/router
|
||||||
|
parameters:
|
||||||
|
keep-existing-routes: true
|
||||||
|
disk-quota: 256M
|
||||||
|
memory: 256M
|
||||||
|
requires:
|
||||||
|
- name: srv-api
|
||||||
|
group: destinations
|
||||||
|
properties:
|
||||||
|
name: srv-api # must be used in xs-app.json as well
|
||||||
|
url: ~{srv-url}
|
||||||
|
forwardAuthToken: true
|
||||||
|
- name: orders-auth
|
||||||
|
|
||||||
|
resources:
|
||||||
|
- name: orders-auth
|
||||||
|
type: org.cloudfoundry.managed-service
|
||||||
|
parameters:
|
||||||
|
service: xsuaa
|
||||||
|
service-plan: application
|
||||||
|
path: ./xs-security.json
|
||||||
|
config:
|
||||||
|
xsappname: orders-${org}-${space}
|
||||||
|
tenant-mode: dedicated
|
||||||
@@ -4,5 +4,19 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@capire/common": "*",
|
"@capire/common": "*",
|
||||||
"@sap/cds": ">=5"
|
"@sap/cds": ">=5"
|
||||||
|
},
|
||||||
|
"cds": {
|
||||||
|
"requires": {
|
||||||
|
"db": { "kind": "sql" },
|
||||||
|
"[multimodule]": {
|
||||||
|
"db": {
|
||||||
|
"kind": "sqlite",
|
||||||
|
"impl": "@cap-js/sqlite",
|
||||||
|
"credentials": {
|
||||||
|
"url": "../db.sqlite"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,7 @@ class OrdersService extends cds.ApplicationService {
|
|||||||
/** order changed -> broadcast event */
|
/** order changed -> broadcast event */
|
||||||
orderChanged (product, deltaQuantity) {
|
orderChanged (product, deltaQuantity) {
|
||||||
// Emit events to inform subscribers about changes in orders
|
// Emit events to inform subscribers about changes in orders
|
||||||
console.log ('> emitting:', 'OrderChanged', { product, deltaQuantity }) // eslint-disable-line no-console
|
console.log ('> emitting:', 'OrderChanged', { product, deltaQuantity })
|
||||||
return this.emit ('OrderChanged', { product, deltaQuantity })
|
return this.emit ('OrderChanged', { product, deltaQuantity })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
5
orders/xs-security.json
Normal file
5
orders/xs-security.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"scopes": [],
|
||||||
|
"attributes": [],
|
||||||
|
"role-templates": []
|
||||||
|
}
|
||||||
2286
package-lock.json
generated
2286
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
33
package.json
33
package.json
@@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@capire/samples",
|
"name": "@capire/samples",
|
||||||
"version": "2.1.0",
|
"version": "2.0.0",
|
||||||
"description": "A monorepo with several samples for CAP.",
|
"description": "A monorepo with several samples for CAP.",
|
||||||
"repository": "https://github.com/sap-samples/cloud-cap-samples.git",
|
"repository": "https://github.com/sap-samples/cloud-cap-samples.git",
|
||||||
"author": "daniel.hutzel@sap.com",
|
"author": "daniel.hutzel@sap.com",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sap/cds": ">=8"
|
"@sap-cloud-sdk/resilience": "^3.14.0",
|
||||||
|
"@sap/cds": ">=7"
|
||||||
},
|
},
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"./bookshop",
|
"./bookshop",
|
||||||
@@ -20,32 +21,48 @@
|
|||||||
"./reviews"
|
"./reviews"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cap-js/cds-types": "^0",
|
|
||||||
"@cap-js/sqlite": "^1",
|
"@cap-js/sqlite": "^1",
|
||||||
|
"@sap/cds-dk": "^7",
|
||||||
|
"@sap/eslint-plugin-cds": "^2.6.1",
|
||||||
"axios": "^1",
|
"axios": "^1",
|
||||||
"chai": "^4.3.4",
|
"chai": "^4.3.4",
|
||||||
"chai-as-promised": "^7.1.1",
|
"chai-as-promised": "^7.1.1",
|
||||||
"chai-subset": "^1.6.0",
|
"chai-subset": "^1.6.0",
|
||||||
"eslint": "^9",
|
|
||||||
"semver": "^7"
|
"semver": "^7"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"cleanup": "rm -rf node_modules && rm -rf */node_modules && rm -rf */*/node_modules",
|
||||||
"bookshop": "cds watch bookshop",
|
"bookshop": "cds watch bookshop",
|
||||||
"start": "cds watch fiori",
|
|
||||||
"fiori": "cds watch fiori",
|
"fiori": "cds watch fiori",
|
||||||
"hello": "cds watch hello",
|
"hello": "cds watch hello",
|
||||||
"media": "cds watch media",
|
"media": "cds watch media",
|
||||||
"lint": "eslint",
|
|
||||||
"test": "npx jest --silent",
|
|
||||||
"jest": "npx jest --silent",
|
|
||||||
"mocha": "CDS_TEST_SILENT=y npx mocha",
|
"mocha": "CDS_TEST_SILENT=y npx mocha",
|
||||||
|
"jest": "npx jest --silent",
|
||||||
|
"start": "cds watch fiori",
|
||||||
|
"test": "npm run jest -- --silent",
|
||||||
"test:hello": "cd hello && npm test"
|
"test:hello": "cd hello && npm test"
|
||||||
},
|
},
|
||||||
|
"jest": {
|
||||||
|
"testTimeout": 20000,
|
||||||
|
"testMatch": [
|
||||||
|
"**/*.test.js"
|
||||||
|
]
|
||||||
|
},
|
||||||
"mocha": {
|
"mocha": {
|
||||||
"recursive": true,
|
"recursive": true,
|
||||||
"parallel": true,
|
"parallel": true,
|
||||||
"timeout": 6666
|
"timeout": 6666
|
||||||
},
|
},
|
||||||
|
"cds": {
|
||||||
|
"requires": {
|
||||||
|
"db": {
|
||||||
|
"kind": "sql",
|
||||||
|
"[development]": {
|
||||||
|
"model": "db/sqlite"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"private": true
|
"private": true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
Date = Datum
|
|
||||||
Rating = Bewertung
|
|
||||||
NumberOfReviews = Anzahl der Reviews
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
Reviews = Reviews
|
|
||||||
Review = Review
|
|
||||||
Date = Date
|
|
||||||
Rating = Rating
|
|
||||||
NumberOfReviews = Number of Reviews
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
Reviews = Avis
|
|
||||||
Review = Avis
|
|
||||||
Date = Date
|
|
||||||
Rating = Note
|
|
||||||
NumberOfReviews = Nombre d''avis
|
|
||||||
@@ -50,6 +50,7 @@ const reviews = Vue.createApp ({
|
|||||||
const res = await POST(`/Reviews`,review)
|
const res = await POST(`/Reviews`,review)
|
||||||
reviews.ID = res.data.ID
|
reviews.ID = res.data.ID
|
||||||
} else {
|
} else {
|
||||||
|
console.trace()
|
||||||
await PUT(`/Reviews/${review.ID}`,review)
|
await PUT(`/Reviews/${review.ID}`,review)
|
||||||
}
|
}
|
||||||
reviews.message = { succeeded: 'Your review was submitted successfully. Thanks.' }
|
reviews.message = { succeeded: 'Your review was submitted successfully. Thanks.' }
|
||||||
|
|||||||
@@ -17,7 +17,17 @@
|
|||||||
"[hybrid]": { "kind": "enterprise-messaging-shared" },
|
"[hybrid]": { "kind": "enterprise-messaging-shared" },
|
||||||
"[production]": { "kind": "enterprise-messaging" }
|
"[production]": { "kind": "enterprise-messaging" }
|
||||||
},
|
},
|
||||||
"db": { "kind": "sql" }
|
|
||||||
|
"db": { "kind": "sql" },
|
||||||
|
"[multimodule]": {
|
||||||
|
"db": {
|
||||||
|
"kind": "sqlite",
|
||||||
|
"impl": "@cap-js/sqlite",
|
||||||
|
"credentials": {
|
||||||
|
"url": "../db.sqlite"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@ module.exports = cds.service.impl (function(){
|
|||||||
const { count, rating } = await cds.tx(req) .run (
|
const { count, rating } = await cds.tx(req) .run (
|
||||||
SELECT.one `round(avg(rating),2) as rating, count(*) as count` .from (Reviews) .where ({subject})
|
SELECT.one `round(avg(rating),2) as rating, count(*) as count` .from (Reviews) .where ({subject})
|
||||||
)
|
)
|
||||||
global.it || console.log ('< emitting:', 'reviewed', { subject, count, rating }) // eslint-disable-line no-console
|
global.it || console.log ('< emitting:', 'reviewed', { subject, count, rating })
|
||||||
await this.emit ('reviewed', { subject, count, rating })
|
await this.emit ('reviewed', { subject, count, rating })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
const cds = require('@sap/cds')
|
|
||||||
const { expect } = cds.test
|
|
||||||
|
|
||||||
describe('cds.ql → cqn', () => {
|
describe('cds.ql → cqn', () => {
|
||||||
|
|
||||||
|
const cds = require('@sap/cds/lib')
|
||||||
|
const { expect } = cds.test
|
||||||
const Foo = { name: 'Foo' }
|
const Foo = { name: 'Foo' }
|
||||||
const Books = { name: 'capire.bookshop.Books' }
|
const Books = { name: 'capire.bookshop.Books' }
|
||||||
|
|
||||||
@@ -677,7 +676,7 @@ describe('cds.ql → cqn', () => {
|
|||||||
.to.eql(INSERT.into(Foo).entries(...entries))
|
.to.eql(INSERT.into(Foo).entries(...entries))
|
||||||
.to.eql(INSERT.into(Foo).entries(entries))
|
.to.eql(INSERT.into(Foo).entries(entries))
|
||||||
.to.eql({
|
.to.eql({
|
||||||
INSERT: { into: { ref: ['Foo'] }, entries },
|
INSERT: { into: cds.env.ql.quirks_mode ? 'Foo' : { ref: ['Foo'] }, entries },
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -693,7 +692,7 @@ describe('cds.ql → cqn', () => {
|
|||||||
.to.eql(INSERT.into(Foo).columns('a', 'b').rows([1, 2], [3, 4]))
|
.to.eql(INSERT.into(Foo).columns('a', 'b').rows([1, 2], [3, 4]))
|
||||||
.to.eql({
|
.to.eql({
|
||||||
INSERT: {
|
INSERT: {
|
||||||
into: { ref: ['Foo'] },
|
into: cds.env.ql.quirks_mode ? 'Foo' : { ref: ['Foo'] },
|
||||||
columns: ['a', 'b'],
|
columns: ['a', 'b'],
|
||||||
rows: [
|
rows: [
|
||||||
[1, 2],
|
[1, 2],
|
||||||
@@ -707,7 +706,7 @@ describe('cds.ql → cqn', () => {
|
|||||||
expect(INSERT.into(Foo).columns('a', 'b').values([1, 2]))
|
expect(INSERT.into(Foo).columns('a', 'b').values([1, 2]))
|
||||||
.to.eql(INSERT.into(Foo).columns('a', 'b').values(1, 2))
|
.to.eql(INSERT.into(Foo).columns('a', 'b').values(1, 2))
|
||||||
.to.eql({
|
.to.eql({
|
||||||
INSERT: { into: { ref: ['Foo'] }, columns: ['a', 'b'], values: [1, 2] },
|
INSERT: { into: cds.env.ql.quirks_mode ? 'Foo' : { ref: ['Foo'] }, columns: ['a', 'b'], values: [1, 2] },
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -722,7 +721,7 @@ describe('cds.ql → cqn', () => {
|
|||||||
test('entity (..., <key>)', () => {
|
test('entity (..., <key>)', () => {
|
||||||
const cqnWhere = {
|
const cqnWhere = {
|
||||||
UPDATE: {
|
UPDATE: {
|
||||||
entity: { ref: ['capire.bookshop.Books'] },
|
entity: cds.env.ql.quirks_mode ? 'capire.bookshop.Books' : { ref: ['capire.bookshop.Books'] },
|
||||||
where: [{ ref: ['ID'] }, '=', { val: 4711 }],
|
where: [{ ref: ['ID'] }, '=', { val: 4711 }],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -766,7 +765,7 @@ describe('cds.ql → cqn', () => {
|
|||||||
.to.eql(UPDATE(Foo).with({ foo: 11, bar: { '-=': 22 } }))
|
.to.eql(UPDATE(Foo).with({ foo: 11, bar: { '-=': 22 } }))
|
||||||
.to.eql({
|
.to.eql({
|
||||||
UPDATE: {
|
UPDATE: {
|
||||||
entity: { ref: ['Foo'] },
|
entity: cds.env.ql.quirks_mode ? 'Foo' : { ref: ['Foo'] },
|
||||||
data: { foo: 11 },
|
data: { foo: 11 },
|
||||||
with: {
|
with: {
|
||||||
bar: { xpr: [{ ref: ['bar'] }, '-', { val: 22 }] },
|
bar: { xpr: [{ ref: ['bar'] }, '-', { val: 22 }] },
|
||||||
@@ -777,7 +776,7 @@ describe('cds.ql → cqn', () => {
|
|||||||
// some more
|
// some more
|
||||||
expect(UPDATE(Foo).with(`bar = coalesce(x,y), car = 'foo''s bar, car'`)).to.eql({
|
expect(UPDATE(Foo).with(`bar = coalesce(x,y), car = 'foo''s bar, car'`)).to.eql({
|
||||||
UPDATE: {
|
UPDATE: {
|
||||||
entity: { ref: ['Foo'] },
|
entity: cds.env.ql.quirks_mode ? 'Foo' : { ref: ['Foo'] },
|
||||||
data: {
|
data: {
|
||||||
car: "foo's bar, car",
|
car: "foo's bar, car",
|
||||||
},
|
},
|
||||||
@@ -797,7 +796,7 @@ describe('cds.ql → cqn', () => {
|
|||||||
test('from (..., <key>)', () => {
|
test('from (..., <key>)', () => {
|
||||||
const cqnWhere = {
|
const cqnWhere = {
|
||||||
DELETE: {
|
DELETE: {
|
||||||
from: { ref: ['capire.bookshop.Books'] },
|
from: cds.env.ql.quirks_mode ? 'capire.bookshop.Books' : { ref: ['capire.bookshop.Books'] },
|
||||||
where: [{ ref: ['ID'] }, '=', { val: 4711 }],
|
where: [{ ref: ['ID'] }, '=', { val: 4711 }],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
const cds = require("@sap/cds");
|
|
||||||
const { expect } = cds.test(
|
|
||||||
"serve",
|
|
||||||
"CatalogService",
|
|
||||||
"--from",
|
|
||||||
"@capire/bookshop,@capire/common",
|
|
||||||
"--in-memory"
|
|
||||||
);
|
|
||||||
|
|
||||||
describe("Consuming actions locally", () => {
|
|
||||||
let cats, CatalogService, Books, stockBefore;
|
|
||||||
const BOOK_ID = 251;
|
|
||||||
const QUANTITY = 1;
|
|
||||||
|
|
||||||
before("bootstrap the database", async () => {
|
|
||||||
CatalogService = cds.services.CatalogService;
|
|
||||||
expect(CatalogService).not.to.be.undefined;
|
|
||||||
|
|
||||||
Books = CatalogService.entities.Books;
|
|
||||||
expect(Books).not.to.be.undefined;
|
|
||||||
|
|
||||||
cats = await cds.connect.to("CatalogService");
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
// Read the stock before the action is called
|
|
||||||
stockBefore = (await cats.get(Books, BOOK_ID)).stock;
|
|
||||||
});
|
|
||||||
|
|
||||||
it("calls unbound actions - basic variant using srv.send", async () => {
|
|
||||||
// Use a managed transaction to create a continuation with an authenticated user
|
|
||||||
const res1 = await cats.tx({ user: "alice" }, () => {
|
|
||||||
return cats.send("submitOrder", { book: BOOK_ID, quantity: QUANTITY });
|
|
||||||
});
|
|
||||||
expect(res1.stock).to.eql(stockBefore - QUANTITY);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("calls unbound actions - named args variant", async () => {
|
|
||||||
// Use a managed transaction to create a continuation with an authenticated user
|
|
||||||
const res2 = await cats.tx({ user: "alice" }, () => {
|
|
||||||
return cats.submitOrder({ book: BOOK_ID, quantity: QUANTITY });
|
|
||||||
});
|
|
||||||
expect(res2.stock).to.eql(stockBefore - QUANTITY);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("calls unbound actions - positional args variant", async () => {
|
|
||||||
// Use a managed transaction to create a continuation with an authenticated user
|
|
||||||
const res3 = await cats.tx({ user: "alice" }, () => {
|
|
||||||
return cats.submitOrder(BOOK_ID, QUANTITY);
|
|
||||||
});
|
|
||||||
expect(res3.stock).to.eql(stockBefore - QUANTITY);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
const cds = require('@sap/cds')
|
const cds = require('@sap/cds/lib')
|
||||||
|
|
||||||
describe('cap/samples - Consuming Services locally', () => {
|
describe('cap/samples - Consuming Services locally', () => {
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const cds = require('@sap/cds')
|
const cds = require('@sap/cds/lib')
|
||||||
|
|
||||||
describe('cap/samples - Custom Handlers', () => {
|
describe('cap/samples - Custom Handlers', () => {
|
||||||
|
|
||||||
@@ -8,10 +8,9 @@ describe('cap/samples - Custom Handlers', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should reject out-of-stock orders', async () => {
|
it('should reject out-of-stock orders', async () => {
|
||||||
await expect(POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}`).to.be.fulfilled
|
await POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}`
|
||||||
await expect(POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}`).to.be.fulfilled
|
await POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}`
|
||||||
await expect(POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}`).to.be.rejectedWith(
|
await expect(POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}`).to.be.rejectedWith(/409 - 5 exceeds stock for book #201/)
|
||||||
/409 - 5 exceeds stock for book #201/)
|
|
||||||
const { data } = await GET`/admin/Books/201/stock/$value`
|
const { data } = await GET`/admin/Books/201/stock/$value`
|
||||||
expect(data).to.equal(2)
|
expect(data).to.equal(2)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
// Quick hack: suppress deprecation warnings w/ Node22 caused by http-proxy (used by OData v2 proxy)
|
const cds = require('@sap/cds/lib')
|
||||||
// See also: https://github.com/http-party/node-http-proxy/pull/1666
|
|
||||||
require('util')._extend = Object.assign
|
|
||||||
|
|
||||||
const cds = require('@sap/cds')
|
|
||||||
|
|
||||||
describe('cap/samples - Fiori APIs - v2', function() {
|
describe('cap/samples - Fiori APIs - v2', function() {
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
const cds = require('@sap/cds')
|
const cds = require('@sap/cds/lib')
|
||||||
|
|
||||||
describe('cap/samples - Hello world!', () => {
|
describe('cap/samples - Hello world!', () => {
|
||||||
|
|
||||||
const { GET, expect } = cds.test (__dirname+'/../hello')
|
const { GET, expect } = cds.test (__dirname+'/../hello')
|
||||||
|
|
||||||
it('should say hello with class impl', async () => {
|
it('should say hello with class impl', async () => {
|
||||||
const {data} = await GET `/odata/v4/say/hello(to='world')`
|
const {data} = await GET `/say/hello(to='world')`
|
||||||
expect(data.value).to.eql('Hello world!')
|
expect(data.value).to.eql('Hello world!')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const cds = require('@sap/cds')
|
const cds = require('@sap/cds/lib')
|
||||||
const { expect } = cds.test.in(__dirname,'..')
|
const { expect } = cds.test.in(__dirname,'..')
|
||||||
|
|
||||||
describe('cap/samples - Hierarchical Data', ()=>{
|
describe('cap/samples - Hierarchical Data', ()=>{
|
||||||
@@ -77,27 +77,29 @@ describe('cap/samples - Hierarchical Data', ()=>{
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it ('supports nested reads', ()=> expect (
|
it ('supports nested reads', async()=>{
|
||||||
|
expect (await
|
||||||
SELECT.one.from (Cats, c=>{
|
SELECT.one.from (Cats, c=>{
|
||||||
c.ID, c.name.as('parent'), c.children (c=>{
|
c.ID, c.name.as('parent'), c.children (c=>{
|
||||||
c.name.as('child')
|
c.name.as('child')
|
||||||
})
|
})
|
||||||
}) .where ({name:'Cat'})
|
}) .where ({name:'Cat'})
|
||||||
) .to.eventually.eql (
|
) .to.eql (
|
||||||
{ ID:101, parent:'Cat', children:[
|
{ ID:101, parent:'Cat', children:[
|
||||||
{ child:'Kitty' },
|
{ child:'Kitty' },
|
||||||
{ child:'Catwoman' },
|
{ child:'Catwoman' },
|
||||||
]}
|
]}
|
||||||
))
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it ('supports deeply nested reads', ()=> expect (
|
it ('supports deeply nested reads', async()=>{
|
||||||
SELECT.one.from (Cats, c=>{
|
expect (await SELECT.one.from (Cats, c=>{
|
||||||
c.ID, c.name, c.children (
|
c.ID, c.name, c.children (
|
||||||
c => { c.name },
|
c => { c.name },
|
||||||
{levels:3}
|
{levels:3}
|
||||||
)
|
)
|
||||||
}) .where ({name:'Cat'})
|
}) .where ({name:'Cat'})
|
||||||
) .to.eventually.eql (
|
) .to.eql (
|
||||||
{ ID:101, name:'Cat', children:[
|
{ ID:101, name:'Cat', children:[
|
||||||
{ name:'Kitty', children:[
|
{ name:'Kitty', children:[
|
||||||
{ name:'Kitty Cat', children:[
|
{ name:'Kitty Cat', children:[
|
||||||
@@ -106,16 +108,18 @@ describe('cap/samples - Hierarchical Data', ()=>{
|
|||||||
{ name:'Catwoman', children:[
|
{ name:'Catwoman', children:[
|
||||||
{ name:'Catalina', children:[] } ]},
|
{ name:'Catalina', children:[] } ]},
|
||||||
]}
|
]}
|
||||||
))
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it ('supports cascaded deletes', async()=>{
|
it ('supports cascaded deletes', async()=>{
|
||||||
const affectedRows = await DELETE.from (Cats) .where ({ID:[102,106]})
|
const affectedRows = await DELETE.from (Cats) .where ({ID:[102,106]})
|
||||||
expect (affectedRows) .to.be.greaterThan (0)
|
expect (affectedRows) .to.be.greaterThan (0)
|
||||||
await expect (SELECT`ID,name`.from(Cats) ).to.eventually.eql ([
|
const expected = [
|
||||||
{ ID:100, name:'Some Cats...' },
|
{ ID:100, name:'Some Cats...' },
|
||||||
{ ID:101, name:'Cat' },
|
{ ID:101, name:'Cat' },
|
||||||
{ ID:108, name:'Catweazle' }
|
{ ID:108, name:'Catweazle' }
|
||||||
])
|
]
|
||||||
|
expect ( await SELECT`ID,name`.from(Cats) ).to.eql (expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const cds = require('@sap/cds')
|
const cds = require('@sap/cds/lib')
|
||||||
|
|
||||||
describe('cap/samples - Localized Data', () => {
|
describe('cap/samples - Localized Data', () => {
|
||||||
|
|
||||||
@@ -27,15 +27,15 @@ describe('cap/samples - Localized Data', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('supports queries with $expand', async () => {
|
it('supports queries with $expand', async () => {
|
||||||
const { data } = await GET(`/browse/Book?&$select=title,author,currencyName`, {
|
const { data } = await GET(`/browse/Books?&$select=title,author&$expand=currency`, {
|
||||||
headers: { 'Accept-Language': 'de' },
|
headers: { 'Accept-Language': 'de' },
|
||||||
})
|
})
|
||||||
expect(data.value).to.containSubset([
|
expect(data.value).to.containSubset([
|
||||||
{ title: 'Sturmhöhe', author: 'Emily Brontë', currencyName: 'Pfund' },
|
{ title: 'Sturmhöhe', author: 'Emily Brontë', currency: { name: 'Pfund' } },
|
||||||
{ title: 'Jane Eyre', author: 'Charlotte Brontë', currencyName: 'Pfund' },
|
{ title: 'Jane Eyre', author: 'Charlotte Brontë', currency: { name: 'Pfund' } },
|
||||||
{ title: 'The Raven', author: 'Edgar Allen Poe', currencyName: 'US-Dollar' },
|
{ title: 'The Raven', author: 'Edgar Allen Poe', currency: { name: 'US-Dollar' } },
|
||||||
{ title: 'Eleonora', author: 'Edgar Allen Poe', currencyName: 'US-Dollar' },
|
{ title: 'Eleonora', author: 'Edgar Allen Poe', currency: { name: 'US-Dollar' } },
|
||||||
{ title: 'Catweazle', author: 'Richard Carpenter', currencyName: 'Yen' },
|
{ title: 'Catweazle', author: 'Richard Carpenter', currency: { name: 'Yen' } },
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const cds = require('@sap/cds')
|
const cds = require('@sap/cds/lib')
|
||||||
|
|
||||||
describe('cap/samples - Messaging', ()=>{
|
describe('cap/samples - Messaging', ()=>{
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const cds = require('@sap/cds')
|
const cds = require('@sap/cds/lib')
|
||||||
|
|
||||||
describe('cap/samples - Bookshop APIs', () => {
|
describe('cap/samples - Bookshop APIs', () => {
|
||||||
const { GET, expect, axios } = cds.test ('@capire/bookshop')
|
const { GET, expect, axios } = cds.test ('@capire/bookshop')
|
||||||
@@ -8,29 +8,26 @@ describe('cap/samples - Bookshop APIs', () => {
|
|||||||
const { headers, status, data } = await GET `/browse/$metadata`
|
const { headers, status, data } = await GET `/browse/$metadata`
|
||||||
expect(status).to.equal(200)
|
expect(status).to.equal(200)
|
||||||
expect(headers).to.contain({
|
expect(headers).to.contain({
|
||||||
// 'content-type': 'application/xml', //> fails with 'application/xml;charset=utf-8', which is set by express
|
'content-type': 'application/xml',
|
||||||
'odata-version': '4.0',
|
'odata-version': '4.0',
|
||||||
})
|
})
|
||||||
expect(headers['content-type']).to.match(/application\/xml/)
|
expect(data).to.contain('<EntitySet Name="Books" EntityType="CatalogService.Books">')
|
||||||
expect(data).to.contain('<EntitySet Name="Books" EntityType="CatalogService.Books"/>')
|
expect(data).to.contain('<Annotation Term="Common.Label" String="Currency"/>')
|
||||||
expect(data).to.contain('<Annotation Term="Common.Label" String="Currency Symbol"/>')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('serves Books?$expand=genre,currency', async () => {
|
it('serves ListOfBooks?$expand=genre,currency', async () => {
|
||||||
const Mystery = { ID: 16, name: 'Mystery', descr: null, parent_ID: 10 }
|
const Mystery = { ID: 16, name: 'Mystery', descr: null, parent_ID: 10 }
|
||||||
const Romance = { ID: 15, name: 'Romance', descr: null, parent_ID: 10 }
|
const Romance = { ID: 15, name: 'Romance', descr: null, parent_ID: 10 }
|
||||||
const USD = { code: 'USD', name: 'US Dollar', descr: null, symbol: '$' }
|
const USD = { code: 'USD', name: 'US Dollar', descr: null, symbol: '$' }
|
||||||
const { data } = await GET `/admin/Books ${{
|
const { data } = await GET `/browse/ListOfBooks ${{
|
||||||
params: { $search: 'Po', $select: `title,author`, $expand:`genre,currency` },
|
params: { $search: 'Po', $select: `title,author`, $expand:`genre,currency` },
|
||||||
}}`
|
}}`
|
||||||
expect(data.value).to.containSubset([
|
expect(data.value).to.containSubset([
|
||||||
{ ID: 251, title: 'The Raven', author_ID: 150, genre:Mystery, currency:USD },
|
{ ID: 251, title: 'The Raven', author: 'Edgar Allen Poe', genre:Mystery, currency:USD },
|
||||||
{ ID: 252, title: 'Eleonora', author_ID: 150, genre:Romance, currency:USD },
|
{ ID: 252, title: 'Eleonora', author: 'Edgar Allen Poe', genre:Romance, currency:USD },
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('query options...', () => {
|
|
||||||
|
|
||||||
it('supports $search in multiple fields', async () => {
|
it('supports $search in multiple fields', async () => {
|
||||||
const { data } = await GET `/browse/Books ${{
|
const { data } = await GET `/browse/Books ${{
|
||||||
params: { $search: 'Po', $select: `title,author` },
|
params: { $search: 'Po', $select: `title,author` },
|
||||||
@@ -89,7 +86,6 @@ describe('cap/samples - Bookshop APIs', () => {
|
|||||||
{ ID: 271, title: 'Catweazle' },
|
{ ID: 271, title: 'Catweazle' },
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
it('serves user info', async () => {
|
it('serves user info', async () => {
|
||||||
const { data: alice } = await GET `/user/me`
|
const { data: alice } = await GET `/user/me`
|
||||||
|
|||||||
Reference in New Issue
Block a user