Compare commits
6 Commits
main
...
openSAP-we
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b97da977e5 | ||
|
|
50085fe7be | ||
|
|
8c3733c9cd | ||
|
|
a412c41970 | ||
|
|
e49e9ae823 | ||
|
|
6cc2741c3e |
2425
.deploy/app-router/package-lock.json
generated
2425
.deploy/app-router/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "approuter",
|
|
||||||
"dependencies": {
|
|
||||||
"@sap/approuter": "^20.0.0"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"start": "node node_modules/@sap/approuter/approuter.js"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../bookshop/app/vue
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../orders/app/orders
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../reviews/app/vue
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
{
|
|
||||||
"welcomeFile": "app/bookshop/index.html",
|
|
||||||
"routes": [
|
|
||||||
{
|
|
||||||
"source": "^/app/(.*)$",
|
|
||||||
"target": "$1",
|
|
||||||
"localDir": "resources",
|
|
||||||
"cacheControl": "no-cache, no-store, must-revalidate"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "^/admin/(.*)$",
|
|
||||||
"target": "/admin/$1",
|
|
||||||
"destination": "bookstore-api",
|
|
||||||
"csrfProtection": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "^/browse/(.*)$",
|
|
||||||
"target": "/browse/$1",
|
|
||||||
"destination": "bookstore-api",
|
|
||||||
"csrfProtection": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "^/user/(.*)$",
|
|
||||||
"target": "/user/$1",
|
|
||||||
"destination": "bookstore-api",
|
|
||||||
"csrfProtection": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "^/odata/v4/orders/(.*)$",
|
|
||||||
"target": "/odata/v4/orders/$1",
|
|
||||||
"destination": "orders-api",
|
|
||||||
"csrfProtection": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "^/reviews/(.*)$",
|
|
||||||
"target": "/reviews/$1",
|
|
||||||
"destination": "reviews-api",
|
|
||||||
"csrfProtection": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
24
.eslintrc
Normal file
24
.eslintrc
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"extends": "eslint:recommended",
|
||||||
|
"env": {
|
||||||
|
"node": true,
|
||||||
|
"es6": true,
|
||||||
|
"jest": true
|
||||||
|
},
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 2018
|
||||||
|
},
|
||||||
|
"globals": {
|
||||||
|
"SELECT": true,
|
||||||
|
"INSERT": true,
|
||||||
|
"UPDATE": true,
|
||||||
|
"DELETE": true,
|
||||||
|
"CREATE": true,
|
||||||
|
"DROP": true,
|
||||||
|
"cds": true
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"no-console": "off",
|
||||||
|
"require-atomic-updates": "off"
|
||||||
|
}
|
||||||
|
}
|
||||||
5
.github/ISSUE_TEMPLATE/config.yml
vendored
5
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1,5 +0,0 @@
|
|||||||
blank_issues_enabled: false
|
|
||||||
contact_links:
|
|
||||||
- name: This channel is CLOSED.
|
|
||||||
about: Use SAP community instead
|
|
||||||
url: https://answers.sap.com/tags/9f13aee1-834c-4105-8e43-ee442775e5ce
|
|
||||||
23
.github/dependabot.yml
vendored
23
.github/dependabot.yml
vendored
@@ -1,23 +0,0 @@
|
|||||||
version: 2
|
|
||||||
|
|
||||||
updates:
|
|
||||||
- package-ecosystem: npm
|
|
||||||
directory: /
|
|
||||||
versioning-strategy: increase-if-necessary
|
|
||||||
schedule:
|
|
||||||
interval: weekly
|
|
||||||
groups:
|
|
||||||
production-dependencies:
|
|
||||||
dependency-type: "production"
|
|
||||||
development-dependencies:
|
|
||||||
dependency-type: "development"
|
|
||||||
ignore:
|
|
||||||
- dependency-name: "chai"
|
|
||||||
# chai 5 doesn't work atm w/ cds.test, TODO fix that in cds.test
|
|
||||||
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"]
|
|
||||||
- dependency-name: "express"
|
|
||||||
# express 5 not supported atm
|
|
||||||
versions: ["5.x"]
|
|
||||||
38
.github/workflows/node.js.yml
vendored
38
.github/workflows/node.js.yml
vendored
@@ -1,38 +0,0 @@
|
|||||||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
|
|
||||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
|
||||||
|
|
||||||
name: CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ main ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ main ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
node-version: [22.x, 20.x]
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node-version }}
|
|
||||||
- run: npm ci
|
|
||||||
- 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
.gitignore
vendored
10
.gitignore
vendored
@@ -12,14 +12,4 @@ target/
|
|||||||
*.mtar
|
*.mtar
|
||||||
connection.properties
|
connection.properties
|
||||||
default-env.json
|
default-env.json
|
||||||
.cdsrc-private.json
|
|
||||||
packages/messageBox
|
packages/messageBox
|
||||||
reviews/msg-box
|
|
||||||
reviews/db/test.db
|
|
||||||
|
|
||||||
*.openapi3.json
|
|
||||||
*.sqlite
|
|
||||||
*.db
|
|
||||||
|
|
||||||
@types/
|
|
||||||
@cds-models/
|
|
||||||
|
|||||||
29
.reuse/dep5
29
.reuse/dep5
@@ -1,29 +0,0 @@
|
|||||||
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
|
||||||
Upstream-Name: cloud-cap-samples
|
|
||||||
Upstream-Contact: <Christian Georgi (christian.georgi@sap.com)>
|
|
||||||
Source: https://github.com/SAP-samples/cloud-cap-samples
|
|
||||||
Disclaimer: The code in this project may include calls to APIs (“API Calls”) of
|
|
||||||
SAP or third-party products or services developed outside of this project
|
|
||||||
(“External Products”).
|
|
||||||
“APIs” means application programming interfaces, as well as their respective
|
|
||||||
specifications and implementing code that allows software to communicate with
|
|
||||||
other software.
|
|
||||||
API Calls to External Products are not licensed under the open source license
|
|
||||||
that governs this project. The use of such API Calls and related External
|
|
||||||
Products are subject to applicable additional agreements with the relevant
|
|
||||||
provider of the External Products. In no event shall the open source license
|
|
||||||
that governs this project grant any rights in or to any External Products,or
|
|
||||||
alter, expand or supersede any terms of the applicable additional agreements.
|
|
||||||
If you have a valid license agreement with SAP for the use of a particular SAP
|
|
||||||
External Product, then you may make use of any API Calls included in this
|
|
||||||
project’s code for that SAP External Product, subject to the terms of such
|
|
||||||
license agreement. If you do not have a valid license agreement for the use of
|
|
||||||
a particular SAP External Product, then you may only make use of any API Calls
|
|
||||||
in this project for that SAP External Product for your internal, non-productive
|
|
||||||
and non-commercial test and evaluation of such API Calls. Nothing herein grants
|
|
||||||
you any rights to use or access any SAP External Product, or provide any third
|
|
||||||
parties the right to use of access any SAP External Product, through API Calls.
|
|
||||||
|
|
||||||
Files: *.*
|
|
||||||
Copyright: 2019-2025 SAP SE or an SAP affiliate company and cap-cloud-samples
|
|
||||||
License: Apache-2.0
|
|
||||||
17
.vscode/extensions.json
vendored
17
.vscode/extensions.json
vendored
@@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
|
|
||||||
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
|
|
||||||
|
|
||||||
// List of extensions which should be recommended for users of this workspace.
|
|
||||||
"recommendations": [
|
|
||||||
"qwtel.sqlite-viewer",
|
|
||||||
"sapse.vscode-cds",
|
|
||||||
"dbaeumer.vscode-eslint",
|
|
||||||
"mechatroner.rainbow-csv",
|
|
||||||
"humao.rest-client",
|
|
||||||
],
|
|
||||||
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
|
|
||||||
"unwantedRecommendations": [
|
|
||||||
|
|
||||||
]
|
|
||||||
}
|
|
||||||
47
.vscode/launch.json
vendored
47
.vscode/launch.json
vendored
@@ -5,30 +5,33 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "bookshop",
|
"name": "bookshop", "request": "launch", "type": "node", "runtimeExecutable": "npx", "runtimeArgs": [ "-n" ],
|
||||||
"command": "npx cds watch bookshop",
|
"args": [ "--", "cds", "run", "--in-memory" ],
|
||||||
"type": "node-terminal",
|
"cwd": "${workspaceFolder}/packages/bookshop",
|
||||||
"request": "launch",
|
"console": "integratedTerminal",
|
||||||
"skipFiles": [
|
"skipFiles": ["<node_internals>/**"]
|
||||||
"<node_internals>/**",
|
|
||||||
"**/node_modules/**",
|
|
||||||
"**/cds/lib/lazy.js",
|
|
||||||
"**/cds/lib/req/cds-context.js",
|
|
||||||
"**/odata-v4/okra/**"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "bookstore",
|
"name": "cds run ...", "request": "launch", "type": "node", "runtimeExecutable": "npx", "runtimeArgs": [ "-n" ],
|
||||||
"command": "npx cds watch bookstore",
|
"args": [ "--", "cds", "run", "--with-mocks", "--in-memory?" ],
|
||||||
"type": "node-terminal",
|
"cwd": "${workspaceFolder}/packages/${input:service}",
|
||||||
"request": "launch",
|
"console": "integratedTerminal",
|
||||||
"skipFiles": [
|
"skipFiles": ["<node_internals>/**"]
|
||||||
"<node_internals>/**",
|
}
|
||||||
"**/node_modules/**",
|
],
|
||||||
"**/cds/lib/lazy.js",
|
"inputs": [
|
||||||
"**/cds/lib/req/cds-context.js",
|
{
|
||||||
"**/odata-v4/okra/**"
|
"type": "pickString",
|
||||||
]
|
"id": "service",
|
||||||
|
"description": "Which service do you want to start?",
|
||||||
|
"options": [
|
||||||
|
"bookshop",
|
||||||
|
"bookstore",
|
||||||
|
"media-server",
|
||||||
|
"office-supplies",
|
||||||
|
"reviews-service"
|
||||||
|
],
|
||||||
|
"default": "bookshop"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
14
.vscode/settings.json
vendored
14
.vscode/settings.json
vendored
@@ -1,16 +1,6 @@
|
|||||||
{
|
{
|
||||||
"files.exclude": {
|
"files.exclude": {
|
||||||
"**/node_modules": true,
|
"**/.gitignore": true,
|
||||||
"LICENSES": true,
|
"**/.vscode": true
|
||||||
".reuse": true
|
|
||||||
},
|
|
||||||
"debug.javascript.terminalOptions": {
|
|
||||||
"skipFiles": [
|
|
||||||
"<node_internals>/**",
|
|
||||||
"**/node_modules/**",
|
|
||||||
"**/cds/lib/lazy.js",
|
|
||||||
"**/cds/lib/req/cds-context.js",
|
|
||||||
"**/odata-v4/okra/**"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
28
.vscode/tasks.json
vendored
28
.vscode/tasks.json
vendored
@@ -1,15 +1,17 @@
|
|||||||
{
|
{
|
||||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
// for the documentation about the tasks.json format
|
// for the documentation about the tasks.json format
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"tasks": [
|
"tasks": [
|
||||||
{
|
{
|
||||||
"type": "npm",
|
"type": "npm", "script": "watch", "path": "packages/bookshop/",
|
||||||
"script": "jest",
|
"options": { "env": { "PORT": "4004" }},
|
||||||
"group": {
|
"presentation": { "group": "A" }
|
||||||
"kind": "test",
|
},
|
||||||
"isDefault": true
|
{
|
||||||
}
|
"type": "npm", "script": "watch", "path": "packages/reviews-service/",
|
||||||
}
|
"options": { "env": { "PORT": "5005" }},
|
||||||
]
|
"presentation": { "group": "A" }
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
391
LICENSE
391
LICENSE
@@ -1,201 +1,190 @@
|
|||||||
Apache License
|
SAP SAMPLE CODE LICENSE AGREEMENT
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
Please scroll down and read the following SAP Sample Code License Agreement
|
||||||
|
carefully ("Agreement"). By downloading, installing, or otherwise using the
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
SAP sample code or any materials that accompany the sample code documentation
|
||||||
|
(collectively, the "Sample Code"), You agree that this Agreement forms a legally
|
||||||
1. Definitions.
|
binding agreement between You ("You" or "Your") and SAP SE, for and on behalf
|
||||||
|
of itself and its subsidiaries and affiliates (as defined in Section 15 of the
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
German Stock Corporation Act), and You agree to be bound by all of the terms
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
and conditions stated in this Agreement. If You are trying to access or download
|
||||||
|
the Sample Code on behalf of Your employer or as a consultant or agent of a
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
third party (either "Your Company"), You represent and warrant that You have
|
||||||
the copyright owner that is granting the License.
|
the authority to act on behalf of and bind Your Company to the terms of this
|
||||||
|
Agreement and everywhere in this Agreement that refers to 'You' or 'Your' shall
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
also include Your Company. If You do not agree to these terms, do not attempt
|
||||||
other entities that control, are controlled by, or are under common
|
to access or use the Sample Code.
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
1. LICENSE: Subject to the terms of this Agreement, SAP grants You a nonexclusive,
|
||||||
direction or management of such entity, whether by contract or
|
non-transferable, non-sublicensable, revocable, royalty-free,
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
limited license to use, copy, and modify the Sample Code solely for Your internal
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
business purposes.
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
2. RESTRICTIONS: You must not use the Sample Code to: (a) impair, degrade or
|
||||||
exercising permissions granted by this License.
|
reduce the performance or security of any SAP products, services or related
|
||||||
|
technology (collectively, "SAP Products"); (b) enable the bypassing or
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
circumventing of SAP's license restrictions and/or provide users with access to
|
||||||
including but not limited to software source code, documentation
|
the SAP Products to which such users are not licensed; or (c) permit mass data
|
||||||
source, and configuration files.
|
extraction from an SAP Product to a non-SAP Product, including use,
|
||||||
|
modification, saving or other processing of such data in the non-SAP Product.
|
||||||
"Object" form shall mean any form resulting from mechanical
|
Further, You must not: (i) provide or make the Sample Code available to any
|
||||||
transformation or translation of a Source form, including but
|
third party other than your authorized employees, contractors and agents
|
||||||
not limited to compiled object code, generated documentation,
|
(collectively, “Representatives”) and solely to be used by Your Representatives
|
||||||
and conversions to other media types.
|
for Your own internal business purposes; ii) remove or modify any marks or
|
||||||
|
proprietary notices from the Sample Code; iii) assign this Agreement, or any
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
interest therein, to any third party; (iv) use any SAP name, trademark or logo
|
||||||
Object form, made available under the License, as indicated by a
|
without the prior written authorization of SAP; or (v) use the Sample Code to
|
||||||
copyright notice that is included in or attached to the work
|
modify an SAP Product or decompile, disassemble or reverse engineer an SAP
|
||||||
(an example is provided in the Appendix below).
|
Product (except to the extent permitted by applicable law). You are responsible
|
||||||
|
for any breach of the terms of this Agreement by You or Your Representatives.
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
3. INTELLECTUAL PROPERTY: SAP or its licensors retain all ownership and
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
intellectual property rights in and to the Sample Code and SAP Products. In
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
exchange for the right to use, copy and modify the Sample Code provided under
|
||||||
of this License, Derivative Works shall not include works that remain
|
this Agreement, You covenant not to assert any intellectual property rights in
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
or to any of Your products, services, or related technology that are based on
|
||||||
the Work and Derivative Works thereof.
|
or incorporate the Sample Code against any individual or entity in respect of
|
||||||
|
any current or future SAP Products.
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
4. SAP AND THIRD PARTY APIS: The Sample Code may include API (application
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
programming interface) calls to SAP and third-party products or services. The
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
access or use of the third-party products and services to which the API calls
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
are directed may be subject to additional terms and conditions between you and
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
SAP or such third parties. You (and not SAP) are solely responsible for
|
||||||
means any form of electronic, verbal, or written communication sent
|
understanding and complying with any additional terms and conditions that apply
|
||||||
to the Licensor or its representatives, including but not limited to
|
to the access or use of those APIs and/or third-party products and services.
|
||||||
communication on electronic mailing lists, source code control systems,
|
SAP does not grant You any rights in or to these APIs, products or services
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
under this Agreement.
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
5. FREE AND OPEN SOURCE COMPONENTS: The Sample Code may include third party
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
free or open source components ("FOSS Components"). You may have additional
|
||||||
|
rights in such FOSS Components that are provided by the third party licensors
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
of those components.
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
6. THIRD PARTY DEPENDENCIES: The Sample Code may require third party software
|
||||||
subsequently incorporated within the Work.
|
dependencies ("Dependencies") for the use or operation of the Sample Code. These
|
||||||
|
Dependencies may be identified by SAP in Maven POM files, documentation or by
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
other means. SAP does not grant You any rights in or to such Dependencies under
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
this Agreement. You are solely responsible for the acquisition, installation
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
and use of such Dependencies.
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
7. WARRANTY:
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
a) If You are located outside the US or Canada: AS THE SAMPLE CODE IS PROVIDED
|
||||||
Work and such Derivative Works in Source or Object form.
|
TO YOU FREE OF CHARGE, SAP DOES NOT GUARANTEE OR WARRANT ANY FEATURES OR
|
||||||
|
QUALITIES OF THE SAMPLE CODE OR GIVE ANY UNDERTAKING WITH REGARD TO ANY OTHER
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
QUALITY. NO SUCH WARRANTY OR UNDERTAKING SHALL BE IMPLIED BY YOU FROM ANY
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
DESCRIPTION IN THE SAMPLE CODE OR ANY OTHER MATERIALS, COMMUNICATION OR
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
ADVERTISEMENT. IN PARTICULAR, SAP DOES NOT WARRANT THAT THE SAMPLE CODE WILL BE
|
||||||
(except as stated in this section) patent license to make, have made,
|
AVAILABLE UNINTERRUPTED, ERROR FREE, OR PERMANENTLY AVAILABLE. ALL WARRANTY
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
CLAIMS RESPECTING THE SAMPLE CODE ARE SUBJECT TO THE LIMITATION OF LIABILITY
|
||||||
where such license applies only to those patent claims licensable
|
STIPULATED IN SECTION 8 BELOW.
|
||||||
by such Contributor that are necessarily infringed by their
|
b) If You are located in the US or Canada: THE SAMPLE CODE IS LICENSED TO YOU
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
"AS IS", WITHOUT ANY WARRANTY, ESCROW, TRAINING, MAINTENANCE, OR SERVICE
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
OBLIGATIONS WHATSOEVER ON THE PART OF SAP. SAP MAKES NO EXPRESS OR IMPLIED
|
||||||
institute patent litigation against any entity (including a
|
WARRANTIES OR CONDITIONS OF SALE OF ANY TYPE WHATSOEVER, INCLUDING BUT NOT
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY AND OF FITNESS FOR A PARTICULAR
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
PURPOSE. IN PARTICULAR, SAP DOES NOT WARRANT THAT THE SAMPLE CODE WILL BE
|
||||||
or contributory patent infringement, then any patent licenses
|
AVAILABLE UNINTERRUPTED, ERROR FREE, OR PERMANENTLY AVAILABLE. YOU ASSUME ALL
|
||||||
granted to You under this License for that Work shall terminate
|
RISKS ASSOCIATED WITH THE USE OF THE SAMPLE CODE, INCLUDING WITHOUT LIMITATION
|
||||||
as of the date such litigation is filed.
|
RISKS RELATING TO QUALITY, AVAILABILITY, PERFORMANCE, DATA LOSS, AND UTILITY IN
|
||||||
|
A PRODUCTION ENVIRONMENT.
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
c) For all locations: SAP DOES NOT MAKE ANY REPRESENTATIONS OR WARRANTIES IN
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
RESPECT OF THIRD PARTY DEPENDENCIES, APIS, PRODUCTS AND SERVICES, INCLUDING BUT
|
||||||
modifications, and in Source or Object form, provided that You
|
NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY AND OF FITNESS FOR A
|
||||||
meet the following conditions:
|
PARTICULAR PURPOSE. IN PARTICULAR, SAP DOES NOT WARRANT THAT THIRDPARTY
|
||||||
|
DEPENDENCIES, APIS, PRODUCTS AND SERVICES WILL BE AVAILABLE, ERROR FREE,
|
||||||
(a) You must give any other recipients of the Work or
|
INTEROPERABLE WITH THE SAMPLE CODE, SUITABLE FOR ANY PARTICULAR PURPOSE OR NONINFRINGING.
|
||||||
Derivative Works a copy of this License; and
|
YOU ASSUME ALL RISKS ASSOCIATED WITH THE USE OF THIRD
|
||||||
|
PARTY DEPENDENCIES, APIS, PRODUCTS AND SERVICES, INCLUDING WITHOUT LIMITATION
|
||||||
(b) You must cause any modified files to carry prominent notices
|
RISKS RELATING TO QUALITY, AVAILABILITY, PERFORMANCE, DATA LOSS, UTILITY IN A
|
||||||
stating that You changed the files; and
|
PRODUCTION ENVIRONMENT, AND NON-INFRINGEMENT. IN NO EVENT WILL SAP BE LIABLE
|
||||||
|
DIRECTLY OR INDIRECTLY IN RESPECT OF ANY USE OF THIRD PARTY DEPENDENCIES, APIS,
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
PRODUCTS AND SERVICES BY YOU.
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
8. LIMITATION OF LIABILITY:
|
||||||
excluding those notices that do not pertain to any part of
|
a) If You are located outside the US or Canada: IRRESPECTIVE OF THE LEGAL
|
||||||
the Derivative Works; and
|
REASONS, SAP SHALL ONLY BE LIABLE FOR DAMAGES UNDER THIS AGREEMENT IF SUCH
|
||||||
|
DAMAGE (I) CAN BE CLAIMED UNDER THE GERMAN PRODUCT LIABILITY ACT OR (II) IS
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
CAUSED BY INTENTIONAL MISCONDUCT OF SAP OR (III) CONSISTS OF PERSONAL INJURY.
|
||||||
distribution, then any Derivative Works that You distribute must
|
IN ALL OTHER CASES, NEITHER SAP NOR ITS EMPLOYEES, AGENTS AND SUBCONTRACTORS
|
||||||
include a readable copy of the attribution notices contained
|
SHALL BE LIABLE FOR ANY KIND OF DAMAGE OR CLAIMS HEREUNDER.
|
||||||
within such NOTICE file, excluding those notices that do not
|
b) If You are located in the US or Canada: IN NO EVENT SHALL SAP BE LIABLE TO
|
||||||
pertain to any part of the Derivative Works, in at least one
|
YOU, YOUR COMPANY OR TO ANY THIRD PARTY FOR ANY DAMAGES IN AN AMOUNT IN EXCESS
|
||||||
of the following places: within a NOTICE text file distributed
|
OF $100 ARISING IN CONNECTION WITH YOUR USE OF OR INABILITY TO USE THE SAMPLE
|
||||||
as part of the Derivative Works; within the Source form or
|
CODE OR IN CONNECTION WITH SAP'S PROVISION OF OR FAILURE TO PROVIDE SERVICES
|
||||||
documentation, if provided along with the Derivative Works; or,
|
PERTAINING TO THE SAMPLE CODE, OR AS A RESULT OF ANY DEFECT IN THE SAMPLE COED.
|
||||||
within a display generated by the Derivative Works, if and
|
THIS DISCLAIMER OF LIABILITY SHALL APPLY REGARDLESS OF THE FORM OF ACTION THAT
|
||||||
wherever such third-party notices normally appear. The contents
|
MAY BE BROUGHT AGAINST SAP, WHETHER IN CONTRACT OR TORT, INCLUDING WITHOUT
|
||||||
of the NOTICE file are for informational purposes only and
|
LIMITATION ANY ACTION FOR NEGLIGENCE. YOUR SOLE REMEDY IN THE EVENT OF BREACH
|
||||||
do not modify the License. You may add Your own attribution
|
OF THIS AGREEMENT BY SAP OR FOR ANY OTHER CLAIM RELATED TO THE SAMPLE CODE SHALL
|
||||||
notices within Derivative Works that You distribute, alongside
|
BE TERMINATION OF THIS AGREEMENT. NOTWITHSTANDING ANYTHING TO THE CONTRARY
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
HEREIN, UNDER NO CIRCUMSTANCES SHALL SAP OR ITS LICENSORS BE LIABLE TO YOU OR
|
||||||
that such additional attribution notices cannot be construed
|
ANY OTHER PERSON OR ENTITY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR
|
||||||
as modifying the License.
|
INDIRECT DAMAGES, LOSS OF GOOD WILL OR BUSINESS PROFITS, WORK STOPPAGE, DATA
|
||||||
|
LOSS, COMPUTER FAILURE OR MALFUNCTION, ANY AND ALL OTHER COMMERCIAL DAMAGES OR
|
||||||
You may add Your own copyright statement to Your modifications and
|
LOSS, OR EXEMPLARY OR PUNITIVE DAMAGES.
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
9. INDEMNITY: You will fully indemnify, hold harmless and defend SAP against
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
law suits based on any claim: (a) that any of Your products, services or related
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
technology that are based on or incorporate the Sample Code infringes or
|
||||||
the conditions stated in this License.
|
misappropriates any patent, copyright, trademark, trade secrets, or other
|
||||||
|
proprietary rights of a third party, or (b) related to Your alleged violation
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
of the terms of this Agreement.
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
10. EXPORT: The Sample Code is subject to German, EU and US export control
|
||||||
this License, without any additional terms or conditions.
|
regulations. You confirm that: a) You will not use the Sample Code for, and
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
will not allow the Sample Code to be used for, any purposes prohibited by
|
||||||
the terms of any separate license agreement you may have executed
|
German, EU and US law, including, without limitation, for the development,
|
||||||
with Licensor regarding such Contributions.
|
design, manufacture or production of nuclear, chemical or biological weapons of
|
||||||
|
mass destruction; b) You are not located in Cuba, Iran, Sudan, Iraq, North
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
Korea, Syria, nor any other country to which the United States has prohibited
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
export or that has been designated by the U.S. Government as a "terrorist
|
||||||
except as required for reasonable and customary use in describing the
|
supporting" country (any, an "US Embargoed Country"); c) You are not a citizen,
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
national or resident of, and are not under the control of, a US Embargoed
|
||||||
|
Country; d) You will not download or otherwise export or re-export the Sample
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
Code, directly or indirectly, to a US Embargoed Country nor to citizens,
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
nationals or residents of a US Embargoed Country; e) You are not listed on the
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
United States Department of Treasury lists of Specially Designated Nationals,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
Specially Designated Terrorists, and Specially Designated Narcotic Traffickers,
|
||||||
implied, including, without limitation, any warranties or conditions
|
nor listed on the United States Department of Commerce Table of Denial Orders
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
or any other U.S. government list of prohibited or restricted parties and f)
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
You will not download or otherwise export or re-export the Sample Code, directly
|
||||||
appropriateness of using or redistributing the Work and assume any
|
or indirectly, to persons on the above-mentioned lists.
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
11. SUPPORT: SAP does not offer support for the Sample Code.
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
12. TERM AND TERMINATION: You may terminate this Agreement by destroying all
|
||||||
unless required by applicable law (such as deliberate and grossly
|
copies of the Sample Code in Your possession or control. SAP may terminate Your
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
license to use the Sample Code immediately if You fail to comply with any of
|
||||||
liable to You for damages, including any direct, indirect, special,
|
the terms of this Agreement, or, for SAP's convenience by providing you with
|
||||||
incidental, or consequential damages of any character arising as a
|
ten (10) days written notice of termination. In case of termination or
|
||||||
result of this License or out of the use or inability to use the
|
expiration of this Agreement, You must immediately destroy all copies of the
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
Sample Code in your possession or control. In the event Your Company is acquired
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
(by merger, purchase of stock, assets or intellectual property or exclusive
|
||||||
other commercial damages or losses), even if such Contributor
|
license), or You become employed, by a direct competitor of SAP, then this
|
||||||
has been advised of the possibility of such damages.
|
Agreement and all licenses granted to You in this Agreement shall immediately
|
||||||
|
terminate upon the date of such acquisition or change of employment.
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
13. LAW/VENUE:
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
a) If You are located outside the US or Canada: This Agreement is governed by
|
||||||
or other liability obligations and/or rights consistent with this
|
and construed in accordance with the laws of Germany without reference to its
|
||||||
License. However, in accepting such obligations, You may act only
|
conflicts of law principles. You and SAP agree to submit to the exclusive
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
jurisdiction of, and venue in, the courts located in Karlsruhe, Germany in any
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
dispute arising out of or relating to this Agreement or the Sample Code. The
|
||||||
defend, and hold each Contributor harmless for any liability
|
United Nations Convention on Contracts for the International Sale of Goods shall
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
not apply to this Agreement.
|
||||||
of your accepting any such warranty or additional liability.
|
b) If You are located in the US or Canada: This Agreement shall be governed by
|
||||||
|
and construed in accordance with the laws of the State of New York, USA without
|
||||||
END OF TERMS AND CONDITIONS
|
reference to its conflicts of law principles. You and SAP agree to submit to
|
||||||
|
the exclusive jurisdiction of, and venue in, the courts located in New York,
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
New York, USA in any dispute arising out of or relating to this Agreement or
|
||||||
|
the Sample Code. The United Nations Convention on Contracts for the
|
||||||
To apply the Apache License to your work, attach the following
|
International Sale of Goods shall not apply to this Agreement.
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
||||||
replaced with your own identifying information. (Don't include
|
14. MISCELLANEOUS: This Agreement is the complete agreement between the parties
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
respecting the Sample Code. This Agreement supersedes all prior or
|
||||||
comment syntax for the file format. We also recommend that a
|
contemporaneous agreements or representations with regards to the Sample Code.
|
||||||
file or class name and description of purpose be included on the
|
If any term of this Agreement is found to be invalid or unenforceable, the
|
||||||
same "printed page" as the copyright notice for easier
|
surviving provisions shall remain effective. SAP's failure to enforce any right
|
||||||
identification within third-party archives.
|
or provisions stipulated in this Agreement will not constitute a waiver of such
|
||||||
|
provision, or any other provision of this Agreement.
|
||||||
Copyright [yyyy] [name of copyright owner]
|
|
||||||
|
v1.0-071618
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
|
|||||||
1
NOTICE
Normal file
1
NOTICE
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved.
|
||||||
42
README.md
Normal file
42
README.md
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# Welcome to SAP Cloud Application Programming model samples
|
||||||
|
|
||||||
|
Find here the samples for the openSAP course [Building Applications with the SAP Cloud Application Programming Model](https://open.sap.com/courses/cp7).
|
||||||
|
|
||||||
|
## Get Access to SAP Business Application Studio
|
||||||
|
The recommended environment for the course is SAP Business Application Studio. Watch [unit 2 of week 1](https://open.sap.com/courses/cp7/items/51pzQUzbXHr2kdbOmVs6jI) for how to get access.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
In SAP Business Application Studio, open a terminal.
|
||||||
|
Then clone the repo with this specific branch:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git clone https://github.com/sap-samples/cloud-cap-samples projects/cloud-cap-samples -b openSAP-week3-unit1
|
||||||
|
cd projects/cloud-cap-samples
|
||||||
|
```
|
||||||
|
|
||||||
|
In the `cloud-cap-samples` folder run:
|
||||||
|
```sh
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
## Run
|
||||||
|
|
||||||
|
Now you're ready to run the samples, for example:
|
||||||
|
```sh
|
||||||
|
cd packages/bookshop
|
||||||
|
cds watch
|
||||||
|
```
|
||||||
|
|
||||||
|
After that, watch out for the little popup in the lower right corner of SAP Business Application Studio that asks you to open the application in your browser.
|
||||||
|
|
||||||
|
|
||||||
|
## Get Support
|
||||||
|
|
||||||
|
Check out the cap docs at https://cap.cloud.sap. <br>
|
||||||
|
In case you find a bug or need support, please [open an issue in here](https://github.com/SAP-samples/cloud-cap-samples/issues/new).
|
||||||
|
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under SAP Sample Code License Agreement, except as noted otherwise in the [LICENSE](/LICENSE) file.
|
||||||
25
bookshop/.vscode/launch.json
vendored
25
bookshop/.vscode/launch.json
vendored
@@ -1,25 +0,0 @@
|
|||||||
{
|
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Attach to...",
|
|
||||||
"type": "node",
|
|
||||||
"request": "attach",
|
|
||||||
"processId": "${command:PickProcess}",
|
|
||||||
"skipFiles": ["<node_internals>/**"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "cds run",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"runtimeExecutable": "npx",
|
|
||||||
"runtimeArgs": ["-n"],
|
|
||||||
"args": ["--", "cds", "run", "--with-mocks", "--in-memory?"],
|
|
||||||
"console": "integratedTerminal",
|
|
||||||
"skipFiles": ["<node_internals>/**"]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
/* global Vue axios */ //> from vue.html
|
|
||||||
const $ = sel => document.querySelector(sel)
|
|
||||||
const GET = (url) => axios.get('/browse'+url)
|
|
||||||
const POST = (cmd,data) => axios.post('/browse'+cmd,data)
|
|
||||||
|
|
||||||
const books = Vue.createApp ({
|
|
||||||
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
list: [],
|
|
||||||
book: undefined,
|
|
||||||
order: { quantity:1, succeeded:'', failed:'' },
|
|
||||||
user: undefined
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
|
||||||
|
|
||||||
search: ({target:{value:v}}) => books.fetch(v && '&$search='+v),
|
|
||||||
|
|
||||||
async fetch (etc='') {
|
|
||||||
const {data} = await GET(`/ListOfBooks?$expand=genre($select=name),currency($select=symbol)${etc}`)
|
|
||||||
books.list = data.value
|
|
||||||
},
|
|
||||||
|
|
||||||
async inspect (eve) {
|
|
||||||
const book = books.book = books.list [eve.currentTarget.rowIndex-1]
|
|
||||||
const res = await GET(`/Books/${book.ID}?$select=descr,stock,image`)
|
|
||||||
Object.assign (book, res.data)
|
|
||||||
books.order = { quantity:1 }
|
|
||||||
setTimeout (()=> $('form > input').focus(), 111)
|
|
||||||
},
|
|
||||||
|
|
||||||
async submitOrder () {
|
|
||||||
const {book,order} = books, quantity = parseInt (order.quantity) || 1 // REVISIT: Okra should be less strict
|
|
||||||
try {
|
|
||||||
const res = await POST(`/submitOrder`, { quantity, book: book.ID })
|
|
||||||
book.stock = res.data.stock
|
|
||||||
books.order = { quantity, succeeded: `Successfully ordered ${quantity} item(s).` }
|
|
||||||
} catch (e) {
|
|
||||||
books.order = { quantity, failed: e.response.data.error ? e.response.data.error.message : e.response.data }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async login() {
|
|
||||||
try {
|
|
||||||
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')
|
|
||||||
|
|
||||||
books.getUserInfo()
|
|
||||||
books.fetch() // initially fill list of books
|
|
||||||
|
|
||||||
document.addEventListener('keydown', (event) => {
|
|
||||||
// hide user info on request
|
|
||||||
if (event.key === 'u') books.user = undefined
|
|
||||||
})
|
|
||||||
|
|
||||||
axios.interceptors.request.use(csrfToken)
|
|
||||||
function csrfToken (request) {
|
|
||||||
if (request.method === 'head' || request.method === 'get') return request
|
|
||||||
if ('csrfToken' in document) {
|
|
||||||
request.headers['x-csrf-token'] = document.csrfToken
|
|
||||||
return request
|
|
||||||
}
|
|
||||||
return fetchToken().then(token => {
|
|
||||||
document.csrfToken = token
|
|
||||||
request.headers['x-csrf-token'] = document.csrfToken
|
|
||||||
return request
|
|
||||||
}).catch(() => {
|
|
||||||
document.csrfToken = null // set mark to not try again
|
|
||||||
return request
|
|
||||||
})
|
|
||||||
|
|
||||||
function fetchToken() {
|
|
||||||
return axios.get('/', { headers: { 'x-csrf-token': 'fetch' } })
|
|
||||||
.then(res => res.headers['x-csrf-token'])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<title> Capire Books </title>
|
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/primitive-ui/dist/css/main.css">
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
|
|
||||||
<style>
|
|
||||||
.hovering tr:hover td { color:cyan; background: #123; cursor: pointer; }
|
|
||||||
.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'>
|
|
||||||
|
|
||||||
<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>
|
|
||||||
|
|
||||||
<input type="text" placeholder="Search..." @input="search">
|
|
||||||
|
|
||||||
<table id='books' class="hovering">
|
|
||||||
<thead>
|
|
||||||
<th> Book </th>
|
|
||||||
<th> Author </th>
|
|
||||||
<th> Genre </th>
|
|
||||||
<th> Rating </th>
|
|
||||||
<th> Price </th>
|
|
||||||
</thead>
|
|
||||||
<tr v-for="book in list" v-bind:id="book.ID" v-on:click="inspect">
|
|
||||||
<td>{{ book.title }}</td>
|
|
||||||
<td>{{ book.author }}</td>
|
|
||||||
<td>{{ book.genre.name }}</td>
|
|
||||||
<td class="rating-stars">
|
|
||||||
{{ ('★'.repeat(Math.round(book.rating))+'☆☆☆☆☆').slice(0,5) }} ({{ book.numberOfReviews }})
|
|
||||||
</td>
|
|
||||||
<td>{{ book.currency && book.currency.symbol }} {{ book.price }}</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<div v-if="book">
|
|
||||||
<img v-bind:src="book.image" alt=""/>
|
|
||||||
<label style="text-align:right">
|
|
||||||
<span class="succeeded"> {{ order.succeeded }} </span>
|
|
||||||
<span class="failed"> {{ order.failed }} </span>
|
|
||||||
{{ book.stock }} in stock
|
|
||||||
</label>
|
|
||||||
<form @submit.prevent="submitOrder" style="float:right; display:flex; flex-direction:row-reverse">
|
|
||||||
<input type="number" v-model="order.quantity" v-bind:class="{ failed: order.failed }" style="width:5em">
|
|
||||||
<input type="submit" value="Order:" class="muted-button">
|
|
||||||
</form>
|
|
||||||
<h4> {{ book.title }} </h4>
|
|
||||||
<p> {{ book.descr }} </p>
|
|
||||||
</div>
|
|
||||||
<div v-else>
|
|
||||||
( click on a row to see details... )
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
<script src="app.js"></script>
|
|
||||||
</html>
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
ID,name,dateOfBirth,placeOfBirth,dateOfDeath,placeOfDeath
|
|
||||||
101,Emily Brontë,1818-07-30,"Thornton, Yorkshire",1848-12-19,"Haworth, Yorkshire"
|
|
||||||
107,Charlotte Brontë,1818-04-21,"Thornton, Yorkshire",1855-03-31,"Haworth, Yorkshire"
|
|
||||||
150,Edgar Allen Poe,1809-01-19,"Boston, Massachusetts",1849-10-07,"Baltimore, Maryland"
|
|
||||||
170,Richard Carpenter,1929-08-14,"King’s Lynn, Norfolk",2012-02-26,"Hertfordshire, England"
|
|
||||||
|
@@ -1,5 +0,0 @@
|
|||||||
ID_texts,ID,locale,title,descr
|
|
||||||
d2a65a27-9f2a-480f-bc38-84ee8ec5c13e,201,de,Sturmhöhe,"Sturmhöhe (Originaltitel: Wuthering Heights) ist der einzige Roman der englischen Schriftstellerin Emily Brontë (1818–1848). Der 1847 unter dem Pseudonym Ellis Bell veröffentlichte Roman wurde vom viktorianischen Publikum weitgehend abgelehnt, heute gilt er als ein Klassiker der britischen Romanliteratur des 19. Jahrhunderts."
|
|
||||||
8c42c706-a979-41cf-9ffe-91e6cf1383a0,201,fr,Les Hauts de Hurlevent,"Les Hauts de Hurlevent (titre original : Wuthering Heights), parfois orthographié Les Hauts de Hurle-Vent, est l'unique roman d'Emily Brontë, publié pour la première fois en 1847 sous le pseudonyme d’Ellis Bell. Loin d'être un récit moralisateur, Emily Brontë achève néanmoins le roman dans une atmosphère sereine, suggérant le triomphe de la paix et du Bien sur la vengeance et le Mal."
|
|
||||||
9e1c4c81-dc90-4600-85b1-e9dd4bf12ce0,207,de,Jane Eyre,"Jane Eyre. Eine Autobiographie (Originaltitel: Jane Eyre. An Autobiography), erstmals erschienen im Jahr 1847 unter dem Pseudonym Currer Bell, ist der erste veröffentlichte Roman der britischen Autorin Charlotte Brontë und ein Klassiker der viktorianischen Romanliteratur des 19. Jahrhunderts. Der Roman erzählt in Form einer Ich-Erzählung die Lebensgeschichte von Jane Eyre (ausgesprochen /ˌdʒeɪn ˈɛə/), die nach einer schweren Kindheit eine Stelle als Gouvernante annimmt und sich in ihren Arbeitgeber verliebt, jedoch immer wieder um ihre Freiheit und Selbstbestimmung kämpfen muss. Als klein, dünn, blass, stets schlicht dunkel gekleidet und mit strengem Mittelscheitel beschrieben, gilt die Heldin des Romans Jane Eyre nicht zuletzt aufgrund der Kino- und Fernsehversionen der melodramatischen Romanvorlage als die bekannteste englische Gouvernante der Literaturgeschichte"
|
|
||||||
9be0524b-4cb9-4fc1-9dc2-d65b1c13cf53,252,de,Eleonora,"“Eleonora” ist eine Erzählung von Edgar Allan Poe. Sie wurde 1841 erstveröffentlicht. In ihr geht es um das Paradox der Treue in der Treulosigkeit."
|
|
||||||
|
@@ -1,43 +0,0 @@
|
|||||||
ID,parent_ID,name
|
|
||||||
10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,,Fiction
|
|
||||||
11aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Drama
|
|
||||||
12aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Poetry
|
|
||||||
13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Fantasy
|
|
||||||
131aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Fairy Tale
|
|
||||||
132aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Epic Fantasy
|
|
||||||
133aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,High Fantasy
|
|
||||||
134aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Gothic
|
|
||||||
14aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Science Fiction
|
|
||||||
141aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,14aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Utopian and Dystopian
|
|
||||||
1411aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,141aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Utopian
|
|
||||||
1412aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,141aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Dystopian
|
|
||||||
14121aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,1412aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Cyberpunk
|
|
||||||
141211aa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,14121aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Steampunk
|
|
||||||
142aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,14aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Space Opera
|
|
||||||
143aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,14aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Time Travel
|
|
||||||
144aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,14aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Tech Noir
|
|
||||||
15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Romance
|
|
||||||
151aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Contemporary Romance
|
|
||||||
152aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Historical Romance
|
|
||||||
153aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Romantic Suspense
|
|
||||||
16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Mystery
|
|
||||||
161aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Crime
|
|
||||||
1611aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,161aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Thriller
|
|
||||||
16111aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,1611aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Police Procedural
|
|
||||||
16112aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,1611aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Legal Thriller
|
|
||||||
16113aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,1611aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Medical Thriller
|
|
||||||
16114aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,1611aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Spy Thriller
|
|
||||||
1612aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,161aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Detective
|
|
||||||
1613aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,161aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Suspense
|
|
||||||
162aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Noir
|
|
||||||
1621aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,162aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Nordic Noir
|
|
||||||
1622aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,162aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Tart Noir
|
|
||||||
163aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Cozy Mystery
|
|
||||||
17aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Adventure
|
|
||||||
18aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Short Story
|
|
||||||
19aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Graphic Novel
|
|
||||||
20aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,,Non-Fiction
|
|
||||||
21aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,20aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Biography
|
|
||||||
22aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,21aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Autobiography
|
|
||||||
23aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,20aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Essay
|
|
||||||
24aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,20aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Speech
|
|
||||||
|
@@ -1,21 +0,0 @@
|
|||||||
const cds = require('@sap/cds')
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
* currencies, if not obtained through @capire/common.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// NOTE: We use cds.on('served') to delay the UPSERTs after the db init
|
|
||||||
// to run after all INSERTs from .csv files happened.
|
|
||||||
module.exports = cds.on('served', ()=>
|
|
||||||
UPSERT.into ('sap.common.Currencies') .columns (
|
|
||||||
[ 'code', 'symbol', 'name' ]
|
|
||||||
) .rows (
|
|
||||||
[ 'EUR', '€', 'Euro' ],
|
|
||||||
[ 'USD', '$', 'US Dollar' ],
|
|
||||||
[ 'GBP', '£', 'British Pound' ],
|
|
||||||
[ 'ILS', '₪', 'Shekel' ],
|
|
||||||
[ 'JPY', '¥', 'Yen' ],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
using { Currency, managed, sap } from '@sap/cds/common';
|
|
||||||
namespace sap.capire.bookshop;
|
|
||||||
|
|
||||||
entity Books : managed {
|
|
||||||
key ID : Integer;
|
|
||||||
title : localized String(111) @mandatory;
|
|
||||||
descr : localized String(1111);
|
|
||||||
author : Association to Authors @mandatory;
|
|
||||||
genre : Association to Genres;
|
|
||||||
stock : Integer;
|
|
||||||
price : Price;
|
|
||||||
currency : Currency;
|
|
||||||
image : LargeBinary @Core.MediaType: 'image/png';
|
|
||||||
}
|
|
||||||
|
|
||||||
entity Authors : managed {
|
|
||||||
key ID : Integer;
|
|
||||||
name : String(111) @mandatory;
|
|
||||||
dateOfBirth : Date;
|
|
||||||
dateOfDeath : Date;
|
|
||||||
placeOfBirth : String;
|
|
||||||
placeOfDeath : String;
|
|
||||||
books : Association to many Books on books.author = $self;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Hierarchically organized Code List for Genres */
|
|
||||||
entity Genres : sap.common.CodeList {
|
|
||||||
key ID : UUID;
|
|
||||||
parent : Association to Genres;
|
|
||||||
children : Composition of many Genres on children.parent = $self;
|
|
||||||
}
|
|
||||||
|
|
||||||
type Price : Decimal(9,2);
|
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------
|
|
||||||
// temporary workaround for reuse in fiori sample and hana deployment
|
|
||||||
annotate Books with @fiori.draft.enabled;
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
namespace sap.capire.bookshop; //> important for reflection
|
|
||||||
using from './db/schema';
|
|
||||||
using from './srv/cat-service';
|
|
||||||
using from './srv/admin-service';
|
|
||||||
using from './srv/user-service';
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@capire/bookshop",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "A simple self-contained bookshop service.",
|
|
||||||
"files": [
|
|
||||||
"app",
|
|
||||||
"srv",
|
|
||||||
"db",
|
|
||||||
"index.cds"
|
|
||||||
],
|
|
||||||
"devDependencies": {
|
|
||||||
"@cap-js/sqlite": ">=1"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@sap/cds": ">=7",
|
|
||||||
"express": "^4.17.1"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"genres": "cds serve test/genres.cds",
|
|
||||||
"start": "cds-serve",
|
|
||||||
"watch": "cds watch"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
# Bookshop Getting Started Sample
|
|
||||||
|
|
||||||
This stand-alone sample introduces the essential tasks in the development of CAP-based services as also covered in the [Getting Started guide in capire](https://cap.cloud.sap/docs/get-started/in-a-nutshell).
|
|
||||||
|
|
||||||
## Hypothetical Use Cases
|
|
||||||
|
|
||||||
1. Build a service that allows to browse _Books_ and _Authors_.
|
|
||||||
2. Books have assigned _Genres_, which are organized hierarchically.
|
|
||||||
3. All users may browse books without login.
|
|
||||||
4. All entries are maintained by Administrators.
|
|
||||||
5. End users may order books (the actual order mgmt being out of scope).
|
|
||||||
|
|
||||||
## Running the Sample
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm run watch
|
|
||||||
```
|
|
||||||
|
|
||||||
## Content & Best Practices
|
|
||||||
|
|
||||||
| Links to capire | Sample files / folders |
|
|
||||||
| --------------------------------------------------------------------------------------------------------- | ------------------------------------ |
|
|
||||||
| [Project Setup & Layouts](https://cap.cloud.sap/docs/get-started/jumpstart#project-structure) | [`./`](./) |
|
|
||||||
| [Domain Modeling with CDS](https://cap.cloud.sap/docs/guides/domain-modeling) | [`./db/schema.cds`](./db/schema.cds) |
|
|
||||||
| [Defining Services](https://cap.cloud.sap/docs/guides/providing-services#modeling-services) | [`./srv/*.cds`](./srv) |
|
|
||||||
| [Single-purposed Services](https://cap.cloud.sap/docs/guides/providing-services#single-purposed-services) | [`./srv/*.cds`](./srv) |
|
|
||||||
| [Providing & Consuming Providers](https://cap.cloud.sap/docs/guides/providing-services) | http://localhost:4004 |
|
|
||||||
| [Using Databases](https://cap.cloud.sap/docs/guides/databases) | [`./db/data/*.csv`](./db/data) |
|
|
||||||
| [Adding Custom Logic](https://cap.cloud.sap/docs/guides/providing-services#adding-custom-logic) | [`./srv/*.js`](./srv) |
|
|
||||||
| Adding Tests | [`./test`](./test) |
|
|
||||||
| [Sharing for Reuse](https://cap.cloud.sap/docs/guides/extensibility/composition) | [`./index.cds`](./index.cds) |
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
using { AdminService } from './admin-service';
|
|
||||||
annotate AdminService with @requires:'admin';
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
using { sap.capire.bookshop as my } from '../db/schema';
|
|
||||||
service AdminService @(path:'/admin') {
|
|
||||||
entity Authors as projection on my.Authors;
|
|
||||||
entity Books as projection on my.Books;
|
|
||||||
entity Genres as projection on my.Genres;
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
const cds = require('@sap/cds')
|
|
||||||
|
|
||||||
module.exports = class AdminService extends cds.ApplicationService { init(){
|
|
||||||
this.before (['NEW','CREATE'],'Authors', genid)
|
|
||||||
this.before (['NEW','CREATE'],'Books', genid)
|
|
||||||
return super.init()
|
|
||||||
}}
|
|
||||||
|
|
||||||
/** Generate primary keys for target entity in request */
|
|
||||||
async function genid (req) {
|
|
||||||
if (req.data.ID) return
|
|
||||||
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.
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using { sap.capire.bookshop as my } from '../db/schema';
|
|
||||||
service CatalogService @(path:'/browse') {
|
|
||||||
|
|
||||||
/** For displaying lists of Books */
|
|
||||||
@readonly entity ListOfBooks as projection on Books
|
|
||||||
excluding { descr };
|
|
||||||
|
|
||||||
/** For display in details pages */
|
|
||||||
@readonly entity Books as projection on my.Books { *,
|
|
||||||
author.name as author
|
|
||||||
} excluding { createdBy, modifiedBy };
|
|
||||||
|
|
||||||
@requires: 'authenticated-user'
|
|
||||||
action submitOrder ( book: Books:ID, quantity: Integer ) returns { stock: Integer };
|
|
||||||
event OrderedBook : { book: Books:ID; quantity: Integer; buyer: String };
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
const cds = require('@sap/cds')
|
|
||||||
|
|
||||||
class CatalogService extends cds.ApplicationService { init() {
|
|
||||||
|
|
||||||
const { Books } = cds.entities('sap.capire.bookshop')
|
|
||||||
const { ListOfBooks } = this.entities
|
|
||||||
|
|
||||||
// Add some discount for overstocked books
|
|
||||||
this.after('each', ListOfBooks, book => {
|
|
||||||
if (book.stock > 111) book.title += ` -- 11% discount!`
|
|
||||||
})
|
|
||||||
|
|
||||||
// Reduce stock of ordered books if available stock suffices
|
|
||||||
this.on('submitOrder', async req => {
|
|
||||||
let { book:id, quantity } = req.data
|
|
||||||
let book = await SELECT.from (Books, id, b => b.stock)
|
|
||||||
|
|
||||||
// Validate input data
|
|
||||||
if (!book) return req.error (404, `Book #${id} doesn't exist`)
|
|
||||||
if (quantity < 1) return req.error (400, `quantity has to be 1 or more`)
|
|
||||||
if (quantity > book.stock) return req.error (409, `${quantity} exceeds stock for book #${id}`)
|
|
||||||
|
|
||||||
// Reduce stock in database and return updated stock value
|
|
||||||
await UPDATE (Books, id) .with ({ stock: book.stock -= quantity })
|
|
||||||
return book
|
|
||||||
})
|
|
||||||
|
|
||||||
// Emit event when an order has been submitted
|
|
||||||
this.after('submitOrder', async (_,req) => {
|
|
||||||
let { book, quantity } = req.data
|
|
||||||
await this.emit('OrderedBook', { book, quantity, buyer: req.user.id })
|
|
||||||
})
|
|
||||||
|
|
||||||
// Delegate requests to the underlying generic service
|
|
||||||
return super.init()
|
|
||||||
}}
|
|
||||||
|
|
||||||
module.exports = CatalogService
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
/**
|
|
||||||
* Exposes user information
|
|
||||||
*/
|
|
||||||
service UserService @(path: '/user') {
|
|
||||||
/**
|
|
||||||
* The current user
|
|
||||||
*/
|
|
||||||
@odata.singleton entity me @cds.persistence.skip {
|
|
||||||
id : String; // user id
|
|
||||||
locale : String;
|
|
||||||
tenant : String;
|
|
||||||
}
|
|
||||||
|
|
||||||
action login() returns me;
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
const cds = require('@sap/cds')
|
|
||||||
module.exports = 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')
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
@@ -1,844 +0,0 @@
|
|||||||
const cds = require('@sap/cds')
|
|
||||||
const { expect } = cds.test
|
|
||||||
|
|
||||||
describe('cds.ql → cqn', () => {
|
|
||||||
|
|
||||||
const Foo = { name: 'Foo' }
|
|
||||||
const Books = { name: 'capire.bookshop.Books' }
|
|
||||||
|
|
||||||
const STAR = '*'
|
|
||||||
const skip = {to:{eql:()=>skip}}
|
|
||||||
const srv = new cds.Service
|
|
||||||
let cqn
|
|
||||||
|
|
||||||
expect.plain = (cqn) => !cqn.SELECT.one && !cqn.SELECT.distinct ? expect(cqn) : skip
|
|
||||||
expect.one = (cqn) => !cqn.SELECT.distinct ? expect(cqn) : skip
|
|
||||||
|
|
||||||
describe.each(['SELECT', 'SELECT one', 'SELECT distinct'])(`%s...`, (each) => {
|
|
||||||
|
|
||||||
let SELECT; beforeEach(()=> SELECT = (
|
|
||||||
each === 'SELECT distinct' ? cds.ql.SELECT.distinct :
|
|
||||||
each === 'SELECT one' ? cds.ql.SELECT.one :
|
|
||||||
cds.ql.SELECT
|
|
||||||
))
|
|
||||||
|
|
||||||
test(`from Foo`, () => {
|
|
||||||
expect(cqn = SELECT `from Foo`)
|
|
||||||
.to.eql(SELECT.from `Foo`)
|
|
||||||
.to.eql(SELECT.from('Foo'))
|
|
||||||
.to.eql(SELECT.from(Foo))
|
|
||||||
.to.eql(SELECT`Foo`)
|
|
||||||
.to.eql(SELECT('Foo'))
|
|
||||||
.to.eql(SELECT(Foo))
|
|
||||||
expect.plain(cqn)
|
|
||||||
.to.eql(CQL`SELECT from Foo`)
|
|
||||||
.to.eql(srv.read `Foo`)
|
|
||||||
.to.eql(srv.read('Foo'))
|
|
||||||
.to.eql(srv.read(Foo))
|
|
||||||
.to.eql({
|
|
||||||
SELECT: { from: { ref: ['Foo'] } },
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
if (each === 'SELECT')
|
|
||||||
test('SELECT ( Foo )', () => {
|
|
||||||
expect({
|
|
||||||
SELECT: { from: { ref: ['Foo'] } },
|
|
||||||
})
|
|
||||||
.to.eql(CQL`SELECT from Foo`)
|
|
||||||
.to.eql(SELECT(Foo))
|
|
||||||
})
|
|
||||||
|
|
||||||
if (each === 'SELECT')
|
|
||||||
test('SELECT ( Foo ) .from ( Bar )', () => {
|
|
||||||
|
|
||||||
expect({
|
|
||||||
SELECT: { columns:[{ref:['Foo']}], from: { ref: ['Bar'] } },
|
|
||||||
})
|
|
||||||
.to.eql(CQL`SELECT Foo from Bar`)
|
|
||||||
.to.eql(SELECT `Foo` .from `Bar`)
|
|
||||||
.to.eql(SELECT `Foo` .from('Bar'))
|
|
||||||
.to.eql(SELECT('Foo').from('Bar'))
|
|
||||||
.to.eql(SELECT(['Foo']).from('Bar'))
|
|
||||||
.to.eql(SELECT(['Foo']).from('Bar'))
|
|
||||||
.to.eql(SELECT `Bar` .columns `Foo`)
|
|
||||||
.to.eql(SELECT `Bar` .columns ('Foo'))
|
|
||||||
.to.eql(SELECT `Bar` .columns (['Foo']))
|
|
||||||
.to.eql(SELECT.from `Bar` .columns ('Foo'))
|
|
||||||
.to.eql(SELECT.from `Bar` .columns (['Foo']))
|
|
||||||
|
|
||||||
expect({
|
|
||||||
SELECT: { columns:[
|
|
||||||
{ref:['Foo']},
|
|
||||||
{ref:['Boo']},
|
|
||||||
], from: { ref: ['Bar'] } },
|
|
||||||
})
|
|
||||||
.to.eql(CQL`SELECT Foo, Boo from Bar`)
|
|
||||||
.to.eql(SELECT `Foo, Boo` .from `Bar`)
|
|
||||||
.to.eql(SELECT `Foo, Boo` .from('Bar'))
|
|
||||||
.to.eql(SELECT('Foo','Boo').from('Bar'))
|
|
||||||
.to.eql(SELECT(['Foo','Boo']).from('Bar'))
|
|
||||||
.to.eql(SELECT `Bar` .columns `Foo, Boo`)
|
|
||||||
.to.eql(SELECT `Bar` .columns `{ Foo, Boo }`)
|
|
||||||
.to.eql(SELECT `Bar` .columns ('{ Foo, Boo }'))
|
|
||||||
.to.eql(SELECT `Bar` .columns ('Foo','Boo'))
|
|
||||||
.to.eql(SELECT `Bar` .columns (['Foo','Boo']))
|
|
||||||
.to.eql(SELECT.from `Bar` .columns ('Foo','Boo'))
|
|
||||||
.to.eql(SELECT.from `Bar` .columns (['Foo','Boo']))
|
|
||||||
|
|
||||||
expect({
|
|
||||||
SELECT: { columns:[
|
|
||||||
{ref:['Foo']},
|
|
||||||
{ref:['Boo']},
|
|
||||||
{ref:['Moo']},
|
|
||||||
], from: { ref: ['Bar'] } },
|
|
||||||
})
|
|
||||||
.to.eql(CQL`SELECT Foo, Boo, Moo from Bar`)
|
|
||||||
.to.eql(SELECT `Foo, Boo, Moo` .from `Bar`)
|
|
||||||
.to.eql(SELECT `Foo, Boo, Moo` .from('Bar'))
|
|
||||||
.to.eql(SELECT('Foo','Boo','Moo').from('Bar'))
|
|
||||||
.to.eql(SELECT(['Foo','Boo','Moo']).from('Bar'))
|
|
||||||
.to.eql(SELECT `Bar` .columns `Foo, Boo, Moo`)
|
|
||||||
.to.eql(SELECT `Bar` .columns ('Foo','Boo','Moo'))
|
|
||||||
.to.eql(SELECT `Bar` .columns (['Foo','Boo','Moo']))
|
|
||||||
.to.eql(SELECT.from `Bar` .columns ('Foo','Boo','Moo'))
|
|
||||||
.to.eql(SELECT.from `Bar` .columns (['Foo','Boo','Moo']))
|
|
||||||
|
|
||||||
|
|
||||||
expect({
|
|
||||||
SELECT: { one:true, columns:[{ref:['Foo']}], from: { ref: ['Bar'] } },
|
|
||||||
})
|
|
||||||
// .to.eql(CQL`SELECT one Foo from Bar`)
|
|
||||||
.to.eql(SELECT.one `Foo` .from `Bar`)
|
|
||||||
.to.eql(SELECT.one `Foo` .from('Bar'))
|
|
||||||
.to.eql(SELECT.one('Foo').from('Bar'))
|
|
||||||
.to.eql(SELECT.one(['Foo']).from('Bar'))
|
|
||||||
.to.eql(SELECT.one(['Foo']).from('Bar'))
|
|
||||||
.to.eql(SELECT.one('Bar',['Foo']))
|
|
||||||
.to.eql(SELECT.one `Bar` .columns `Foo`)
|
|
||||||
.to.eql(SELECT.one('Bar').columns('Foo'))
|
|
||||||
.to.eql(SELECT.one('Bar').columns(['Foo']))
|
|
||||||
.to.eql(SELECT.one.from('Bar',['Foo']))
|
|
||||||
.to.eql(SELECT.one.from('Bar').columns('Foo'))
|
|
||||||
.to.eql(SELECT.one.from('Bar').columns(['Foo']))
|
|
||||||
|
|
||||||
expect({
|
|
||||||
SELECT: { one:true, columns:[
|
|
||||||
{ref:['Foo']},
|
|
||||||
{ref:['Boo']},
|
|
||||||
], from: { ref: ['Bar'] } },
|
|
||||||
})
|
|
||||||
// .to.eql(CQL`SELECT Foo, Boo from Bar`)
|
|
||||||
.to.eql(SELECT.one `Foo, Boo` .from `Bar`)
|
|
||||||
.to.eql(SELECT.one `Foo, Boo` .from('Bar'))
|
|
||||||
.to.eql(SELECT.one('Foo','Boo').from('Bar'))
|
|
||||||
.to.eql(SELECT.one(['Foo','Boo']).from('Bar'))
|
|
||||||
.to.eql(SELECT.one('Bar',['Foo','Boo']))
|
|
||||||
.to.eql(SELECT.one `Bar` .columns `Foo, Boo`)
|
|
||||||
.to.eql(SELECT.one('Bar').columns('Foo','Boo'))
|
|
||||||
.to.eql(SELECT.one('Bar').columns(['Foo','Boo']))
|
|
||||||
.to.eql(SELECT.one.from('Bar',['Foo','Boo']))
|
|
||||||
.to.eql(SELECT.one.from('Bar').columns('Foo','Boo'))
|
|
||||||
.to.eql(SELECT.one.from('Bar').columns(['Foo','Boo']))
|
|
||||||
|
|
||||||
expect({
|
|
||||||
SELECT: { one:true, columns:[
|
|
||||||
{ref:['Foo']},
|
|
||||||
{ref:['Boo']},
|
|
||||||
{ref:['Moo']},
|
|
||||||
], from: { ref: ['Bar'] } },
|
|
||||||
})
|
|
||||||
// .to.eql(CQL`SELECT Foo, Boo, Moo from Bar`)
|
|
||||||
.to.eql(SELECT.one `Foo, Boo, Moo` .from `Bar`)
|
|
||||||
.to.eql(SELECT.one `Foo, Boo, Moo` .from('Bar'))
|
|
||||||
.to.eql(SELECT.one('Foo','Boo','Moo').from('Bar'))
|
|
||||||
.to.eql(SELECT.one(['Foo','Boo','Moo']).from('Bar'))
|
|
||||||
.to.eql(SELECT.one('Bar',['Foo','Boo','Moo']))
|
|
||||||
.to.eql(SELECT.one `Bar` .columns `Foo, Boo, Moo`)
|
|
||||||
.to.eql(SELECT.one('Bar').columns('Foo','Boo','Moo'))
|
|
||||||
.to.eql(SELECT.one('Bar').columns(['Foo','Boo','Moo']))
|
|
||||||
.to.eql(SELECT.one.from('Bar',['Foo','Boo','Moo']))
|
|
||||||
.to.eql(SELECT.one.from('Bar').columns('Foo','Boo','Moo'))
|
|
||||||
.to.eql(SELECT.one.from('Bar').columns(['Foo','Boo','Moo']))
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
if (each === 'SELECT')
|
|
||||||
test('from ( Foo )', () => {
|
|
||||||
expect({
|
|
||||||
SELECT: { from: {ref: [{ id:'Foo', where: [{val:11}] }] }}
|
|
||||||
})
|
|
||||||
.to.eql(srv.read`Foo[${11}]`)
|
|
||||||
.to.eql(SELECT`Foo[${11}]`)
|
|
||||||
|
|
||||||
expect((cqn = SELECT`from Foo[ID=11]`))
|
|
||||||
.to.eql(SELECT`from Foo[ID=${11}]`)
|
|
||||||
.to.eql(SELECT.from `Foo[ID=11]`)
|
|
||||||
.to.eql(SELECT.from `Foo[ID=${11}]`)
|
|
||||||
.to.eql(SELECT`Foo[ID=11]`)
|
|
||||||
expect.plain(cqn)
|
|
||||||
.to.eql(CQL`SELECT from Foo[ID=11]`)
|
|
||||||
.to.eql(srv.read`Foo[ID=11]`)
|
|
||||||
.to.eql({
|
|
||||||
SELECT: { from: {
|
|
||||||
ref: [{ id: 'Foo', where: [{ ref: ['ID'] }, '=', { val: 11 }] }],
|
|
||||||
}},
|
|
||||||
})
|
|
||||||
|
|
||||||
expect.plain (cqn)
|
|
||||||
.to.eql(SELECT`Foo[ID=${11}]`)
|
|
||||||
.to.eql(srv.read`Foo[ID=${11}]`)
|
|
||||||
|
|
||||||
// Following implicitly resolve to SELECT.one
|
|
||||||
expect(cqn = SELECT.from(Foo,11))
|
|
||||||
.to.eql(SELECT.from(Foo,{ID:11}))
|
|
||||||
.to.eql(SELECT.from(Foo).byKey(11))
|
|
||||||
.to.eql(SELECT.from(Foo).byKey({ID:11}))
|
|
||||||
if (cds.version >= '5.6.0') {
|
|
||||||
expect.one(cqn)
|
|
||||||
.to.eql({
|
|
||||||
SELECT: {
|
|
||||||
one: true,
|
|
||||||
from: { ref: [{ id: 'Foo', where: [{ ref: ['ID'] }, '=', { val: 11 }] }] },
|
|
||||||
},
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
expect.one(cqn)
|
|
||||||
.to.eql({
|
|
||||||
SELECT: {
|
|
||||||
one: true,
|
|
||||||
from: { ref: ['Foo'] },
|
|
||||||
where: [{ ref: ['ID'] }, '=', { val: 11 }],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
test('from Foo {...}', () => {
|
|
||||||
|
|
||||||
expect(cqn = SELECT `*,a,b as c` .from `Foo`)
|
|
||||||
.to.eql(SELECT `*,a,b as c`. from(Foo))
|
|
||||||
.to.eql(SELECT('*','a',{b:'c'}).from`Foo`)
|
|
||||||
.to.eql(SELECT('*','a',{b:'c'}).from(Foo))
|
|
||||||
.to.eql(SELECT(['*','a',{b:'c'}]).from(Foo))
|
|
||||||
.to.eql(SELECT.columns('*','a',{b:'c'}).from(Foo))
|
|
||||||
.to.eql(SELECT.columns(['*','a',{b:'c'}]).from(Foo))
|
|
||||||
.to.eql(SELECT.columns((foo) => { foo`.*`, foo.a, foo.b`as c` }).from(Foo))
|
|
||||||
.to.eql(SELECT.columns((foo) => { foo('*'), foo.a, foo.b.as('c') }).from(Foo))
|
|
||||||
.to.eql(SELECT.from(Foo).columns('*','a',{b:'c'}))
|
|
||||||
.to.eql(SELECT.from(Foo).columns(['*','a',{b:'c'}]))
|
|
||||||
.to.eql(SELECT.from(Foo).columns((foo) => { foo`.*`, foo.a, foo.b`as c` }))
|
|
||||||
.to.eql(SELECT.from(Foo).columns((foo) => { foo('*'), foo.a, foo.b.as('c') }))
|
|
||||||
.to.eql(SELECT.from(Foo,['*','a',{b:'c'}]))
|
|
||||||
.to.eql(SELECT.from(Foo, (foo) => { foo`.*`, foo.a, foo.b`as c` }))
|
|
||||||
.to.eql(SELECT.from(Foo, (foo) => { foo('*'), foo.a, foo.b.as('c') }))
|
|
||||||
|
|
||||||
expect.plain(cqn)
|
|
||||||
.to.eql({
|
|
||||||
SELECT: {
|
|
||||||
from: { ref: ['Foo'] },
|
|
||||||
columns: [ STAR, { ref: ['a'] }, { ref: ['b'], as: 'c' }],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
expect.plain(cqn)
|
|
||||||
.to.eql(CQL`SELECT *,a,b as c from Foo`)
|
|
||||||
.to.eql(CQL`SELECT from Foo {*,a,b as c}`)
|
|
||||||
|
|
||||||
// Test combination with key as second argument to .from
|
|
||||||
expect(cqn = SELECT.from(Foo, 11, ['a']))
|
|
||||||
.to.eql(SELECT.from(Foo, 11, foo => foo.a))
|
|
||||||
|
|
||||||
if (cds.version >= '5.6.0') {
|
|
||||||
expect.one(cqn)
|
|
||||||
.to.eql({
|
|
||||||
SELECT: {
|
|
||||||
one: true,
|
|
||||||
from: { ref: [{ id: 'Foo', where: [{ ref: ['ID'] }, '=', { val: 11 }]}] },
|
|
||||||
columns: [{ ref: ['a'] }]
|
|
||||||
},
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
expect.one(cqn)
|
|
||||||
.to.eql({
|
|
||||||
SELECT: {
|
|
||||||
one: true,
|
|
||||||
from: { ref: ['Foo'] },
|
|
||||||
columns: [{ ref: ['a'] }],
|
|
||||||
where: [{ ref: ['ID'] }, '=', { val: 11 }],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
test('with nested expands', () => {
|
|
||||||
// SELECT from Foo { *, x, bar.*, car{*}, boo { *, moo.zoo } }
|
|
||||||
expect(cqn =
|
|
||||||
SELECT.from (Foo, foo => {
|
|
||||||
foo`*`, foo.x, foo.car`*`, foo.boo (b => {
|
|
||||||
b`*`, b.moo.zoo(
|
|
||||||
x => x.y.z
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
).to.eql(
|
|
||||||
SELECT.from (Foo, foo => {
|
|
||||||
foo('*'), foo.x, foo.car('*'), foo.boo (b => {
|
|
||||||
b('*'), b.moo.zoo(
|
|
||||||
x => x.y.z
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
expect.plain(cqn)
|
|
||||||
.to.eql({
|
|
||||||
SELECT: {
|
|
||||||
from: { ref: ['Foo'] },
|
|
||||||
columns: [
|
|
||||||
STAR,
|
|
||||||
{ ref: ['x'] },
|
|
||||||
{ ref: ['car'], expand: ['*'] },
|
|
||||||
{
|
|
||||||
ref: ['boo'],
|
|
||||||
expand: [ '*', { ref: ['moo', 'zoo'], expand: [{ ref: ['y', 'z'] }] }],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
test('with nested inlines', () => {
|
|
||||||
// SELECT from Foo { *, x, bar.*, car{*}, boo { *, moo.zoo } }
|
|
||||||
expect.plain(
|
|
||||||
SELECT.from (Foo, foo => {
|
|
||||||
foo.bar `*`,
|
|
||||||
foo.bar `.*`, //> leading dot indicates inline
|
|
||||||
foo.boo(_ => _.moo.zoo), //> underscore arg name indicates inline
|
|
||||||
foo.boo(x => x.moo.zoo)
|
|
||||||
})
|
|
||||||
).to.eql({
|
|
||||||
SELECT: {
|
|
||||||
from: { ref: ['Foo'] },
|
|
||||||
columns: [
|
|
||||||
{ ref: ['bar'], expand: ['*'] },
|
|
||||||
{ ref: ['bar'], inline: ['*'] },
|
|
||||||
{ ref: ['boo'], inline: [{ ref: ['moo', 'zoo'] }] },
|
|
||||||
{ ref: ['boo'], expand: [{ ref: ['moo', 'zoo'] }] },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
describe ('SELECT where...', ()=>{
|
|
||||||
|
|
||||||
it('should correctly handle { ... and:{...} }', () => {
|
|
||||||
expect(SELECT.from(Foo).where({ x: 1, and: { y: 2, or: { z: 3 } } })).to.eql({
|
|
||||||
SELECT: {
|
|
||||||
from: { ref: ['Foo'] },
|
|
||||||
where: [
|
|
||||||
{ ref: ['x'] },
|
|
||||||
'=',
|
|
||||||
{ val: 1 },
|
|
||||||
'and',
|
|
||||||
// '(',
|
|
||||||
{xpr:[
|
|
||||||
{ ref: ['y'] },
|
|
||||||
'=',
|
|
||||||
{ val: 2 },
|
|
||||||
'or',
|
|
||||||
{ ref: ['z'] },
|
|
||||||
'=',
|
|
||||||
{ val: 3 },
|
|
||||||
]},
|
|
||||||
// ')',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test ("where x='*'", ()=>{
|
|
||||||
expect (SELECT.from(Foo).where({x:'*'}))
|
|
||||||
.to.eql(SELECT.from(Foo).where("x='*'"))
|
|
||||||
.to.eql(SELECT.from(Foo).where("x=",'*'))
|
|
||||||
.to.eql(SELECT.from(Foo).where`x=${'*'}`)
|
|
||||||
.to.eql(
|
|
||||||
CQL`SELECT from Foo where x='*'`
|
|
||||||
)
|
|
||||||
expect (SELECT.from(Foo).where({x:['*',1]}))
|
|
||||||
.to.eql(SELECT.from(Foo).where("x in ('*',1)"))
|
|
||||||
.to.eql(SELECT.from(Foo).where("x in",['*',1]))
|
|
||||||
.to.eql(SELECT.from(Foo).where`x in ${['*',1]}`)
|
|
||||||
.to.eql(
|
|
||||||
CQL`SELECT from Foo where x in ('*',1)`
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test ('where, and, or', ()=>{
|
|
||||||
expect (
|
|
||||||
SELECT.from(Foo).where({x:1,and:{y:2}})
|
|
||||||
).to.eql (
|
|
||||||
CQL`SELECT from Foo where x=1 and y=2`
|
|
||||||
) .to.eql ({ SELECT: {
|
|
||||||
from: {ref:['Foo']},
|
|
||||||
where: [
|
|
||||||
{ref:['x']}, '=', {val:1},
|
|
||||||
'and',
|
|
||||||
{ref:['y']}, '=', {val:2}
|
|
||||||
]
|
|
||||||
}})
|
|
||||||
|
|
||||||
const ql_with_groups_fix = !!cds.ql.Query.prototype.flat
|
|
||||||
if (ql_with_groups_fix) {
|
|
||||||
|
|
||||||
expect (
|
|
||||||
SELECT.from(Foo).where({x:1}).or({y:2}).and({z:3})
|
|
||||||
).to.eql ({ SELECT: {
|
|
||||||
from: {ref:['Foo']},
|
|
||||||
where: [
|
|
||||||
{ref:['x']}, '=', {val:1},
|
|
||||||
'or',
|
|
||||||
{ref:['y']}, '=', {val:2},
|
|
||||||
'and',
|
|
||||||
{ref:['z']}, '=', {val:3},
|
|
||||||
]
|
|
||||||
}})
|
|
||||||
|
|
||||||
expect (
|
|
||||||
SELECT.from(Foo).where({x:1,or:{y:2}}).and({z:3})
|
|
||||||
).to.eql ({ SELECT: {
|
|
||||||
from: {ref:['Foo']},
|
|
||||||
where: [
|
|
||||||
{xpr:[
|
|
||||||
{ref:['x']}, '=', {val:1},
|
|
||||||
'or',
|
|
||||||
{ref:['y']}, '=', {val:2},
|
|
||||||
]},
|
|
||||||
'and',
|
|
||||||
{ref:['z']}, '=', {val:3},
|
|
||||||
]
|
|
||||||
}})
|
|
||||||
|
|
||||||
expect (
|
|
||||||
SELECT.from(Foo).where({a:1}).or({x:1,or:{y:2}}).and({z:3})
|
|
||||||
).to.eql ({ SELECT: {
|
|
||||||
from: {ref:['Foo']},
|
|
||||||
where: [
|
|
||||||
{ref:['a']}, '=', {val:1},
|
|
||||||
'or',
|
|
||||||
{xpr:[
|
|
||||||
{ref:['x']}, '=', {val:1},
|
|
||||||
'or',
|
|
||||||
{ref:['y']}, '=', {val:2},
|
|
||||||
]},
|
|
||||||
'and',
|
|
||||||
{ref:['z']}, '=', {val:3},
|
|
||||||
]
|
|
||||||
}})
|
|
||||||
|
|
||||||
expect (
|
|
||||||
{ SELECT: SELECT.from(Foo).where({x:1,or:{y:2}}).SELECT }
|
|
||||||
).to.eql ({ SELECT: {
|
|
||||||
from: {ref:['Foo']},
|
|
||||||
where: [
|
|
||||||
{ref:['x']}, '=', {val:1},
|
|
||||||
'or',
|
|
||||||
{ref:['y']}, '=', {val:2},
|
|
||||||
]
|
|
||||||
}})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
expect (
|
|
||||||
SELECT.from(Foo).where({x:1,and:{y:2}}).or({z:3})
|
|
||||||
).to.eql (
|
|
||||||
CQL`SELECT from Foo where x=1 and y=2 or z=3`
|
|
||||||
)
|
|
||||||
|
|
||||||
expect (
|
|
||||||
SELECT.from(Foo).where({x:1}).and({y:2,or:{z:3}})
|
|
||||||
).to.eql (
|
|
||||||
CQL`SELECT from Foo where x=1 and ( y=2 or z=3 )`
|
|
||||||
)
|
|
||||||
|
|
||||||
expect (
|
|
||||||
SELECT.from(Foo).where({1:1}).and({x:1,or:{x:2}}).and({y:2,or:{z:3}})
|
|
||||||
).to.eql (
|
|
||||||
CQL`SELECT from Foo where 1=1 and ( x=1 or x=2 ) and ( y=2 or z=3 )`
|
|
||||||
)
|
|
||||||
|
|
||||||
expect (
|
|
||||||
SELECT.from(Foo).where({x:1,or:{x:2}}).and({y:2,or:{z:3}})
|
|
||||||
).to.eql (
|
|
||||||
CQL`SELECT from Foo where ( x=1 or x=2 ) and ( y=2 or z=3 )`
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('where ({x:[undefined]})', () => {
|
|
||||||
expect (
|
|
||||||
SELECT.from(Foo).where({x:[undefined]})
|
|
||||||
).to.eql ({ SELECT: {
|
|
||||||
from: {ref:['Foo']},
|
|
||||||
where: [
|
|
||||||
{ref:['x']},
|
|
||||||
'in',
|
|
||||||
{ list: [ {val:undefined} ] }
|
|
||||||
]
|
|
||||||
}})
|
|
||||||
})
|
|
||||||
|
|
||||||
test('where ( ... cql | {x:y} )', () => {
|
|
||||||
const args = [`foo`, "'bar'", 3]
|
|
||||||
const ID = 11
|
|
||||||
|
|
||||||
// using simple predicate objects
|
|
||||||
// (Note: this doesn't support paths in left-hand-sides, nor references in arrays)
|
|
||||||
expect(
|
|
||||||
SELECT.from(Foo).where({
|
|
||||||
ID,
|
|
||||||
args,
|
|
||||||
and: { x: { like: '%x%' }, or: { y: { '>=': 9 } } },
|
|
||||||
})
|
|
||||||
).to.eql({
|
|
||||||
SELECT: {
|
|
||||||
from: { ref: ['Foo'] },
|
|
||||||
where: [
|
|
||||||
{ ref: ['ID'] },
|
|
||||||
'=',
|
|
||||||
{ val: ID },
|
|
||||||
'and',
|
|
||||||
{ ref: ['args'] },
|
|
||||||
'in',
|
|
||||||
{ list: args.map(val => ({ val })) },
|
|
||||||
'and',
|
|
||||||
{
|
|
||||||
xpr: [
|
|
||||||
{ ref: ['x'] },
|
|
||||||
'like',
|
|
||||||
{ val: '%x%' },
|
|
||||||
'or',
|
|
||||||
{ ref: ['y'] },
|
|
||||||
'>=',
|
|
||||||
{ val: 9 },
|
|
||||||
]
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// using CQL fragments -> uses cds.parse.expr
|
|
||||||
const is_v2 = !!cds.parse.expr('(1,2)').list
|
|
||||||
if (is_v2) expect((cqn = CQL`SELECT from Foo where ID=11 and x in ( foo, 'bar', 3)`)).to.eql({
|
|
||||||
SELECT: {
|
|
||||||
from: { ref: ['Foo'] },
|
|
||||||
where: [
|
|
||||||
{ ref: ['ID'] },
|
|
||||||
'=',
|
|
||||||
{ val: ID },
|
|
||||||
'and',
|
|
||||||
{ ref: ['x'] },
|
|
||||||
'in',
|
|
||||||
{list:[
|
|
||||||
{ ref: ['foo'] },
|
|
||||||
{ val: 'bar' },
|
|
||||||
{ val: 3 },
|
|
||||||
]}
|
|
||||||
],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
else expect((cqn = CQL`SELECT from Foo where ID=11 and x in ( foo, 'bar', 3)`)).to.eql({
|
|
||||||
SELECT: {
|
|
||||||
from: { ref: ['Foo'] },
|
|
||||||
where: [
|
|
||||||
{ ref: ['ID'] },
|
|
||||||
'=',
|
|
||||||
{ val: ID },
|
|
||||||
'and',
|
|
||||||
{ ref: ['x'] },
|
|
||||||
'in',
|
|
||||||
'(',
|
|
||||||
{ ref: ['foo'] },
|
|
||||||
',',
|
|
||||||
{ val: 'bar' },
|
|
||||||
',',
|
|
||||||
{ val: 3 },
|
|
||||||
')',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!is_v2) expect(
|
|
||||||
SELECT.from(Foo).where(`x=`, 1, `or y.z is null and (a>`, 2, `or b=`, 3, `)`)
|
|
||||||
).to.eql(CQL`SELECT from Foo where x=1 or y.z is null and (a>2 or b=3)`)
|
|
||||||
|
|
||||||
expect(SELECT.from(Foo).where(`x between`, 1, `and`, 9)).to.eql(
|
|
||||||
CQL`SELECT from Foo where x between 1 and 9`
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('w/ sub selects', () => {
|
|
||||||
// in where causes
|
|
||||||
expect(SELECT.from(Foo).where({ x: SELECT('y').from('Bar') })).to.eql(
|
|
||||||
CQL`SELECT from Foo where x in (SELECT y from Bar)`
|
|
||||||
)
|
|
||||||
|
|
||||||
// using query api
|
|
||||||
expect(SELECT.from('Books').where(
|
|
||||||
`author.name in`, SELECT('name').from('Authors'))).to.eql(CQL`SELECT from Books where author.name in (SELECT name from Authors)`
|
|
||||||
)
|
|
||||||
|
|
||||||
// in classical semi joins
|
|
||||||
expect(
|
|
||||||
SELECT('x').from(Foo) .where ( `exists`,
|
|
||||||
SELECT(1).from('Bar') .where ({ y: { ref: ['x'] } })
|
|
||||||
) // prettier-ignore
|
|
||||||
).to.eql(CQL`SELECT x from Foo where exists (SELECT 1 from Bar where y=x)`)
|
|
||||||
|
|
||||||
// in select clauses
|
|
||||||
cqn = CQL`SELECT from Foo { x, (SELECT y from Bar) as y }`
|
|
||||||
cds.version >= '3.33.3' &&
|
|
||||||
expect(
|
|
||||||
SELECT.from(Foo, (foo) => {
|
|
||||||
foo.x, foo(SELECT.from('Bar', (b) => b.y)).as('y')
|
|
||||||
})
|
|
||||||
).to.eql(cqn)
|
|
||||||
cds.version >= '3.33.3' &&
|
|
||||||
expect(
|
|
||||||
SELECT.from(Foo, ['x', Object.assign(SELECT('y').from('Bar'), { as: 'y' })])
|
|
||||||
).to.eql(cqn)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('w/ plain SQL', () => {
|
|
||||||
expect(SELECT.from(Books) + 'WHERE ...').to.eql(
|
|
||||||
'SELECT * FROM capire_bookshop_Books WHERE ...'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should consistently handle *', () => {
|
|
||||||
expect({
|
|
||||||
SELECT: { from: { ref: ['Foo'] }, columns: ['*'] },
|
|
||||||
})
|
|
||||||
.to.eql(CQL`SELECT * from Foo`)
|
|
||||||
.to.eql(CQL`SELECT from Foo{*}`)
|
|
||||||
.to.eql(SELECT('*').from(Foo))
|
|
||||||
.to.eql(SELECT.from(Foo,['*']))
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should consistently handle lists', () => {
|
|
||||||
const ID = 11, args = [{ref:['foo']}, "bar", 3]
|
|
||||||
const cqn = CQL`SELECT from Foo where ID=11 and x in (foo,'bar',3)`
|
|
||||||
expect(SELECT.from(Foo).where`ID=${ID} and x in ${args}`).to.eql(cqn)
|
|
||||||
expect(SELECT.from(Foo).where(`ID=`, ID, `and x in`, args)).to.eql(cqn)
|
|
||||||
expect(SELECT.from(Foo).where({ ID, x:args })).to.eql(cqn)
|
|
||||||
})
|
|
||||||
|
|
||||||
//
|
|
||||||
})
|
|
||||||
|
|
||||||
describe(`SELECT for update`, () => {
|
|
||||||
beforeAll(() => {
|
|
||||||
delete cds.env.sql.lock_acquire_timeout
|
|
||||||
})
|
|
||||||
|
|
||||||
it('no wait', () => {
|
|
||||||
const q = SELECT.from('Foo').forUpdate()
|
|
||||||
expect(q.SELECT.forUpdate).eqls({})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('specific wait', () => {
|
|
||||||
const q = SELECT.from('Foo').forUpdate({ wait: 1 })
|
|
||||||
expect(q.SELECT.forUpdate).eqls({ wait: 1 })
|
|
||||||
})
|
|
||||||
|
|
||||||
it('default wait', () => {
|
|
||||||
cds.env.sql.lock_acquire_timeout = 2
|
|
||||||
const q = SELECT.from('Foo').forUpdate()
|
|
||||||
expect(q.SELECT.forUpdate).eqls({ wait: 2 })
|
|
||||||
})
|
|
||||||
|
|
||||||
it('override default', () => {
|
|
||||||
cds.env.sql.lock_acquire_timeout = 1
|
|
||||||
const q = SELECT.from('Foo').forUpdate({ wait:-1 })
|
|
||||||
expect(q.SELECT.forUpdate).eqls({})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe(`INSERT...`, () => {
|
|
||||||
test('entries ({a,b}, ...)', () => {
|
|
||||||
const entries = [{ foo: 1 }, { boo: 2 }]
|
|
||||||
expect(INSERT(...entries).into(Foo))
|
|
||||||
.to.eql(INSERT(entries).into(Foo))
|
|
||||||
.to.eql(INSERT.into(Foo).entries(...entries))
|
|
||||||
.to.eql(INSERT.into(Foo).entries(entries))
|
|
||||||
.to.eql({
|
|
||||||
INSERT: { into: { ref: ['Foo'] }, entries },
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test('rows ([1,2], ...)', () => {
|
|
||||||
expect(
|
|
||||||
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({
|
|
||||||
INSERT: {
|
|
||||||
into: { ref: ['Foo'] },
|
|
||||||
columns: ['a', 'b'],
|
|
||||||
rows: [
|
|
||||||
[1, 2],
|
|
||||||
[3, 4],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test('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: { ref: ['Foo'] }, columns: ['a', 'b'], values: [1, 2] },
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test('w/ plain SQL', () => {
|
|
||||||
expect(INSERT.into(Books) + 'VALUES ...').to.eql(
|
|
||||||
'INSERT INTO capire_bookshop_Books VALUES ...'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe(`UPDATE...`, () => {
|
|
||||||
test('entity (..., <key>)', () => {
|
|
||||||
const cqnWhere = {
|
|
||||||
UPDATE: {
|
|
||||||
entity: { ref: ['capire.bookshop.Books'] },
|
|
||||||
where: [{ ref: ['ID'] }, '=', { val: 4711 }],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
expect(UPDATE(Books).where({ ID: 4711 }))
|
|
||||||
.to.eql(UPDATE(Books).where(`ID=`, 4711))
|
|
||||||
.to.eql(cqnWhere)
|
|
||||||
|
|
||||||
const cqnKey = (cds.version >= '5.6.0') ?
|
|
||||||
{
|
|
||||||
UPDATE: {
|
|
||||||
entity: { ref: [{ id: 'capire.bookshop.Books', where: [{ ref: ['ID'] }, '=', { val: 4711 }] }] }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
: cqnWhere
|
|
||||||
expect(UPDATE(Books, 4711))
|
|
||||||
.to.eql(UPDATE(Books, { ID: 4711 }))
|
|
||||||
.to.eql(UPDATE(Books).byKey(4711))
|
|
||||||
.to.eql(UPDATE(Books).byKey({ ID: 4711 }))
|
|
||||||
.to.eql(UPDATE.entity(Books, 4711))
|
|
||||||
.to.eql(UPDATE.entity(Books, { ID: 4711 }))
|
|
||||||
// etc...
|
|
||||||
.to.eql(cqnKey)
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
|
||||||
UPDATE.with allows to pass in plain data payloads, e.g. as obtained from REST clients.
|
|
||||||
In addition, UPDATE.with supports specifying expressions, either in CQL fragements
|
|
||||||
notation or as simple expression objects.
|
|
||||||
|
|
||||||
UPDATE.data allows to pass in plain data payloads, e.g. as obtained from REST clients.
|
|
||||||
The passed in object can be modified subsequently, e.g. by adding or modifying values
|
|
||||||
before the query is finally executed.
|
|
||||||
*/
|
|
||||||
test('with + data', () => {
|
|
||||||
if (cds.version < '4.1.0') return
|
|
||||||
const o = {}
|
|
||||||
const q = UPDATE(Foo).data(o).with(`bar-=`, 22)
|
|
||||||
o.foo = 11
|
|
||||||
expect(q)
|
|
||||||
.to.eql(UPDATE(Foo).with(`foo=`, 11, `bar-=`, 22))
|
|
||||||
.to.eql(UPDATE(Foo).with({ foo: 11, bar: { '-=': 22 } }))
|
|
||||||
.to.eql({
|
|
||||||
UPDATE: {
|
|
||||||
entity: { ref: ['Foo'] },
|
|
||||||
data: { foo: 11 },
|
|
||||||
with: {
|
|
||||||
bar: { xpr: [{ ref: ['bar'] }, '-', { val: 22 }] },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
// some more
|
|
||||||
expect(UPDATE(Foo).with(`bar = coalesce(x,y), car = 'foo''s bar, car'`)).to.eql({
|
|
||||||
UPDATE: {
|
|
||||||
entity: { ref: ['Foo'] },
|
|
||||||
data: {
|
|
||||||
car: "foo's bar, car",
|
|
||||||
},
|
|
||||||
with: {
|
|
||||||
bar: { func: 'coalesce', args: [{ ref: ['x'] }, { ref: ['y'] }] },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test('w/ plain SQL', () => {
|
|
||||||
expect(UPDATE(Books) + 'SET ...').to.eql('UPDATE capire_bookshop_Books SET ...')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe(`DELETE...`, () => {
|
|
||||||
test('from (..., <key>)', () => {
|
|
||||||
const cqnWhere = {
|
|
||||||
DELETE: {
|
|
||||||
from: { ref: ['capire.bookshop.Books'] },
|
|
||||||
where: [{ ref: ['ID'] }, '=', { val: 4711 }],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
expect(DELETE.from(Books).where({ ID: 4711 }))
|
|
||||||
.to.eql(DELETE.from(Books).where(`ID=`, 4711))
|
|
||||||
.to.eql(cqnWhere)
|
|
||||||
const cqnKey = (cds.version >= '5.6.0') ?
|
|
||||||
{
|
|
||||||
DELETE: {
|
|
||||||
from: { ref: [{ id: 'capire.bookshop.Books', where: [{ ref: ['ID'] }, '=', { val: 4711 }]}] }
|
|
||||||
},
|
|
||||||
} : cqnWhere
|
|
||||||
|
|
||||||
expect(DELETE(Books, 4711))
|
|
||||||
.to.eql(DELETE(Books, { ID: 4711 }))
|
|
||||||
.to.eql(DELETE.from(Books, 4711))
|
|
||||||
.to.eql(DELETE.from(Books, { ID: 4711 }))
|
|
||||||
.to.eql(DELETE.from(Books).byKey(4711))
|
|
||||||
.to.eql(DELETE.from(Books).byKey({ ID: 4711 }))
|
|
||||||
.to.eql(cqnKey)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('/w plain SQL', () => {
|
|
||||||
expect(DELETE.from(Books) + 'WHERE ...').to.eql(
|
|
||||||
'DELETE FROM capire_bookshop_Books WHERE ...'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe(`cds.ql etc...`, () => {
|
|
||||||
it('should keep null and undefined', () => {
|
|
||||||
for (let each of [null, undefined]) {
|
|
||||||
expect(SELECT.from(Foo).where({ ID: each })).to.eql({
|
|
||||||
SELECT: {
|
|
||||||
from: { ref: ['Foo'] },
|
|
||||||
where: [{ ref: ['ID'] }, '=', { val: each }],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
//
|
|
||||||
})
|
|
||||||
@@ -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,82 +0,0 @@
|
|||||||
const cds = require('@sap/cds')
|
|
||||||
const { expect } = cds.test ('@capire/bookshop')
|
|
||||||
cds.User.default = cds.User.privileged // disable auth checks
|
|
||||||
|
|
||||||
describe('cap/samples - Consuming Services locally', () => {
|
|
||||||
|
|
||||||
it('bootstrapped the database successfully', ()=>{
|
|
||||||
const { AdminService } = cds.services
|
|
||||||
const { Authors } = AdminService.entities
|
|
||||||
expect(AdminService).to.exist
|
|
||||||
expect(Authors).to.exist
|
|
||||||
})
|
|
||||||
|
|
||||||
it('supports targets as strings or reflected defs', async () => {
|
|
||||||
const AdminService = await cds.connect.to('AdminService')
|
|
||||||
const { Authors } = AdminService.entities
|
|
||||||
expect (await SELECT.from(Authors))
|
|
||||||
// .to.eql(await SELECT.from('Authors'))
|
|
||||||
.to.eql(await AdminService.read(Authors))
|
|
||||||
.to.eql(await AdminService.read('Authors'))
|
|
||||||
.to.eql(await AdminService.run(SELECT.from(Authors)))
|
|
||||||
.to.eql(await AdminService.run(SELECT.from('Authors')))
|
|
||||||
})
|
|
||||||
|
|
||||||
it('allows reading from local services using cds.ql', async () => {
|
|
||||||
const AdminService = await cds.connect.to('AdminService')
|
|
||||||
const authors = await AdminService.read (`Authors`, a => {
|
|
||||||
a.name,
|
|
||||||
a.books((b) => {
|
|
||||||
b.title,
|
|
||||||
b.currency((c) => {
|
|
||||||
c.name, c.symbol
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}).where(`name like`, 'E%')
|
|
||||||
expect(authors).to.containSubset([
|
|
||||||
{
|
|
||||||
name: 'Emily Brontë',
|
|
||||||
books: [
|
|
||||||
{
|
|
||||||
title: 'Wuthering Heights',
|
|
||||||
currency: { name: 'British Pound', symbol: '£' },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Edgar Allen Poe',
|
|
||||||
books: [
|
|
||||||
{ title: 'The Raven', currency: { name: 'US Dollar', symbol: '$' } },
|
|
||||||
{ title: 'Eleonora', currency: { name: 'US Dollar', symbol: '$' } },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('provides CRUD-style convenience methods', async () => {})
|
|
||||||
|
|
||||||
it('uses same methods for all kind of services, including dbs', async () => {
|
|
||||||
const srv = await cds.connect.to('AdminService')
|
|
||||||
const db = await cds.connect.to('db')
|
|
||||||
const { Authors } = srv.entities
|
|
||||||
const projection = (a) => {
|
|
||||||
a.name,
|
|
||||||
a.books((b) => {
|
|
||||||
b.title,
|
|
||||||
b.currency((c) => {
|
|
||||||
c.name, c.symbol
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const query1 = SELECT.from(Authors, projection).where(`name like`, 'E%')
|
|
||||||
const query2 = cds.read(Authors, projection).where(`name like`, 'E%')
|
|
||||||
expect(await cds.run(query1))
|
|
||||||
.to.eql(await db.run(query1))
|
|
||||||
.to.eql(await srv.run(query1))
|
|
||||||
.to.eql(await srv.read(Authors, projection).where(`name like`, 'E%'))
|
|
||||||
.to.eql(await cds.run(query2))
|
|
||||||
.to.eql(await db.run(query2))
|
|
||||||
.to.eql(await srv.run(query2))
|
|
||||||
.to.eql(await db.read(Authors, projection).where(`name like`, 'E%'))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
const cds = require('@sap/cds')
|
|
||||||
const { GET, POST, expect } = cds.test(__dirname+'/..')
|
|
||||||
cds.User.default = cds.User.Privileged // hard core monkey patch
|
|
||||||
|
|
||||||
describe('cap/samples - Custom Handlers', () => {
|
|
||||||
|
|
||||||
it('should reject out-of-stock orders', async () => {
|
|
||||||
await expect(POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}`).to.be.fulfilled
|
|
||||||
await expect(POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}`).to.be.fulfilled
|
|
||||||
await expect(POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}`).to.be.rejectedWith(
|
|
||||||
/409 - 5 exceeds stock for book #201/)
|
|
||||||
const { data } = await GET`/admin/Books/201/stock/$value`
|
|
||||||
expect(data).to.equal(2)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
const cds = require('@sap/cds')
|
|
||||||
const { expect } = cds.test.in(__dirname,'..','..')
|
|
||||||
|
|
||||||
describe('cap/samples - Hierarchical Data', ()=>{
|
|
||||||
|
|
||||||
const csn = CDL`
|
|
||||||
entity Categories {
|
|
||||||
key ID : Integer;
|
|
||||||
name : String;
|
|
||||||
children : Composition of many Categories on children.parent = $self;
|
|
||||||
parent : Association to Categories;
|
|
||||||
}
|
|
||||||
`
|
|
||||||
const model = cds.compile.for.nodejs(csn)
|
|
||||||
const {Categories:Cats} = model.definitions
|
|
||||||
|
|
||||||
before ('bootstrap sqlite in-memory db...', async()=>{
|
|
||||||
await cds.deploy (csn) .to ('sqlite::memory:') // REVISIT: cds.compile.to.sql should accept cds.compiled.for.nodejs models
|
|
||||||
expect (cds.db) .to.exist
|
|
||||||
expect (cds.db.model) .to.exist
|
|
||||||
})
|
|
||||||
|
|
||||||
it ('supports deeply nested inserts', ()=> INSERT.into (Cats,
|
|
||||||
{ ID:100, name:'Some Cats...', children:[
|
|
||||||
{ ID:101, name:'Cat', children:[
|
|
||||||
{ ID:102, name:'Kitty', children:[
|
|
||||||
{ ID:103, name:'Kitty Cat', children:[
|
|
||||||
{ ID:104, name:'Aristocat' } ]},
|
|
||||||
{ ID:105, name:'Kitty Bat' } ]},
|
|
||||||
{ ID:106, name:'Catwoman', children:[
|
|
||||||
{ ID:107, name:'Catalina' } ]} ]},
|
|
||||||
{ ID:108, name:'Catweazle' }
|
|
||||||
]}
|
|
||||||
))
|
|
||||||
|
|
||||||
it ('should generate correct queries for expands', ()=>{
|
|
||||||
let q = SELECT.from (Cats, c => { c.ID, c.name, c.children (c => c.name) })
|
|
||||||
expect (q) .to.eql ({
|
|
||||||
SELECT: {
|
|
||||||
from: { ref:[ "Categories" ] },
|
|
||||||
columns: [
|
|
||||||
{ ref: [ "ID" ] },
|
|
||||||
{ ref: [ "name" ] },
|
|
||||||
{ ref: [ "children" ], expand: [ {ref:['name']} ] },
|
|
||||||
]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
/* temp skip for release
|
|
||||||
if (q.forSQL) expect (q.forSQL()) .to.eql ({
|
|
||||||
SELECT: {
|
|
||||||
from: { ref:[ "Categories" ], as: "Categories" },
|
|
||||||
columns: [
|
|
||||||
{ ref: [ "Categories", "ID" ] },
|
|
||||||
{ ref: [ "Categories", "name" ] },
|
|
||||||
{ as: "children", SELECT: { expand: true,
|
|
||||||
one: false,
|
|
||||||
columns: [{ ref: [ "children", "name" ]}],
|
|
||||||
from: { ref:["Categories"], as: "children" },
|
|
||||||
where: [
|
|
||||||
{ref:[ "Categories", "ID" ]}, "=", {ref:[ "children", "parent_ID" ]}
|
|
||||||
],
|
|
||||||
}},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if (q.toSql) expect (q.toSql()) .to.eql (
|
|
||||||
`SELECT json_insert('{}',` +
|
|
||||||
`'$."ID"',ID,` +
|
|
||||||
`'$."name"',name,` +
|
|
||||||
`'$."children"',children->'$'` +
|
|
||||||
`) as _json_ FROM (` +
|
|
||||||
`SELECT Categories.ID,Categories.name,(` +
|
|
||||||
`SELECT jsonb_group_array(jsonb_insert('{}','$."name"',name)) as _json_ FROM (` +
|
|
||||||
`SELECT children.name FROM Categories as children WHERE Categories.ID = children.parent_ID` +
|
|
||||||
`)` +
|
|
||||||
`) as children FROM Categories as Categories` +
|
|
||||||
`)`
|
|
||||||
)
|
|
||||||
*/
|
|
||||||
})
|
|
||||||
|
|
||||||
it ('supports nested reads', ()=> expect (
|
|
||||||
SELECT.one.from (Cats, c=>{
|
|
||||||
c.ID, c.name.as('parent'), c.children (c=>{
|
|
||||||
c.name.as('child')
|
|
||||||
})
|
|
||||||
}) .where ({name:'Cat'})
|
|
||||||
) .to.eventually.eql (
|
|
||||||
{ ID:101, parent:'Cat', children:[
|
|
||||||
{ child:'Kitty' },
|
|
||||||
{ child:'Catwoman' },
|
|
||||||
]}
|
|
||||||
))
|
|
||||||
|
|
||||||
it ('supports deeply nested reads', ()=> expect (
|
|
||||||
SELECT.one.from (Cats, c=>{
|
|
||||||
c.ID, c.name, c.children (
|
|
||||||
c => { c.name },
|
|
||||||
{levels:3}
|
|
||||||
)
|
|
||||||
}) .where ({name:'Cat'})
|
|
||||||
) .to.eventually.eql (
|
|
||||||
{ ID:101, name:'Cat', children:[
|
|
||||||
{ name:'Kitty', children:[
|
|
||||||
{ name:'Kitty Cat', children:[
|
|
||||||
{ name:'Aristocat' }, ]}, // level 3
|
|
||||||
{ name:'Kitty Bat', children:[] }, ]},
|
|
||||||
{ name:'Catwoman', children:[
|
|
||||||
{ name:'Catalina', children:[] } ]},
|
|
||||||
]}
|
|
||||||
))
|
|
||||||
|
|
||||||
it ('supports cascaded deletes', async()=>{
|
|
||||||
const affectedRows = await DELETE.from (Cats) .where ({ID:[102,106]})
|
|
||||||
expect (affectedRows) .to.be.greaterThan (0)
|
|
||||||
await expect (SELECT`ID,name`.from(Cats) ).to.eventually.eql ([
|
|
||||||
{ ID:100, name:'Some Cats...' },
|
|
||||||
{ ID:101, name:'Cat' },
|
|
||||||
{ ID:108, name:'Catweazle' }
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
#################################################
|
|
||||||
#
|
|
||||||
# Genres
|
|
||||||
#
|
|
||||||
|
|
||||||
GET http://localhost:4004/odata/v4/test/Genres?
|
|
||||||
###
|
|
||||||
|
|
||||||
GET http://localhost:4004/odata/v4/test/Genres?
|
|
||||||
&$filter=parent_ID eq null&$select=name
|
|
||||||
&$expand=children($select=name)
|
|
||||||
###
|
|
||||||
|
|
||||||
POST http://localhost:4004/odata/v4/test/Genres?
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{ "ID":"100aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Some Sample Genres...", "children":[
|
|
||||||
{ "ID":"101aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Cat", "children":[
|
|
||||||
{ "ID":"102aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Kitty", "children":[
|
|
||||||
{ "ID":"103aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Aristocat" },
|
|
||||||
{ "ID":"104aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Kitty Bat" } ]},
|
|
||||||
{ "ID":"105aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Catwoman", "children":[
|
|
||||||
{ "ID":"106aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Catalina" } ]} ]},
|
|
||||||
{ "ID":"107aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Catweazle" }
|
|
||||||
]}
|
|
||||||
###
|
|
||||||
|
|
||||||
GET http://localhost:4004/odata/v4/test/Genres(100aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa)?
|
|
||||||
&$expand=children
|
|
||||||
&$expand=children($expand=children($expand=children($expand=children)))
|
|
||||||
###
|
|
||||||
|
|
||||||
DELETE http://localhost:4004/odata/v4/test/Genres(103aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa)
|
|
||||||
###
|
|
||||||
|
|
||||||
DELETE http://localhost:4004/odata/v4/test/Genres(100aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa)
|
|
||||||
###
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
using { sap.capire.bookshop as my } from '../../db/schema';
|
|
||||||
service TestService {
|
|
||||||
entity Genres as projection on my.Genres;
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"devDependencies": {
|
|
||||||
"@cap-js/sqlite": "*"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
using { CatalogService, sap.capire.bookshop as my } from '@capire/bookshop';
|
|
||||||
using from '@capire/common';
|
|
||||||
|
|
||||||
extend service CatalogService with {
|
|
||||||
@cds.localized:false
|
|
||||||
entity BooksSans as projection on my.Books {
|
|
||||||
*, //> non-localized defaults, e.g. title
|
|
||||||
key ID,
|
|
||||||
texts.title as localized_title,
|
|
||||||
texts.locale
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
const cds = require('@sap/cds')
|
|
||||||
const { GET, expect } = cds.test (__dirname)
|
|
||||||
cds.User.default = cds.User.Privileged // hard core monkey patch
|
|
||||||
|
|
||||||
describe('cap/samples - Localized Data', () => {
|
|
||||||
|
|
||||||
it('serves localized $metadata documents', async () => {
|
|
||||||
const { data } = await GET(`/browse/$metadata?sap-language=de`, { headers: { 'accept-language': 'de' }})
|
|
||||||
expect(data).to.contain('<Annotation Term="Common.Label" String="Währung"/>')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('supports accept-language header', async () => {
|
|
||||||
const { data } = await GET(`/browse/Books?$select=title,author`, {
|
|
||||||
headers: { 'Accept-Language': 'de' },
|
|
||||||
})
|
|
||||||
expect(data.value).to.containSubset([
|
|
||||||
{ title: 'Sturmhöhe', author: 'Emily Brontë' },
|
|
||||||
{ title: 'Jane Eyre', author: 'Charlotte Brontë' },
|
|
||||||
{ title: 'The Raven', author: 'Edgar Allen Poe' },
|
|
||||||
{ title: 'Eleonora', author: 'Edgar Allen Poe' },
|
|
||||||
{ title: 'Catweazle', author: 'Richard Carpenter' },
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('supports queries with $expand', async () => {
|
|
||||||
const { data } = await GET(`/browse/Books?&$select=title,author&$expand=currency`, {
|
|
||||||
headers: { 'Accept-Language': 'de' },
|
|
||||||
})
|
|
||||||
expect(data.value).to.containSubset([
|
|
||||||
{ title: 'Sturmhöhe', author: 'Emily Brontë', currency: { name: 'Pfund' } },
|
|
||||||
{ title: 'Jane Eyre', author: 'Charlotte Brontë', currency: { name: 'Pfund' } },
|
|
||||||
{ title: 'The Raven', author: 'Edgar Allen Poe', currency: { name: 'US-Dollar' } },
|
|
||||||
{ title: 'Eleonora', author: 'Edgar Allen Poe', currency: { name: 'US-Dollar' } },
|
|
||||||
{ title: 'Catweazle', author: 'Richard Carpenter', currency: { name: 'Yen' } },
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('supports queries with nested $expand', async () => {
|
|
||||||
const { data } = await GET(`/admin/Authors`, {
|
|
||||||
params: {
|
|
||||||
$filter: `startswith(name,'E')`,
|
|
||||||
$expand: `books(
|
|
||||||
$select=title;
|
|
||||||
$expand=currency(
|
|
||||||
$select=name,symbol
|
|
||||||
)
|
|
||||||
)`.replace(/\s/g, ''),
|
|
||||||
$select: `name`,
|
|
||||||
},
|
|
||||||
headers: { 'Accept-Language': 'de' },
|
|
||||||
})
|
|
||||||
expect(data.value).to.containSubset([
|
|
||||||
{
|
|
||||||
name: 'Emily Brontë',
|
|
||||||
books: [{ title: 'Sturmhöhe', currency: { name: 'Pfund', symbol: '£' } }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Edgar Allen Poe',
|
|
||||||
books: [
|
|
||||||
{ title: 'The Raven', currency: { name: 'US-Dollar', symbol: '$' } },
|
|
||||||
{ title: 'Eleonora', currency: { name: 'US-Dollar', symbol: '$' } },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('supports @cds.localized:false', async ()=>{
|
|
||||||
const { data } = await GET(`/browse/BooksSans?&$select=title,localized_title&$expand=currency&$filter=locale eq 'de' or locale eq null`, {
|
|
||||||
headers: { 'Accept-Language': 'de' },
|
|
||||||
})
|
|
||||||
expect(data.value).to.containSubset([
|
|
||||||
{ title: 'Wuthering Heights', localized_title: 'Sturmhöhe', currency: { name: 'British Pound' } },
|
|
||||||
{ title: 'Jane Eyre', currency: { name: 'British Pound' } },
|
|
||||||
{ title: 'The Raven', currency: { name: 'US Dollar' } },
|
|
||||||
{ title: 'Eleonora', currency: { name: 'US Dollar' } },
|
|
||||||
{ title: 'Catweazle', currency: { name: 'Yen' } },
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
const cds = require('@sap/cds')
|
|
||||||
const { expect } = cds.test.in(__dirname,'..')
|
|
||||||
|
|
||||||
describe('cap/samples - Messaging', ()=>{
|
|
||||||
|
|
||||||
const _model = '@capire/reviews'
|
|
||||||
const Reviews = 'sap.capire.reviews.Reviews'
|
|
||||||
beforeAll(()=>{
|
|
||||||
cds.User.default = cds.User.Privileged // hard core monkey patch
|
|
||||||
})
|
|
||||||
|
|
||||||
it ('should bootstrap sqlite in-memory db', async()=>{
|
|
||||||
const db = await cds.deploy (_model) .to ('sqlite::memory:')
|
|
||||||
await db.delete(Reviews)
|
|
||||||
expect (db.model) .not.undefined
|
|
||||||
})
|
|
||||||
|
|
||||||
let srv
|
|
||||||
it ('should serve ReviewsService', async()=>{
|
|
||||||
srv = await cds.serve('ReviewsService') .from (_model)
|
|
||||||
expect (srv.name) .to.match (/ReviewsService/)
|
|
||||||
})
|
|
||||||
|
|
||||||
let N=0, received=[], M=0
|
|
||||||
it ('should add messaging event handlers', ()=>{
|
|
||||||
srv.on('reviewed', (msg)=> received.push(msg))
|
|
||||||
})
|
|
||||||
|
|
||||||
it ('should add more messaging event handlers', ()=>{
|
|
||||||
srv.on('reviewed', ()=> ++M)
|
|
||||||
})
|
|
||||||
|
|
||||||
it ('should add review', async ()=>{
|
|
||||||
const review = { subject: "201", title: "Captivating", rating: ++N }
|
|
||||||
cds._debug = 1
|
|
||||||
const response = await srv.create ('Reviews') .entries (review)
|
|
||||||
expect (response) .to.containSubset (review)
|
|
||||||
})
|
|
||||||
|
|
||||||
it ('should add more reviews', ()=> Promise.all ([
|
|
||||||
// REVISIT: mass operation should trigger one message per entry
|
|
||||||
// srv.create('Reviews').entries(
|
|
||||||
// { ID: 111 + (++N), subject: "201", title: "Captivating", rating: N },
|
|
||||||
// { ID: 111 + (++N), subject: "201", title: "Captivating", rating: N },
|
|
||||||
// { ID: 111 + (++N), subject: "201", title: "Captivating", rating: N },
|
|
||||||
// { ID: 111 + (++N), subject: "201", title: "Captivating", rating: N },
|
|
||||||
// ),
|
|
||||||
srv.create ('Reviews') .entries (
|
|
||||||
{ ID: String(111 + (++N)), subject: "201", title: "Captivating", rating: N }
|
|
||||||
),
|
|
||||||
srv.create ('Reviews') .entries (
|
|
||||||
{ ID: String(111 + (++N)), subject: "201", title: "Captivating", rating: N }
|
|
||||||
),
|
|
||||||
srv.create ('Reviews') .entries (
|
|
||||||
{ ID: String(111 + (++N)), subject: "201", title: "Captivating", rating: N }
|
|
||||||
),
|
|
||||||
srv.create ('Reviews') .entries (
|
|
||||||
{ ID: String(111 + (++N)), subject: "201", title: "Captivating", rating: N }
|
|
||||||
),
|
|
||||||
]))
|
|
||||||
|
|
||||||
it ('should have received all messages', async()=> {
|
|
||||||
await new Promise((done)=>setImmediate(done))
|
|
||||||
expect(M).equals(N)
|
|
||||||
expect(received.length).equals(N)
|
|
||||||
expect(received.map(m=>m.data)).to.deep.equal([
|
|
||||||
{ count: 1, subject: '201', rating: 1 },
|
|
||||||
{ count: 2, subject: '201', rating: 1.5 },
|
|
||||||
{ count: 3, subject: '201', rating: 2 },
|
|
||||||
{ count: 4, subject: '201', rating: 2.5 },
|
|
||||||
{ count: 5, subject: '201', rating: 3 },
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
const cds = require('@sap/cds')
|
|
||||||
const { GET, expect, axios } = cds.test ('@capire/bookshop')
|
|
||||||
axios.defaults.auth = { username: 'alice', password: 'admin' }
|
|
||||||
|
|
||||||
describe('cap/samples - Bookshop APIs', () => {
|
|
||||||
|
|
||||||
it('serves $metadata documents in v4', async () => {
|
|
||||||
const { headers, status, data } = await GET `/browse/$metadata`
|
|
||||||
expect(status).to.equal(200)
|
|
||||||
expect(headers).to.contain({
|
|
||||||
// 'content-type': 'application/xml', //> fails with 'application/xml;charset=utf-8', which is set by express
|
|
||||||
'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('<Annotation Term="Common.Label" String="Currency"/>')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('serves ListOfBooks?$expand=genre,currency', async () => {
|
|
||||||
const Mystery = { name: 'Mystery' }
|
|
||||||
const Romance = { name: 'Romance' }
|
|
||||||
const USD = { code: 'USD', name: 'US Dollar', descr: null, symbol: '$' }
|
|
||||||
const { data } = await GET `/browse/ListOfBooks ${{
|
|
||||||
params: { $search: 'Po', $select: `title,author`, $expand:`genre,currency` },
|
|
||||||
}}`
|
|
||||||
expect(data.value).to.containSubset([
|
|
||||||
{ ID: 251, title: 'The Raven', author: 'Edgar Allen Poe', genre:Mystery, currency:USD },
|
|
||||||
{ ID: 252, title: 'Eleonora', author: 'Edgar Allen Poe', genre:Romance, currency:USD },
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('query options...', () => {
|
|
||||||
|
|
||||||
it('supports $search in multiple fields', async () => {
|
|
||||||
const { data } = await GET `/browse/Books ${{
|
|
||||||
params: { $search: 'Po', $select: `title,author` },
|
|
||||||
}}`
|
|
||||||
expect(data.value).to.containSubset([
|
|
||||||
{ ID: 201, title: 'Wuthering Heights', author: 'Emily Brontë' },
|
|
||||||
{ ID: 207, title: 'Jane Eyre', author: 'Charlotte Brontë' },
|
|
||||||
{ ID: 251, title: 'The Raven', author: 'Edgar Allen Poe' },
|
|
||||||
{ ID: 252, title: 'Eleonora', author: 'Edgar Allen Poe' },
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('supports $select', async () => {
|
|
||||||
const { data } = await GET(`/browse/Books`, {
|
|
||||||
params: { $select: `ID,title` },
|
|
||||||
})
|
|
||||||
expect(data.value).to.containSubset([
|
|
||||||
{ ID: 201, title: 'Wuthering Heights' },
|
|
||||||
{ ID: 207, title: 'Jane Eyre' },
|
|
||||||
{ ID: 251, title: 'The Raven' },
|
|
||||||
{ ID: 252, title: 'Eleonora' },
|
|
||||||
{ ID: 271, title: 'Catweazle' },
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('supports $expand', async () => {
|
|
||||||
const { data } = await GET(`/admin/Authors`, {
|
|
||||||
params: {
|
|
||||||
$select: `name`,
|
|
||||||
$expand: `books($select=title)`,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
expect(data.value).to.containSubset([
|
|
||||||
{ name: 'Emily Brontë', books: [{ title: 'Wuthering Heights' }] },
|
|
||||||
{ name: 'Charlotte Brontë', books: [{ title: 'Jane Eyre' }] },
|
|
||||||
{ name: 'Edgar Allen Poe', books: [{ title: 'The Raven' }, { title: 'Eleonora' }] },
|
|
||||||
{ name: 'Richard Carpenter', books: [{ title: 'Catweazle' }] },
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('supports $value requests', async () => {
|
|
||||||
const { data } = await GET`/admin/Books/201/stock/$value`
|
|
||||||
expect(data).to.equal(12)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('supports $top/$skip paging', async () => {
|
|
||||||
const { data: p1 } = await GET`/browse/Books?$select=title&$top=3`
|
|
||||||
expect(p1.value).to.containSubset([
|
|
||||||
{ ID: 201, title: 'Wuthering Heights' },
|
|
||||||
{ ID: 207, title: 'Jane Eyre' },
|
|
||||||
{ ID: 251, title: 'The Raven' },
|
|
||||||
])
|
|
||||||
const { data: p2 } = await GET`/browse/Books?$select=title&$skip=3`
|
|
||||||
expect(p2.value).to.containSubset([
|
|
||||||
{ ID: 252, title: 'Eleonora' },
|
|
||||||
{ ID: 271, title: 'Catweazle' },
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('serves user info', async () => {
|
|
||||||
const { data: alice } = await GET `/user/me`
|
|
||||||
expect(alice).to.containSubset({ id: 'alice' })
|
|
||||||
const { data: joe } = await GET (`/user/me`, {auth: { username: 'joe' }})
|
|
||||||
expect(joe).to.containSubset({ id: 'joe' })
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
@server = http://localhost:4004
|
|
||||||
@me = Authorization: Basic {{$processEnv USER}}:
|
|
||||||
|
|
||||||
|
|
||||||
### ------------------------------------------------------------------------
|
|
||||||
# Get service info
|
|
||||||
GET {{server}}/browse
|
|
||||||
{{me}}
|
|
||||||
|
|
||||||
|
|
||||||
### ------------------------------------------------------------------------
|
|
||||||
# Get $metadata document
|
|
||||||
GET {{server}}/browse/$metadata
|
|
||||||
{{me}}
|
|
||||||
|
|
||||||
|
|
||||||
### ------------------------------------------------------------------------
|
|
||||||
# Browse Books as any user
|
|
||||||
GET {{server}}/browse/ListOfBooks?
|
|
||||||
# &$select=title,stock
|
|
||||||
&$expand=genre
|
|
||||||
# &sap-language=de
|
|
||||||
{{me}}
|
|
||||||
|
|
||||||
|
|
||||||
### ------------------------------------------------------------------------
|
|
||||||
# Fetch Authors as admin
|
|
||||||
GET {{server}}/admin/Authors?
|
|
||||||
# &$select=name,dateOfBirth,placeOfBirth
|
|
||||||
# &$expand=books($select=title;$expand=currency)
|
|
||||||
# &$filter=ID eq 101
|
|
||||||
# &sap-language=de
|
|
||||||
Authorization: Basic alice:
|
|
||||||
|
|
||||||
### ------------------------------------------------------------------------
|
|
||||||
# Create Author
|
|
||||||
POST {{server}}/admin/Authors
|
|
||||||
Content-Type: application/json;IEEE754Compatible=true
|
|
||||||
Authorization: Basic alice:
|
|
||||||
|
|
||||||
{
|
|
||||||
"ID": 112,
|
|
||||||
"name": "Shakespeeeeere"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
### ------------------------------------------------------------------------
|
|
||||||
# Create book
|
|
||||||
POST {{server}}/admin/Books
|
|
||||||
Content-Type: application/json;IEEE754Compatible=true
|
|
||||||
Authorization: Basic alice:
|
|
||||||
|
|
||||||
{
|
|
||||||
"ID": 2,
|
|
||||||
"title": "Poems : Pocket Poets",
|
|
||||||
"descr": "The Everyman's Library Pocket Poets hardcover series is popular for its compact size and reasonable price which does not compromise content. Poems: Bronte contains poems that demonstrate a sensibility elemental in its force with an imaginative discipline and flexibility of the highest order. Also included are an Editor's Note and an index of first lines.",
|
|
||||||
"author": { "ID": 101 },
|
|
||||||
"genre": { "ID": "12aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" },
|
|
||||||
"stock": 5,
|
|
||||||
"price": "12.05",
|
|
||||||
"currency": { "code": "USD" }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
### ------------------------------------------------------------------------
|
|
||||||
# Put image to books
|
|
||||||
PUT {{server}}/admin/Books(2)/image
|
|
||||||
Content-Type: image/png
|
|
||||||
Authorization: Basic alice:
|
|
||||||
|
|
||||||
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANwAAADcCAYAAAAbWs+BAAAGwElEQVR4Ae3cwZFbNxBFUY5rkrDTmKAUk5QT03Aa44U22KC7NHptw+DRikVAXf8fzC3u8Hj4R4AAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAgZzAW26USQT+e4HPx+Mz+RRvj0e0kT+SD2cWAQK1gOBqH6sEogKCi3IaRqAWEFztY5VAVEBwUU7DCNQCgqt9rBKICgguymkYgVpAcLWPVQJRAcFFOQ0jUAsIrvaxSiAqILgop2EEagHB1T5WCUQFBBflNIxALSC42scqgaiA4KKchhGoBQRX+1glEBUQXJTTMAK1gOBqH6sEogKCi3IaRqAWeK+Xb1z9iN558fHxcSPS9p2ezx/ROz4e4TtIHt+3j/61hW9f+2+7/+UXbifjewIDAoIbQDWSwE5AcDsZ3xMYEBDcAKqRBHYCgtvJ+J7AgIDgBlCNJLATENxOxvcEBgQEN4BqJIGdgOB2Mr4nMCAguAFUIwnsBAS3k/E9gQEBwQ2gGklgJyC4nYzvCQwICG4A1UgCOwHB7WR8T2BAQHADqEYS2AkIbifjewIDAoIbQDWSwE5AcDsZ3xMYEEjfTzHwiK91B8npd6Q8n8/oGQ/ckRJ9vvQwv3BpUfMIFAKCK3AsEUgLCC4tah6BQkBwBY4lAmkBwaVFzSNQCAiuwLFEIC0guLSoeQQKAcEVOJYIpAUElxY1j0AhILgCxxKBtIDg0qLmESgEBFfgWCKQFhBcWtQ8AoWA4AocSwTSAoJLi5pHoBAQXIFjiUBaQHBpUfMIFAKCK3AsEUgLCC4tah6BQmDgTpPsHSTFs39p6fQ7Q770UsV/Ov19X+2OFL9wxR+rJQJpAcGlRc0jUAgIrsCxRCAtILi0qHkECgHBFTiWCKQFBJcWNY9AISC4AscSgbSA4NKi5hEoBARX4FgikBYQXFrUPAKFgOAKHEsE0gKCS4uaR6AQEFyBY4lAWkBwaVHzCBQCgitwLBFICwguLWoegUJAcAWOJQJpAcGlRc0jUAgIrsCxRCAt8J4eePq89B0ar3ZnyOnve/rfn1+400/I810lILirjtPLnC4guNNPyPNdJSC4q47Ty5wuILjTT8jzXSUguKuO08ucLiC400/I810lILirjtPLnC4guNNPyPNdJSC4q47Ty5wuILjTT8jzXSUguKuO08ucLiC400/I810lILirjtPLnC4guNNPyPNdJSC4q47Ty5wuILjTT8jzXSUguKuO08ucLiC400/I810l8JZ/m78+szP/zI47fJo7Q37vgJ7PHwN/07/3TOv/9gu3avhMYFhAcMPAxhNYBQS3avhMYFhAcMPAxhNYBQS3avhMYFhAcMPAxhNYBQS3avhMYFhAcMPAxhNYBQS3avhMYFhAcMPAxhNYBQS3avhMYFhAcMPAxhNYBQS3avhMYFhAcMPAxhNYBQS3avhMYFhAcMPAxhNYBQS3avhMYFhAcMPAxhNYBQS3avhMYFhg4P6H9J0maYHXuiMlrXf+vOfA33Turf3C5SxNItAKCK4lsoFATkBwOUuTCLQCgmuJbCCQExBcztIkAq2A4FoiGwjkBASXszSJQCsguJbIBgI5AcHlLE0i0AoIriWygUBOQHA5S5MItAKCa4lsIJATEFzO0iQCrYDgWiIbCOQEBJezNIlAKyC4lsgGAjkBweUsTSLQCgiuJbKBQE5AcDlLkwi0Akff//Dz6U+/I6U1/sUNr3bnytl3kPzi4bXb/cK1RDYQyAkILmdpEoFWQHAtkQ0EcgKCy1maRKAVEFxLZAOBnIDgcpYmEWgFBNcS2UAgJyC4nKVJBFoBwbVENhDICQguZ2kSgVZAcC2RDQRyAoLLWZpEoBUQXEtkA4GcgOByliYRaAUE1xLZQCAnILicpUkEWgHBtUQ2EMgJCC5naRKBVkBwLZENBHIC/4M7TXIv+3PS22d24qvdQfL3C/7N5P5i/MLlLE0i0AoIriWygUBOQHA5S5MItAKCa4lsIJATEFzO0iQCrYDgWiIbCOQEBJezNIlAKyC4lsgGAjkBweUsTSLQCgiuJbKBQE5AcDlLkwi0AoJriWwgkBMQXM7SJAKtgOBaIhsI5AQEl7M0iUArILiWyAYCOQHB5SxNItAKCK4lsoFATkBwOUuTCBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIDAvyrwDySEJ2VQgUSoAAAAAElFTkSuQmCC
|
|
||||||
|
|
||||||
|
|
||||||
### ------------------------------------------------------------------------
|
|
||||||
# Reading image from from the server directly
|
|
||||||
GET {{server}}/browse/Books(2)/image
|
|
||||||
|
|
||||||
|
|
||||||
### ------------------------------------------------------------------------
|
|
||||||
# Submit Order as authenticated user
|
|
||||||
# (send that three times to get out-of-stock message)
|
|
||||||
POST {{server}}/browse/submitOrder
|
|
||||||
Content-Type: application/json
|
|
||||||
{{me}}
|
|
||||||
|
|
||||||
{ "book":201, "quantity":5 }
|
|
||||||
|
|
||||||
|
|
||||||
### ------------------------------------------------------------------------
|
|
||||||
# Browse Genres
|
|
||||||
GET {{server}}/browse/Genres?
|
|
||||||
# &$filter=parent_ID eq null&$select=name
|
|
||||||
# &$expand=children($select=name)
|
|
||||||
{{me}}
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
const cds = require('@sap/cds/lib')
|
|
||||||
const { GET, expect, axios } = cds.test(__dirname)
|
|
||||||
|
|
||||||
// Fetch API disallows GET|HEAD requests with body
|
|
||||||
if (axios.constructor.name === 'Naxios') it = it.skip
|
|
||||||
|
|
||||||
describe ('GET w/ query in body', () => {
|
|
||||||
|
|
||||||
it ('serves CQN query objects in body', async () => {
|
|
||||||
const {data:books} = await GET ('/hcql/admin', {
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
data: cds.ql `SELECT from Books`
|
|
||||||
})
|
|
||||||
expect(books).to.be.an('array').of.length(5)
|
|
||||||
})
|
|
||||||
|
|
||||||
it ('serves plain CQL strings in body', async () => {
|
|
||||||
const {data:books} = await GET ('/hcql/admin', {
|
|
||||||
headers: { 'Content-Type': 'text/plain' },
|
|
||||||
data: `SELECT from Books`
|
|
||||||
})
|
|
||||||
expect(books).to.be.an('array').of.length(5)
|
|
||||||
})
|
|
||||||
|
|
||||||
it ('serves complex and deep queries', async () => {
|
|
||||||
const {data:books} = await GET ('/hcql/admin', {
|
|
||||||
headers: { 'Content-Type': 'text/plain' },
|
|
||||||
data: `SELECT from Authors {
|
|
||||||
name,
|
|
||||||
books [order by title] {
|
|
||||||
title,
|
|
||||||
genre.name as genre
|
|
||||||
}
|
|
||||||
}`
|
|
||||||
})
|
|
||||||
expect(books).to.deep.equal([
|
|
||||||
{
|
|
||||||
name: "Emily Brontë",
|
|
||||||
books: [
|
|
||||||
{ title: "Wuthering Heights", genre: 'Drama' }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Charlotte Brontë",
|
|
||||||
books: [
|
|
||||||
{ title: "Jane Eyre", genre: 'Drama' }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Edgar Allen Poe",
|
|
||||||
books: [
|
|
||||||
{ title: "Eleonora", genre: 'Romance' },
|
|
||||||
{ title: "The Raven", genre: 'Mystery' },
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Richard Carpenter",
|
|
||||||
books: [
|
|
||||||
{ title: "Catweazle", genre: 'Fantasy' }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
describe ('Sluggified variants', () => {
|
|
||||||
|
|
||||||
test ('GET /Books', async () => {
|
|
||||||
const {data:books} = await GET ('/hcql/admin/Books')
|
|
||||||
expect(books).to.be.an('array').of.length(5)
|
|
||||||
expect(books.length).to.eql(5) //.of.length(5)
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
test ('GET /Books/201', async () => {
|
|
||||||
const {data:book} = await GET ('/hcql/admin/Books/201')
|
|
||||||
expect(book).to.be.an('object')
|
|
||||||
expect(book).to.have.property ('title', "Wuthering Heights")
|
|
||||||
})
|
|
||||||
|
|
||||||
test ('GET /Books { title, author.name as author }' , async () => {
|
|
||||||
const {data:books} = await GET ('/hcql/admin/Books { title, author.name as author } order by ID')
|
|
||||||
expect(books).to.deep.equal ([
|
|
||||||
{ title: "Wuthering Heights", author: "Emily Brontë" },
|
|
||||||
{ title: "Jane Eyre", author: "Charlotte Brontë" },
|
|
||||||
{ title: "The Raven", author: "Edgar Allen Poe" },
|
|
||||||
{ title: "Eleonora", author: "Edgar Allen Poe" },
|
|
||||||
{ title: "Catweazle", author: "Richard Carpenter" }
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
test ('GET /Books/201 w/ CQL tail in URL' , async () => {
|
|
||||||
const {data:book} = await GET ('/hcql/admin/Books/201 { title, author.name as author } order by ID')
|
|
||||||
expect(book).to.deep.equal ({ title: "Wuthering Heights", author: "Emily Brontë" })
|
|
||||||
})
|
|
||||||
|
|
||||||
it ('GET /Books/201 w/ CQL fragment in body' , async () => {
|
|
||||||
const {data:book} = await GET ('/hcql/admin/Books/201', {
|
|
||||||
headers: { 'Content-Type': 'text/plain' },
|
|
||||||
data: `{ title, author.name as author }`
|
|
||||||
})
|
|
||||||
expect(book).to.deep.equal ({ title: "Wuthering Heights", author: "Emily Brontë" })
|
|
||||||
})
|
|
||||||
|
|
||||||
it ('GET /Books/201 w/ CQN fragment in body' , async () => {
|
|
||||||
const {data:book} = await GET ('/hcql/admin/Books/201', {
|
|
||||||
data: cds.ql `SELECT title, author.name as author` .SELECT
|
|
||||||
})
|
|
||||||
expect(book).to.deep.equal ({ title: "Wuthering Heights", author: "Emily Brontë" })
|
|
||||||
})
|
|
||||||
|
|
||||||
it ('GET /Books/201 w/ tail in URL plus CQL/CQN fragments in body' , async () => {
|
|
||||||
const {data:[b1]} = await GET ('/hcql/admin/Books where ID=201', {
|
|
||||||
data: cds.ql `SELECT title, author.name as author` .SELECT
|
|
||||||
})
|
|
||||||
expect(b1).to.deep.equal ({ title: "Wuthering Heights", author: "Emily Brontë" })
|
|
||||||
const {data:[b2]} = await GET ('/hcql/admin/Books where ID=201', {
|
|
||||||
headers: { 'Content-Type': 'text/plain' },
|
|
||||||
data: `{ title, author.name as author }`
|
|
||||||
})
|
|
||||||
expect(b2).to.deep.equal ({ title: "Wuthering Heights", author: "Emily Brontë" })
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
|
||||||
@@ -1,225 +0,0 @@
|
|||||||
@server = http://localhost:4004
|
|
||||||
|
|
||||||
GET {{server}}/odata/v4/admin/Authors?
|
|
||||||
&$select=ID,name
|
|
||||||
&$expand=books($select=ID,title)
|
|
||||||
&$count=true
|
|
||||||
###
|
|
||||||
|
|
||||||
#
|
|
||||||
# The basic variant expects a CQN object passed as an application/json body
|
|
||||||
# to a POST request. This is also the fastest one, as it doesn't need CQL parsing.
|
|
||||||
# Note: $count is returned in X-Total-Count response header
|
|
||||||
#
|
|
||||||
GET {{server}}/hcql/admin
|
|
||||||
Content-Type: application/json
|
|
||||||
# Accept-Language: de
|
|
||||||
|
|
||||||
{ "SELECT": {
|
|
||||||
"from": { "ref": [ "Authors" ] },
|
|
||||||
"columns": [
|
|
||||||
{ "ref": [ "name" ] },
|
|
||||||
{ "ref": [ "books" ], "expand": [
|
|
||||||
{ "ref": [ "ID" ] },
|
|
||||||
{ "ref": [ "title" ] }
|
|
||||||
]}
|
|
||||||
],
|
|
||||||
"count": true
|
|
||||||
}}
|
|
||||||
###
|
|
||||||
|
|
||||||
POST {{server}}/hcql/browse/submitOrder?book=201&quantity=2
|
|
||||||
Authorization: Basic alice:
|
|
||||||
###
|
|
||||||
|
|
||||||
POST {{server}}/hcql/browse/submitOrder
|
|
||||||
Authorization: Basic alice:
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"book": 201,
|
|
||||||
"quantity": 2
|
|
||||||
}
|
|
||||||
###
|
|
||||||
|
|
||||||
GET {{server}}/hcql/browse/submitOrder?book=201&quantity=2
|
|
||||||
Authorization: Basic alice:
|
|
||||||
###
|
|
||||||
|
|
||||||
#
|
|
||||||
# Alternatively you can pass a CQL string as plain/text body
|
|
||||||
#
|
|
||||||
GET {{server}}/hcql/admin
|
|
||||||
Content-Type: text/plain
|
|
||||||
# X-Total-Count: true
|
|
||||||
|
|
||||||
SELECT from Authors { name, books { title }}
|
|
||||||
# SELECT from Books { title, currency }
|
|
||||||
###
|
|
||||||
|
|
||||||
#
|
|
||||||
# In addition we offer convenience slug routes...
|
|
||||||
# .e.g. /srv/entity routes
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
GET {{server}}/hcql/admin/Books
|
|
||||||
###
|
|
||||||
|
|
||||||
GET {{server}}/hcql/admin/Books/201
|
|
||||||
###
|
|
||||||
|
|
||||||
GET {{server}}/hcql/admin/Books { ID, title, author.name as author }
|
|
||||||
###
|
|
||||||
|
|
||||||
GET {{server}}/hcql/admin/Books order by stock desc
|
|
||||||
Content-Type: text/plain
|
|
||||||
|
|
||||||
{ title, stock }
|
|
||||||
###
|
|
||||||
|
|
||||||
GET {{server}}/hcql/admin/Books/201 { ID, title, author.name }
|
|
||||||
###
|
|
||||||
|
|
||||||
GET {{server}}/hcql/admin/Books/201 { ID, title, author{name} }
|
|
||||||
###
|
|
||||||
|
|
||||||
|
|
||||||
POST {{server}}/hcql/admin/Books?title=The Black Cat&author_ID=101
|
|
||||||
###
|
|
||||||
|
|
||||||
|
|
||||||
POST {{server}}/hcql/admin/Books?title=The Black Cat
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"author_ID": 101
|
|
||||||
}
|
|
||||||
###
|
|
||||||
|
|
||||||
POST {{server}}/hcql/admin/Books
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"title": "The Black Cat",
|
|
||||||
"author": { "ID": 101 }
|
|
||||||
}
|
|
||||||
###
|
|
||||||
|
|
||||||
PUT {{server}}/hcql/admin/Books/275?title=Catastrophe
|
|
||||||
###
|
|
||||||
|
|
||||||
PATCH {{server}}/hcql/admin/Books/275
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"title": "Catastrophe"
|
|
||||||
}
|
|
||||||
###
|
|
||||||
|
|
||||||
GET {{server}}/hcql/admin/Authors { name, books { ID, title }}
|
|
||||||
###
|
|
||||||
|
|
||||||
GET {{server}}/hcql/admin/Books { ID, title, author.name as author } order by ID desc
|
|
||||||
###
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------
|
|
||||||
|
|
||||||
POST {{server}}/hcql/admin
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{"SELECT": { "from": { "ref": ["Books"] }}}
|
|
||||||
###
|
|
||||||
|
|
||||||
POST {{server}}/hcql/admin
|
|
||||||
Content-Type: text/plain
|
|
||||||
|
|
||||||
SELECT from Authors {
|
|
||||||
name as author,
|
|
||||||
books {
|
|
||||||
title,
|
|
||||||
stock,
|
|
||||||
price,
|
|
||||||
currency { * }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
where name like '%Bro%'
|
|
||||||
order by name asc
|
|
||||||
###
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Simple REST-style URLs as supported as well
|
|
||||||
#
|
|
||||||
|
|
||||||
GET {{server}}/hcql/admin/Books
|
|
||||||
###
|
|
||||||
|
|
||||||
GET {{server}}/hcql/admin/Books/201
|
|
||||||
###
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# REST-style URLs can be combined with trailing CQL in the path, in plain
|
|
||||||
# text body, or with projections sent as application/json array
|
|
||||||
#
|
|
||||||
|
|
||||||
GET {{server}}/hcql/admin/Books order by stock desc
|
|
||||||
###
|
|
||||||
|
|
||||||
GET {{server}}/hcql/admin/Books { title as book, stock } order by stock desc
|
|
||||||
###
|
|
||||||
|
|
||||||
GET {{server}}/hcql/admin/Authors
|
|
||||||
Content-Type: text/plain
|
|
||||||
Accept-Language: fr
|
|
||||||
|
|
||||||
{
|
|
||||||
ID, name as author,
|
|
||||||
books {
|
|
||||||
title,
|
|
||||||
stock,
|
|
||||||
currency { * }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
where name like '%Bro%'
|
|
||||||
order by name asc
|
|
||||||
###
|
|
||||||
|
|
||||||
|
|
||||||
GET {{server}}/hcql/admin/Books/201 { title, stock }
|
|
||||||
###
|
|
||||||
|
|
||||||
GET {{server}}/hcql/admin/Books order by stock desc
|
|
||||||
Content-Type: text/plain
|
|
||||||
|
|
||||||
{ title, stock }
|
|
||||||
###
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# CQL adaptor also provides access to the underlying CSN schema
|
|
||||||
#
|
|
||||||
|
|
||||||
GET {{server}}/hcql/admin/$csn
|
|
||||||
###
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# CQL adaptor also supports INSERTs, UPDATEs, DELETEs ...
|
|
||||||
#
|
|
||||||
|
|
||||||
POST {{server}}/hcql/admin
|
|
||||||
Content-Type: application/jsonin wonderland
|
|
||||||
|
|
||||||
{ "INSERT": {
|
|
||||||
"into": "Books",
|
|
||||||
"entries": [{
|
|
||||||
"title": "The Black Cat",
|
|
||||||
"author": { "ID": 150 }
|
|
||||||
}]
|
|
||||||
}}
|
|
||||||
###
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
@server = http://localhost:4004
|
|
||||||
|
|
||||||
GET {{server}}/odata/v2/admin/Authors
|
|
||||||
Authorization: Basic alice:
|
|
||||||
###
|
|
||||||
|
|
||||||
GET {{server}}/odata/v2/admin/Authors?$select=ID,name&$expand=books($select=ID,title)
|
|
||||||
Authorization: Basic alice:
|
|
||||||
###
|
|
||||||
|
|
||||||
GET {{server}}/odata/v4/admin/Authors
|
|
||||||
Authorization: Basic alice:
|
|
||||||
###
|
|
||||||
|
|
||||||
GET {{server}}/odata/v4/admin/Authors?$select=ID,name&$expand=books($select=ID,title)
|
|
||||||
Authorization: Basic alice:
|
|
||||||
###
|
|
||||||
|
|
||||||
|
|
||||||
GET {{server}}/rest/admin/Authors
|
|
||||||
Authorization: Basic alice:
|
|
||||||
###
|
|
||||||
|
|
||||||
GET {{server}}/rest/admin/Authors?$select=ID,name&$expand=books($select=ID,title)
|
|
||||||
Authorization: Basic alice:
|
|
||||||
###
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
@server = http://localhost:4004
|
|
||||||
|
|
||||||
GET {{server}}/rest/admin/Authors
|
|
||||||
Authorization: Basic alice:
|
|
||||||
###
|
|
||||||
|
|
||||||
GET {{server}}/rest/admin/Authors?$select=ID,name&$expand=books($select=ID,title)
|
|
||||||
Authorization: Basic alice:
|
|
||||||
###
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
|
|
||||||
using { CatalogService, AdminService } from '@capire/bookstore';
|
|
||||||
annotate CatalogService with @hcql @odata @path:'browse' @requires:[];
|
|
||||||
annotate AdminService with @hcql @odata @path:'admin';
|
|
||||||
@@ -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
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
AuthorName = Name des Autors
|
|
||||||
Age = Alter
|
|
||||||
rder = Bestellung
|
|
||||||
Orders = Bestellungen
|
|
||||||
Price = Preis
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
Age = Age
|
|
||||||
Lifetime = Lifetime
|
|
||||||
|
|
||||||
SubGenres = Subgenre
|
|
||||||
|
|
||||||
NumCode = Numeric Code
|
|
||||||
MinorUnit = Minor Unit
|
|
||||||
Exponent = Exponent
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
using {AdminService} from '@capire/bookshop';
|
|
||||||
|
|
||||||
annotate AdminService.Authors with @odata.draft.enabled;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Authors Object Page
|
|
||||||
//
|
|
||||||
annotate AdminService.Authors with @(UI : {
|
|
||||||
HeaderInfo : {
|
|
||||||
TypeName : 'Author',
|
|
||||||
TypeNamePlural : 'Authors',
|
|
||||||
Description : {Value : lifetime}
|
|
||||||
},
|
|
||||||
Facets : [
|
|
||||||
{
|
|
||||||
$Type : 'UI.ReferenceFacet',
|
|
||||||
Label : '{i18n>Details}',
|
|
||||||
Target : '@UI.FieldGroup#Details'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$Type : 'UI.ReferenceFacet',
|
|
||||||
Label : '{i18n>Books}',
|
|
||||||
Target : 'books/@UI.LineItem'
|
|
||||||
},
|
|
||||||
],
|
|
||||||
FieldGroup #Details : {Data : [
|
|
||||||
{Value : placeOfBirth},
|
|
||||||
{Value : placeOfDeath},
|
|
||||||
{Value : dateOfBirth},
|
|
||||||
{Value : dateOfDeath},
|
|
||||||
{
|
|
||||||
Value : age,
|
|
||||||
Label : '{i18n>Age}'
|
|
||||||
},
|
|
||||||
]},
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// Workaround to avoid errors for unknown db-specific calculated fields above
|
|
||||||
extend sap.capire.bookshop.Authors with {
|
|
||||||
virtual age : Integer;
|
|
||||||
virtual lifetime : String;
|
|
||||||
}
|
|
||||||
|
|
||||||
annotate AdminService.Authors with {
|
|
||||||
age @Common.Label : '{i18n>Age}';
|
|
||||||
lifetime @Common.Label : '{i18n>Lifetime}'
|
|
||||||
}
|
|
||||||
|
|
||||||
// Workaround for Fiori popup for asking user to enter a new UUID on Create
|
|
||||||
annotate AdminService.Authors with { ID @Core.Computed; }
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
sap.ui.define(["sap/fe/core/AppComponent"], function (AppComponent) {
|
|
||||||
"use strict";
|
|
||||||
return AppComponent.extend("authors.Component", {
|
|
||||||
metadata: { manifest: "json" },
|
|
||||||
});
|
|
||||||
});
|
|
||||||
/* eslint no-undef:0 */
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
# This is the resource bundle of itelo
|
|
||||||
# __ldi.translation.uuid=c3431418-9caf-11e8-98d0-529269fb1459
|
|
||||||
|
|
||||||
# JCI app descriptor contains lower case TITLE
|
|
||||||
appTitle=Manage Authors
|
|
||||||
|
|
||||||
# JCI app descriptor contains lower case DESCRIPTION
|
|
||||||
appSubTitle=CAP Sample Application
|
|
||||||
|
|
||||||
# JCI app descriptor contains lower case DESCRIPTION
|
|
||||||
appDescription=Bookshop Authors
|
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
{
|
|
||||||
"_version": "1.28.0",
|
|
||||||
"sap.app": {
|
|
||||||
"id": "authors",
|
|
||||||
"type": "application",
|
|
||||||
"title": "Manage Authors",
|
|
||||||
"description": "Sample Application",
|
|
||||||
"i18n": "i18n/i18n.properties",
|
|
||||||
"applicationVersion": {
|
|
||||||
"version": "1.0.0"
|
|
||||||
},
|
|
||||||
"dataSources": {
|
|
||||||
"AdminService": {
|
|
||||||
"uri": "admin/",
|
|
||||||
"type": "OData",
|
|
||||||
"settings": {
|
|
||||||
"odataVersion": "4.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"sourceTemplate": {
|
|
||||||
"id": "ui5template.basicSAPUI5ApplicationProject",
|
|
||||||
"-id": "ui5template.smartTemplate",
|
|
||||||
"version": "1.40.12"
|
|
||||||
},
|
|
||||||
"crossNavigation": {
|
|
||||||
"inbounds": {
|
|
||||||
"intent1": {
|
|
||||||
"signature": {
|
|
||||||
"parameters": {
|
|
||||||
"Books.author.ID":{
|
|
||||||
"renameTo": "ID"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"additionalParameters": "ignored"
|
|
||||||
},
|
|
||||||
"semanticObject": "Authors",
|
|
||||||
"action": "manage",
|
|
||||||
"title": "{{appTitle}}",
|
|
||||||
"info": "{{appInfo}}",
|
|
||||||
"subTitle": "{{appSubTitle}}",
|
|
||||||
"icon": "sap-icon://SAP-icons-TNT/user",
|
|
||||||
"indicatorDataSource": {
|
|
||||||
"dataSource": "AdminService",
|
|
||||||
"path": "Authors/$count",
|
|
||||||
"refresh": 1800
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"sap.ui5": {
|
|
||||||
"dependencies": {
|
|
||||||
"minUI5Version": "1.81.0",
|
|
||||||
"libs": {
|
|
||||||
"sap.fe.templates": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"models": {
|
|
||||||
"i18n": {
|
|
||||||
"type": "sap.ui.model.resource.ResourceModel",
|
|
||||||
"uri": "i18n/i18n.properties"
|
|
||||||
},
|
|
||||||
"": {
|
|
||||||
"dataSource": "AdminService",
|
|
||||||
"settings": {
|
|
||||||
"synchronizationMode": "None",
|
|
||||||
"operationMode": "Server",
|
|
||||||
"autoExpandSelect": true,
|
|
||||||
"earlyRequests": true,
|
|
||||||
"groupProperties": {
|
|
||||||
"default": {
|
|
||||||
"submit": "Auto"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"routing": {
|
|
||||||
"routes": [
|
|
||||||
{
|
|
||||||
"pattern": ":?query:",
|
|
||||||
"name": "AuthorsList",
|
|
||||||
"target": "AuthorsList"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"pattern": "Authors({key}):?query:",
|
|
||||||
"name": "AuthorsDetails",
|
|
||||||
"target": "AuthorsDetails"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"targets": {
|
|
||||||
"AuthorsList": {
|
|
||||||
"type": "Component",
|
|
||||||
"id": "AuthorsList",
|
|
||||||
"name": "sap.fe.templates.ListReport",
|
|
||||||
"options": {
|
|
||||||
"settings": {
|
|
||||||
"entitySet": "Authors",
|
|
||||||
"initialLoad": true,
|
|
||||||
"navigation": {
|
|
||||||
"Authors": {
|
|
||||||
"detail": {
|
|
||||||
"route": "AuthorsDetails"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"AuthorsDetails": {
|
|
||||||
"type": "Component",
|
|
||||||
"id": "AuthorsDetailsList",
|
|
||||||
"name": "sap.fe.templates.ObjectPage",
|
|
||||||
"options": {
|
|
||||||
"settings": {
|
|
||||||
"entitySet": "Authors"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"contentDensities": {
|
|
||||||
"compact": true,
|
|
||||||
"cozy": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"sap.ui": {
|
|
||||||
"technology": "UI5",
|
|
||||||
"fullWidth": false,
|
|
||||||
"deviceTypes":{
|
|
||||||
"desktop": true,
|
|
||||||
"tablet": true,
|
|
||||||
"phone": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"sap.fiori": {
|
|
||||||
"registrationIds": [],
|
|
||||||
"archeType": "transactional"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
using { AdminService } from '@capire/bookstore';
|
|
||||||
using from '../common'; // to help UI linter get the complete annotations
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Books Object Page
|
|
||||||
//
|
|
||||||
|
|
||||||
annotate AdminService.Books with @(
|
|
||||||
UI: {
|
|
||||||
Facets: [
|
|
||||||
{$Type: 'UI.ReferenceFacet', Label: '{i18n>General}', Target: '@UI.FieldGroup#General'},
|
|
||||||
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Translations}', Target: 'texts/@UI.LineItem'},
|
|
||||||
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Details}', Target: '@UI.FieldGroup#Details'},
|
|
||||||
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Admin}', Target: '@UI.FieldGroup#Admin'},
|
|
||||||
],
|
|
||||||
FieldGroup#General: {
|
|
||||||
Data: [
|
|
||||||
{Value: title},
|
|
||||||
{Value: author_ID},
|
|
||||||
{Value: genre_ID},
|
|
||||||
{Value: descr},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
FieldGroup#Details: {
|
|
||||||
Data: [
|
|
||||||
{Value: stock},
|
|
||||||
{Value: price},
|
|
||||||
{Value: currency_code, Label: '{i18n>Currency}'},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
FieldGroup#Admin: {
|
|
||||||
Data: [
|
|
||||||
{Value: createdBy},
|
|
||||||
{Value: createdAt},
|
|
||||||
{Value: modifiedBy},
|
|
||||||
{Value: modifiedAt}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Value Help for Tree Table
|
|
||||||
//
|
|
||||||
annotate AdminService.Books with {
|
|
||||||
genre @(Common: {
|
|
||||||
Label : 'Genre',
|
|
||||||
ValueList: {
|
|
||||||
CollectionPath : 'Genres',
|
|
||||||
Parameters : [
|
|
||||||
{
|
|
||||||
$Type : 'Common.ValueListParameterDisplayOnly',
|
|
||||||
ValueListProperty: 'name',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$Type : 'Common.ValueListParameterInOut',
|
|
||||||
LocalDataProperty: genre_ID,
|
|
||||||
ValueListProperty: 'ID',
|
|
||||||
}
|
|
||||||
],
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hide ID because of the ValueHelp
|
|
||||||
annotate AdminService.Genres with {
|
|
||||||
ID @UI.Hidden;
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Draft for Localized Data
|
|
||||||
//
|
|
||||||
|
|
||||||
annotate sap.capire.bookshop.Books with @fiori.draft.enabled;
|
|
||||||
annotate AdminService.Books with @odata.draft.enabled;
|
|
||||||
|
|
||||||
annotate AdminService.Books.texts with @(
|
|
||||||
UI: {
|
|
||||||
Identification: [{Value:title}],
|
|
||||||
SelectionFields: [ locale, title ],
|
|
||||||
LineItem: [
|
|
||||||
{Value: locale, Label: 'Locale'},
|
|
||||||
{Value: title, Label: 'Title'},
|
|
||||||
{Value: descr, Label: 'Description'},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
annotate AdminService.Books.texts with {
|
|
||||||
ID @UI.Hidden;
|
|
||||||
ID_texts @UI.Hidden;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Add Value Help for Locales
|
|
||||||
annotate AdminService.Books.texts {
|
|
||||||
locale @(
|
|
||||||
ValueList.entity:'Languages', Common.ValueListWithFixedValues, //show as drop down, not a dialog
|
|
||||||
)
|
|
||||||
}
|
|
||||||
// In addition we need to expose Languages through AdminService as a target for ValueList
|
|
||||||
using { sap } from '@sap/cds/common';
|
|
||||||
extend service AdminService {
|
|
||||||
@readonly entity Languages as projection on sap.common.Languages;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Workaround for Fiori popup for asking user to enter a new UUID on Create
|
|
||||||
annotate AdminService.Books with { ID @Core.Computed; }
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
sap.ui.define(["sap/fe/core/AppComponent"], function(AppComponent) {
|
|
||||||
"use strict";
|
|
||||||
return AppComponent.extend("books.Component", {
|
|
||||||
metadata: { manifest: "json" }
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
/* eslint no-undef:0 */
|
|
||||||
@@ -1,167 +0,0 @@
|
|||||||
{
|
|
||||||
"services": {
|
|
||||||
"LaunchPage": {
|
|
||||||
"adapter": {
|
|
||||||
"config": {
|
|
||||||
"groups": [
|
|
||||||
{
|
|
||||||
"id": "Bookshop",
|
|
||||||
"title": "Bookshop",
|
|
||||||
"isPreset": true,
|
|
||||||
"isVisible": true,
|
|
||||||
"isGroupLocked": false,
|
|
||||||
"tiles": [
|
|
||||||
{
|
|
||||||
"id": "BrowseBooks",
|
|
||||||
"tileType": "sap.ushell.ui.tile.StaticTile",
|
|
||||||
"properties": {
|
|
||||||
"title": "Browse Books",
|
|
||||||
"targetURL": "#Books-display"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "BrowseGenres",
|
|
||||||
"tileType": "sap.ushell.ui.tile.StaticTile",
|
|
||||||
"properties": {
|
|
||||||
"title": "Browse Genres",
|
|
||||||
"targetURL": "#Genres-display"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "Administration",
|
|
||||||
"title": "Administration",
|
|
||||||
"isPreset": true,
|
|
||||||
"isVisible": true,
|
|
||||||
"isGroupLocked": false,
|
|
||||||
"tiles": [
|
|
||||||
{
|
|
||||||
"id": "ManageBooks",
|
|
||||||
"tileType": "sap.ushell.ui.tile.StaticTile",
|
|
||||||
"properties": {
|
|
||||||
"title": "Manage Books",
|
|
||||||
"targetURL": "#Books-manage"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "ManageAuthors",
|
|
||||||
"tileType": "sap.ushell.ui.tile.StaticTile",
|
|
||||||
"properties": {
|
|
||||||
"title": "Manage Authors",
|
|
||||||
"targetURL": "#Authors-manage"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "ManageOrders",
|
|
||||||
"tileType": "sap.ushell.ui.tile.StaticTile",
|
|
||||||
"properties": {
|
|
||||||
"title": "Manage Orders",
|
|
||||||
"targetURL": "#Orders-manage"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"NavTargetResolution": {
|
|
||||||
"config": {
|
|
||||||
"enableClientSideTargetResolution": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"ClientSideTargetResolution": {
|
|
||||||
"adapter": {
|
|
||||||
"config": {
|
|
||||||
"inbounds": {
|
|
||||||
"BrowseBooks": {
|
|
||||||
"semanticObject": "Books",
|
|
||||||
"action": "display",
|
|
||||||
"title": "Browse Books",
|
|
||||||
"signature": {
|
|
||||||
"parameters": {
|
|
||||||
"Books.ID": {
|
|
||||||
"renameTo": "ID"
|
|
||||||
},
|
|
||||||
"Authors.books.ID": {
|
|
||||||
"renameTo": "ID"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"additionalParameters": "ignored"
|
|
||||||
},
|
|
||||||
"resolutionResult": {
|
|
||||||
"applicationType": "SAPUI5",
|
|
||||||
"additionalInformation": "SAPUI5.Component=bookshop",
|
|
||||||
"url": "/browse/webapp"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"BrowseAuthors": {
|
|
||||||
"semanticObject": "Authors",
|
|
||||||
"action": "manage",
|
|
||||||
"title": "Browse Authors",
|
|
||||||
"signature": {
|
|
||||||
"parameters": {
|
|
||||||
"Books.author.ID":{
|
|
||||||
"renameTo": "ID"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"additionalParameters": "ignored"
|
|
||||||
},
|
|
||||||
"resolutionResult": {
|
|
||||||
"applicationType": "SAPUI5",
|
|
||||||
"additionalInformation": "SAPUI5.Component=authors",
|
|
||||||
"url": "/admin-authors/webapp"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"BrowseGenres": {
|
|
||||||
"semanticObject": "Genres",
|
|
||||||
"action": "display",
|
|
||||||
"title": "Browse Genres",
|
|
||||||
"signature": {
|
|
||||||
"parameters": {
|
|
||||||
"Genre.ID": {
|
|
||||||
"renameTo": "ID"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"additionalParameters": "ignored"
|
|
||||||
},
|
|
||||||
"resolutionResult": {
|
|
||||||
"applicationType": "SAPUI5",
|
|
||||||
"additionalInformation": "SAPUI5.Component=genres",
|
|
||||||
"url": "/genres/webapp"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"ManageBooks": {
|
|
||||||
"semanticObject": "Books",
|
|
||||||
"action": "manage",
|
|
||||||
"title": "Manage Books",
|
|
||||||
"signature": {
|
|
||||||
"parameters": {},
|
|
||||||
"additionalParameters": "allowed"
|
|
||||||
},
|
|
||||||
"resolutionResult": {
|
|
||||||
"applicationType": "SAPUI5",
|
|
||||||
"additionalInformation": "SAPUI5.Component=books",
|
|
||||||
"url": "/admin-books/webapp"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"ManageOrders": {
|
|
||||||
"semanticObject": "Orders",
|
|
||||||
"action": "manage",
|
|
||||||
"signature": {
|
|
||||||
"parameters": {},
|
|
||||||
"additionalParameters": "allowed"
|
|
||||||
},
|
|
||||||
"resolutionResult": {
|
|
||||||
"applicationType": "SAPUI5",
|
|
||||||
"additionalInformation": "SAPUI5.Component=orders",
|
|
||||||
"url": "/orders/webapp"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
using CatalogService from '@capire/bookstore';
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Books Object Page
|
|
||||||
//
|
|
||||||
annotate CatalogService.Books with @(UI : {
|
|
||||||
HeaderInfo : {
|
|
||||||
TypeName : '{i18n>Book}',
|
|
||||||
TypeNamePlural : '{i18n>Books}',
|
|
||||||
Description : {Value : author}
|
|
||||||
},
|
|
||||||
HeaderFacets : [{
|
|
||||||
$Type : 'UI.ReferenceFacet',
|
|
||||||
Label : '{i18n>Description}',
|
|
||||||
Target : '@UI.FieldGroup#Descr'
|
|
||||||
}, ],
|
|
||||||
Facets : [{
|
|
||||||
$Type : 'UI.ReferenceFacet',
|
|
||||||
Label : '{i18n>Details}',
|
|
||||||
Target : '@UI.FieldGroup#Price'
|
|
||||||
}, ],
|
|
||||||
FieldGroup #Descr : {Data : [{Value : descr}, ]},
|
|
||||||
FieldGroup #Price : {Data : [
|
|
||||||
{Value : price},
|
|
||||||
{
|
|
||||||
Value : currency.symbol,
|
|
||||||
Label : '{i18n>Currency}'
|
|
||||||
},
|
|
||||||
]},
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Books List Page
|
|
||||||
//
|
|
||||||
annotate CatalogService.Books with @(UI : {
|
|
||||||
SelectionFields : [
|
|
||||||
ID,
|
|
||||||
price,
|
|
||||||
currency_code
|
|
||||||
],
|
|
||||||
LineItem : [
|
|
||||||
{
|
|
||||||
Value : ID,
|
|
||||||
Label : '{i18n>Title}'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Value : author,
|
|
||||||
Label : '{i18n>Author}'
|
|
||||||
},
|
|
||||||
{Value : genre.name},
|
|
||||||
{Value : price},
|
|
||||||
{Value : currency.symbol},
|
|
||||||
]
|
|
||||||
}, );
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
sap.ui.define(["sap/fe/core/AppComponent"], function(AppComponent) {
|
|
||||||
"use strict";
|
|
||||||
return AppComponent.extend("bookshop.Component", {
|
|
||||||
metadata: { manifest: "json" }
|
|
||||||
});
|
|
||||||
});
|
|
||||||
/* eslint no-undef:0 */
|
|
||||||
@@ -1,233 +0,0 @@
|
|||||||
/*
|
|
||||||
Common Annotations shared by all apps
|
|
||||||
*/
|
|
||||||
|
|
||||||
using { sap.capire.bookshop as my } from '@capire/bookstore';
|
|
||||||
using { sap.common } from '@capire/common';
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Books Lists
|
|
||||||
//
|
|
||||||
annotate my.Books with @(
|
|
||||||
Common.SemanticKey : [ID],
|
|
||||||
UI : {
|
|
||||||
Identification : [{ Value: title }],
|
|
||||||
SelectionFields : [
|
|
||||||
ID,
|
|
||||||
author_ID,
|
|
||||||
price,
|
|
||||||
currency_code
|
|
||||||
],
|
|
||||||
LineItem : [
|
|
||||||
{ Value: ID, Label: '{i18n>Title}' },
|
|
||||||
{ Value: author.ID, Label: '{i18n>Author}' },
|
|
||||||
{ Value: genre.name },
|
|
||||||
{ Value: stock },
|
|
||||||
{ Value: price },
|
|
||||||
{ Value: currency.symbol },
|
|
||||||
]
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
ID @Common: {
|
|
||||||
SemanticObject : 'Books',
|
|
||||||
Text: title,
|
|
||||||
TextArrangement : #TextOnly
|
|
||||||
};
|
|
||||||
author @ValueList.entity : 'Authors';
|
|
||||||
};
|
|
||||||
|
|
||||||
annotate common.Currencies with {
|
|
||||||
symbol @Common.Label : '{i18n>Currency}';
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Books Details
|
|
||||||
//
|
|
||||||
annotate my.Books with @(UI : {HeaderInfo : {
|
|
||||||
TypeName : '{i18n>Book}',
|
|
||||||
TypeNamePlural : '{i18n>Books}',
|
|
||||||
Title : { Value: title },
|
|
||||||
Description : { Value: author.name }
|
|
||||||
}, });
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Books Elements
|
|
||||||
//
|
|
||||||
annotate my.Books with {
|
|
||||||
ID @title: '{i18n>ID}';
|
|
||||||
title @title: '{i18n>Title}';
|
|
||||||
genre @title: '{i18n>Genre}' @Common: { Text: genre.name, TextArrangement: #TextOnly };
|
|
||||||
author @title: '{i18n>Author}' @Common: { Text: author.name, TextArrangement: #TextOnly };
|
|
||||||
price @title: '{i18n>Price}' @Measures.ISOCurrency : currency_code;
|
|
||||||
stock @title: '{i18n>Stock}';
|
|
||||||
descr @title: '{i18n>Description}' @UI.MultiLineText;
|
|
||||||
image @title: '{i18n>Image}';
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Authors List
|
|
||||||
//
|
|
||||||
annotate my.Authors with @(
|
|
||||||
Common.SemanticKey : [ID],
|
|
||||||
UI : {
|
|
||||||
Identification : [{ Value: name}],
|
|
||||||
SelectionFields : [name],
|
|
||||||
LineItem : [
|
|
||||||
{ Value: ID },
|
|
||||||
{ Value: dateOfBirth },
|
|
||||||
{ Value: dateOfDeath },
|
|
||||||
{ Value: placeOfBirth },
|
|
||||||
{ Value: placeOfDeath },
|
|
||||||
],
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
ID @Common: {
|
|
||||||
SemanticObject : 'Authors',
|
|
||||||
Text: name,
|
|
||||||
TextArrangement : #TextOnly,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Author Details
|
|
||||||
//
|
|
||||||
annotate my.Authors with @(UI : {
|
|
||||||
HeaderInfo : {
|
|
||||||
TypeName : '{i18n>Author}',
|
|
||||||
TypeNamePlural : '{i18n>Authors}',
|
|
||||||
Title : { Value: name },
|
|
||||||
Description : { Value: dateOfBirth }
|
|
||||||
},
|
|
||||||
Facets : [{
|
|
||||||
$Type : 'UI.ReferenceFacet',
|
|
||||||
Target : 'books/@UI.LineItem'
|
|
||||||
}, ],
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Authors Elements
|
|
||||||
//
|
|
||||||
annotate my.Authors with {
|
|
||||||
ID @title: '{i18n>ID}';
|
|
||||||
name @title: '{i18n>Name}';
|
|
||||||
dateOfBirth @title: '{i18n>DateOfBirth}';
|
|
||||||
dateOfDeath @title: '{i18n>DateOfDeath}';
|
|
||||||
placeOfBirth @title: '{i18n>PlaceOfBirth}';
|
|
||||||
placeOfDeath @title: '{i18n>PlaceOfDeath}';
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Languages List
|
|
||||||
//
|
|
||||||
annotate common.Languages with @(
|
|
||||||
Common.SemanticKey : [code],
|
|
||||||
Identification : [{ Value: code}],
|
|
||||||
UI : {
|
|
||||||
SelectionFields : [
|
|
||||||
name,
|
|
||||||
descr
|
|
||||||
],
|
|
||||||
LineItem : [
|
|
||||||
{ Value: code },
|
|
||||||
{ Value: name },
|
|
||||||
],
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Language Details
|
|
||||||
//
|
|
||||||
annotate common.Languages with @(UI : {
|
|
||||||
HeaderInfo : {
|
|
||||||
TypeName : '{i18n>Language}',
|
|
||||||
TypeNamePlural : '{i18n>Languages}',
|
|
||||||
Title : { Value: name },
|
|
||||||
Description : { Value: descr }
|
|
||||||
},
|
|
||||||
Facets : [{
|
|
||||||
$Type : 'UI.ReferenceFacet',
|
|
||||||
Label : '{i18n>Details}',
|
|
||||||
Target : '@UI.FieldGroup#Details'
|
|
||||||
}, ],
|
|
||||||
FieldGroup #Details : {Data : [
|
|
||||||
{ Value: code },
|
|
||||||
{ Value: name },
|
|
||||||
{ Value: descr }
|
|
||||||
]},
|
|
||||||
});
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Currencies List
|
|
||||||
//
|
|
||||||
annotate common.Currencies with @(
|
|
||||||
Common.SemanticKey : [code],
|
|
||||||
Identification : [{ Value: code}],
|
|
||||||
UI : {
|
|
||||||
SelectionFields : [
|
|
||||||
name,
|
|
||||||
descr
|
|
||||||
],
|
|
||||||
LineItem : [
|
|
||||||
{ Value: descr },
|
|
||||||
{ Value: symbol },
|
|
||||||
{ Value: code },
|
|
||||||
],
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Currency Details
|
|
||||||
//
|
|
||||||
annotate common.Currencies with @(UI : {
|
|
||||||
HeaderInfo : {
|
|
||||||
TypeName : '{i18n>Currency}',
|
|
||||||
TypeNamePlural : '{i18n>Currencies}',
|
|
||||||
Title : { Value: descr },
|
|
||||||
Description : { Value: code }
|
|
||||||
},
|
|
||||||
Facets : [
|
|
||||||
{
|
|
||||||
$Type : 'UI.ReferenceFacet',
|
|
||||||
Label : '{i18n>Details}',
|
|
||||||
Target : '@UI.FieldGroup#Details'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$Type : 'UI.ReferenceFacet',
|
|
||||||
Label : '{i18n>Extended}',
|
|
||||||
Target : '@UI.FieldGroup#Extended'
|
|
||||||
},
|
|
||||||
],
|
|
||||||
FieldGroup #Details : {Data : [
|
|
||||||
{ Value: name },
|
|
||||||
{ Value: symbol },
|
|
||||||
{ Value: code },
|
|
||||||
{ Value: descr }
|
|
||||||
]},
|
|
||||||
FieldGroup #Extended : {Data : [
|
|
||||||
{ Value: numcode },
|
|
||||||
{ Value: minor },
|
|
||||||
{ Value: exponent }
|
|
||||||
]},
|
|
||||||
});
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Currencies Elements
|
|
||||||
//
|
|
||||||
annotate common.Currencies with {
|
|
||||||
numcode @title: '{i18n>NumCode}';
|
|
||||||
minor @title: '{i18n>MinorUnit}';
|
|
||||||
exponent @title: '{i18n>Exponent}';
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
||||||
<title>Bookshop</title>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
window["sap-ushell-config"] = {
|
|
||||||
defaultRenderer: "fiori2",
|
|
||||||
applications: {},
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script id="sap-ushell-bootstrap" src="https://ui5.sap.com/test-resources/sap/ushell/bootstrap/sandbox.js"></script>
|
|
||||||
<script id="sap-ui-bootstrap" src="https://ui5.sap.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-theme="sap_horizon"></script>
|
|
||||||
<script>
|
|
||||||
sap.ui.getCore().attachInit(() =>
|
|
||||||
sap.ushell.Container.createRenderer().placeAt("content")
|
|
||||||
);
|
|
||||||
</script>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body class="sapUiBody" id="content">
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
using { sap.capire.bookshop.Genres } from '@capire/bookstore';
|
|
||||||
|
|
||||||
annotate Genres with @cds.search: {name};
|
|
||||||
annotate Genres with @readonly;
|
|
||||||
annotate Genres with {
|
|
||||||
name @title: '{i18n>Genre}';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lists
|
|
||||||
annotate Genres with @(
|
|
||||||
Common.SemanticKey : [name],
|
|
||||||
UI.SelectionFields : [name],
|
|
||||||
UI.LineItem : [
|
|
||||||
{ Value: name, Label: '{i18n>Name}' },
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
// Details
|
|
||||||
annotate Genres with @(UI : {
|
|
||||||
Identification : [{ Value: name }],
|
|
||||||
HeaderInfo : {
|
|
||||||
TypeName : '{i18n>Genre}',
|
|
||||||
TypeNamePlural : '{i18n>Genres}',
|
|
||||||
Title : { Value: name },
|
|
||||||
Description : { Value: ID }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// Tree Views
|
|
||||||
// annotate AdminService.Genres with @hierarchy; // upcomming simplification
|
|
||||||
using from './tree-view';
|
|
||||||
using from './value-help';
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
using { AdminService } from '@capire/bookstore';
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Genres Tree View
|
|
||||||
//
|
|
||||||
|
|
||||||
// Tell Fiori about the structure of the hierarchy
|
|
||||||
annotate AdminService.Genres with @Aggregation.RecursiveHierarchy #GenresHierarchy : {
|
|
||||||
ParentNavigationProperty : parent, // navigates to a node's parent
|
|
||||||
NodeProperty : ID, // identifies a node, usually the key
|
|
||||||
};
|
|
||||||
|
|
||||||
// Fiori expects the following to be defined explicitly, even though they're always the same
|
|
||||||
extend AdminService.Genres with @(
|
|
||||||
// The columns expected by Fiori to be present in hierarchy entities
|
|
||||||
Hierarchy.RecursiveHierarchy #GenresHierarchy : {
|
|
||||||
LimitedDescendantCount : LimitedDescendantCount,
|
|
||||||
DistanceFromRoot : DistanceFromRoot,
|
|
||||||
DrillState : DrillState,
|
|
||||||
LimitedRank : LimitedRank
|
|
||||||
},
|
|
||||||
// Disallow filtering on these properties from Fiori UIs
|
|
||||||
Capabilities.FilterRestrictions.NonFilterableProperties: [
|
|
||||||
'LimitedDescendantCount',
|
|
||||||
'DistanceFromRoot',
|
|
||||||
'DrillState',
|
|
||||||
'LimitedRank'
|
|
||||||
],
|
|
||||||
// Disallow sorting on these properties from Fiori UIs
|
|
||||||
Capabilities.SortRestrictions.NonSortableProperties : [
|
|
||||||
'LimitedDescendantCount',
|
|
||||||
'DistanceFromRoot',
|
|
||||||
'DrillState',
|
|
||||||
'LimitedRank'
|
|
||||||
],
|
|
||||||
) columns { // Ensure we can query these fields from database
|
|
||||||
null as LimitedDescendantCount : Int16,
|
|
||||||
null as DistanceFromRoot : Int16,
|
|
||||||
null as DrillState : String,
|
|
||||||
null as LimitedRank : Int16,
|
|
||||||
};
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
// Value help with Tree View
|
|
||||||
using from '../admin-books/fiori-service';
|
|
||||||
annotate AdminService.Books:genre with @Common.ValueList.PresentationVariantQualifier: 'VH';
|
|
||||||
annotate AdminService.Genres with @UI.PresentationVariant #VH: {
|
|
||||||
RecursiveHierarchyQualifier : 'GenresHierarchy',
|
|
||||||
};
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
sap.ui.define(["sap/fe/core/AppComponent"], ac => ac.extend("genres.Component", {
|
|
||||||
metadata:{ manifest:'json' }
|
|
||||||
}))
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
#XTIT
|
|
||||||
appTitle=Browse Genres
|
|
||||||
#XTXT
|
|
||||||
appDescription=Genres as Tree View
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
appTitle=Zeige Genres
|
|
||||||
appDescription=Genres als Baumansicht
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
{
|
|
||||||
"_version": "1.8.0",
|
|
||||||
"sap.app": {
|
|
||||||
"id": "genres",
|
|
||||||
"type": "application",
|
|
||||||
"title": "{{appTitle}}",
|
|
||||||
"description": "{{appDescription}}",
|
|
||||||
"applicationVersion": {
|
|
||||||
"version": "1.0.0"
|
|
||||||
},
|
|
||||||
"dataSources": {
|
|
||||||
"AdminService": {
|
|
||||||
"uri": "admin/",
|
|
||||||
"type": "OData",
|
|
||||||
"settings": {
|
|
||||||
"odataVersion": "4.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"crossNavigation": {
|
|
||||||
"inbounds": {
|
|
||||||
"Genres-display": {
|
|
||||||
"signature": {
|
|
||||||
"parameters": {},
|
|
||||||
"additionalParameters": "allowed"
|
|
||||||
},
|
|
||||||
"semanticObject": "Genres",
|
|
||||||
"action": "display"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"sap.ui5": {
|
|
||||||
"dependencies": {
|
|
||||||
"minUI5Version": "1.122.0",
|
|
||||||
"libs": {
|
|
||||||
"sap.fe.templates": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"models": {
|
|
||||||
"i18n": {
|
|
||||||
"type": "sap.ui.model.resource.ResourceModel",
|
|
||||||
"uri": "i18n/i18n.properties"
|
|
||||||
},
|
|
||||||
"": {
|
|
||||||
"dataSource": "AdminService",
|
|
||||||
"settings": {
|
|
||||||
"synchronizationMode": "None",
|
|
||||||
"operationMode": "Server",
|
|
||||||
"autoExpandSelect": true,
|
|
||||||
"earlyRequests": true,
|
|
||||||
"groupProperties": {
|
|
||||||
"default": {
|
|
||||||
"submit": "Auto"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"routing": {
|
|
||||||
"routes": [
|
|
||||||
{
|
|
||||||
"pattern": ":?query:",
|
|
||||||
"name": "GenresList",
|
|
||||||
"target": "GenresList"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"pattern": "Genres({key}):?query:",
|
|
||||||
"name": "GenresDetails",
|
|
||||||
"target": "GenresDetails"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"targets": {
|
|
||||||
"GenresList": {
|
|
||||||
"type": "Component",
|
|
||||||
"id": "GenresList",
|
|
||||||
"name": "sap.fe.templates.ListReport",
|
|
||||||
"options": {
|
|
||||||
"settings": {
|
|
||||||
"contextPath": "/Genres",
|
|
||||||
"navigation": {
|
|
||||||
"Genres": {
|
|
||||||
"detail": {
|
|
||||||
"route": "GenresDetails"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"controlConfiguration": {
|
|
||||||
"@com.sap.vocabularies.UI.v1.LineItem": {
|
|
||||||
"tableSettings": {
|
|
||||||
"hierarchyQualifier": "GenresHierarchy",
|
|
||||||
"type": "TreeTable"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"GenresDetails": {
|
|
||||||
"type": "Component",
|
|
||||||
"id": "GenresDetails",
|
|
||||||
"name": "sap.fe.templates.ObjectPage",
|
|
||||||
"options": {
|
|
||||||
"settings": {
|
|
||||||
"contextPath": "/Genres"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"contentDensities": {
|
|
||||||
"compact": true,
|
|
||||||
"cozy": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"sap.ui": {
|
|
||||||
"technology": "UI5",
|
|
||||||
"fullWidth": false
|
|
||||||
},
|
|
||||||
"sap.fiori": {
|
|
||||||
"registrationIds": [],
|
|
||||||
"archeType": "transactional"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
/*
|
|
||||||
This model controls what gets served to Fiori frontends...
|
|
||||||
*/
|
|
||||||
|
|
||||||
using from './admin-authors/fiori-service';
|
|
||||||
using from './admin-books/fiori-service';
|
|
||||||
using from './browse/fiori-service';
|
|
||||||
using from './genres/fiori-service';
|
|
||||||
|
|
||||||
using from './common';
|
|
||||||
using from '@capire/bookstore/srv/mashup';
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
//
|
|
||||||
// Add Author.age and .lifetime with a DB-specific function
|
|
||||||
//
|
|
||||||
|
|
||||||
using { AdminService } from '@capire/bookshop';
|
|
||||||
|
|
||||||
extend projection AdminService.Authors with {
|
|
||||||
YEARS_BETWEEN(dateOfBirth, dateOfDeath) as age: Integer,
|
|
||||||
YEAR(dateOfBirth) || ' – ' || YEAR(dateOfDeath) as lifetime : String
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
//
|
|
||||||
// Add Author.age and .lifetime with a DB-specific function
|
|
||||||
//
|
|
||||||
|
|
||||||
using { AdminService } from '@capire/bookshop';
|
|
||||||
|
|
||||||
extend projection AdminService.Authors with {
|
|
||||||
strftime('%Y',dateOfDeath)-strftime('%Y',dateOfBirth) as age: Integer,
|
|
||||||
strftime('%Y',dateOfBirth) || ' – ' || strftime('%Y',dateOfDeath) as lifetime : String
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
namespace sap.capire.bookshop; //> important for reflection
|
|
||||||
using from './srv/mashup';
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@capire/bookstore",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"dependencies": {
|
|
||||||
"@capire/bookshop": "*",
|
|
||||||
"@capire/reviews": "*",
|
|
||||||
"@capire/orders": "*",
|
|
||||||
"@capire/common": "*",
|
|
||||||
"@capire/data-viewer": "*",
|
|
||||||
"@cap-js/hana": ">=1",
|
|
||||||
"@sap-cloud-sdk/http-client": "^4",
|
|
||||||
"@sap-cloud-sdk/resilience": "^4",
|
|
||||||
"@sap/cds": ">=5",
|
|
||||||
"express": "^4.17.1"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@cap-js/sqlite": ">=1"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"start": "cds-serve",
|
|
||||||
"watch": "cds watch"
|
|
||||||
},
|
|
||||||
"cds": {
|
|
||||||
"requires": {
|
|
||||||
"ReviewsService": {
|
|
||||||
"kind": "odata",
|
|
||||||
"model": "@capire/reviews"
|
|
||||||
},
|
|
||||||
"OrdersService": {
|
|
||||||
"kind": "odata",
|
|
||||||
"model": "@capire/orders"
|
|
||||||
},
|
|
||||||
"messaging": true,
|
|
||||||
"db": true,
|
|
||||||
"db-ext": {
|
|
||||||
"[development]": {
|
|
||||||
"model": "db/sqlite"
|
|
||||||
},
|
|
||||||
"[production]": {
|
|
||||||
"model": "db/hana"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"log": { "service": true }
|
|
||||||
},
|
|
||||||
"sapux": [
|
|
||||||
"app/admin-authors",
|
|
||||||
"app/admin-books",
|
|
||||||
"app/browse"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
require('./srv/mashup')
|
|
||||||
require('./srv/trees')
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Enhancing bookshop with Reviews and Orders provided through
|
|
||||||
// respective reuse packages and services
|
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// Extend Books with access to Reviews and average ratings
|
|
||||||
//
|
|
||||||
using { sap.capire.bookshop.Books } from '@capire/bookshop';
|
|
||||||
using { ReviewsService.Reviews } from '@capire/reviews';
|
|
||||||
extend Books with {
|
|
||||||
reviews : Composition of many Reviews on reviews.subject = $self.ID;
|
|
||||||
rating : type of Reviews:rating; // average rating
|
|
||||||
numberOfReviews : Integer @title : '{i18n>NumberOfReviews}';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// Extend Orders with Books as Products
|
|
||||||
//
|
|
||||||
using { sap.capire.orders.Orders } from '@capire/orders';
|
|
||||||
extend Orders:Items with {
|
|
||||||
book : Association to Books on product.ID = book.ID
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure models from all imported packages are loaded
|
|
||||||
using from '@capire/orders/app/fiori';
|
|
||||||
using from '@capire/data-viewer';
|
|
||||||
using from '@capire/common';
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
const cds = require ('@sap/cds')
|
|
||||||
|
|
||||||
|
|
||||||
// Add routes to UIs from imported packages
|
|
||||||
if (!cds.env.production) cds.once ('bootstrap', (app) => {
|
|
||||||
app.serve ('/bookshop') .from ('@capire/bookshop','app/vue')
|
|
||||||
app.serve ('/reviews') .from ('@capire/reviews','app/vue')
|
|
||||||
app.serve ('/orders') .from('@capire/orders','app/orders')
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
// Mashing up bookshop services with required services...
|
|
||||||
cds.once ('served', async ()=>{
|
|
||||||
|
|
||||||
const CatalogService = await cds.connect.to ('CatalogService')
|
|
||||||
const ReviewsService = await cds.connect.to ('ReviewsService')
|
|
||||||
const OrdersService = await cds.connect.to ('OrdersService')
|
|
||||||
const db = await cds.connect.to ('db')
|
|
||||||
|
|
||||||
// reflect entity definitions used below...
|
|
||||||
const { Books } = db.entities ('sap.capire.bookshop')
|
|
||||||
|
|
||||||
//
|
|
||||||
// Delegate requests to read reviews to the ReviewsService
|
|
||||||
// Note: prepend is neccessary to intercept generic default handler
|
|
||||||
//
|
|
||||||
CatalogService.prepend (srv => srv.on ('READ', 'Books/reviews', (req) => {
|
|
||||||
console.debug ('> delegating request to ReviewsService') // eslint-disable-line no-console
|
|
||||||
const [id] = req.params, { columns, limit } = req.query.SELECT
|
|
||||||
return ReviewsService.read ('Reviews',columns).limit(limit).where({subject:String(id)})
|
|
||||||
}))
|
|
||||||
|
|
||||||
//
|
|
||||||
// Create an order with the OrdersService when CatalogService signals a new order
|
|
||||||
//
|
|
||||||
CatalogService.on ('OrderedBook', async (msg) => {
|
|
||||||
const { book, quantity, buyer } = msg.data
|
|
||||||
const { title, price } = await db.read (Books, book, b => { b.title, b.price })
|
|
||||||
return OrdersService.create ('OrdersNoDraft').entries({
|
|
||||||
OrderNo: 'Order at '+ (new Date).toLocaleString(),
|
|
||||||
Items: [{ product:{ID:`${book}`}, title, price, quantity }],
|
|
||||||
buyer, createdBy: buyer
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
//
|
|
||||||
// Update Books' average ratings when ReviewsService signals updated reviews
|
|
||||||
//
|
|
||||||
ReviewsService.on ('reviewed', (msg) => {
|
|
||||||
console.debug ('> received:', msg.event, msg.data) // eslint-disable-line no-console
|
|
||||||
const { subject, count, rating } = msg.data
|
|
||||||
return UPDATE(Books,subject).with({ numberOfReviews:count, rating })
|
|
||||||
})
|
|
||||||
|
|
||||||
//
|
|
||||||
// Reduce stock of ordered books for orders are created from Orders admin UI
|
|
||||||
//
|
|
||||||
OrdersService.on ('OrderChanged', (msg) => {
|
|
||||||
console.debug ('> received:', msg.event, msg.data) // eslint-disable-line no-console
|
|
||||||
const { product, deltaQuantity } = msg.data
|
|
||||||
return UPDATE (Books) .where ('ID =', product)
|
|
||||||
.and ('stock >=', deltaQuantity)
|
|
||||||
.set ('stock -=', deltaQuantity)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
const cds = require('@sap/cds/lib')
|
|
||||||
|
|
||||||
// PoC for simplified Fiori Tree Views
|
|
||||||
cds.on('compile.for.runtime', csn => {
|
|
||||||
for (let each of cds.linked(csn).definitions) {
|
|
||||||
if (each.is_entity && each._service && each['@hierarchy']) _hierarchy (each)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
const _hierarchy = entity => {
|
|
||||||
|
|
||||||
// Add annotations explaining the hierarchy structure to Fiori
|
|
||||||
const Qualifier = entity.name.slice (entity._service.name.length+1) + 'Hierarchy'
|
|
||||||
const parent = _parent4(entity)
|
|
||||||
entity[`@Aggregation.RecursiveHierarchy#${Qualifier}.ParentNavigationProperty`] ??= {'=': parent.name }
|
|
||||||
entity[`@Aggregation.RecursiveHierarchy#${Qualifier}.NodeProperty`] ??= {'=': parent.keys[0].ref[0] }
|
|
||||||
|
|
||||||
// Add expected hierarchy elements to the entity
|
|
||||||
const columns = entity.projection.columns ??= ['*']
|
|
||||||
const elements = entity.elements
|
|
||||||
for (let e of Hierarchy.elements) {
|
|
||||||
entity[`@Hierarchy.RecursiveHierarchy#${Qualifier}.${e.name}`] = {'=': e.name }
|
|
||||||
if (e.name in elements) continue
|
|
||||||
const { name, value, ...rest } = e
|
|
||||||
elements[e.name] = Object.defineProperty ({ __proto__:e, ...rest }, 'parent', { value: entity })
|
|
||||||
columns.push ({ ...value, as: name, cast: { type: e.type } })
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable filter and sort for hierarchy elements
|
|
||||||
entity['@Capabilities.FilterRestrictions.NonFilterableProperties'] =
|
|
||||||
entity['@Capabilities.SortRestrictions.NonSortableProperties'] =
|
|
||||||
Object.keys (Hierarchy.elements)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const _parent4 = entity => {
|
|
||||||
const parent = entity['@hierarchy.parent'] || entity['@hierarchy.via']
|
|
||||||
if (parent) return entity.elements [parent['=']||parent]
|
|
||||||
else for (let e of entity.elements) // use first recursive uplink association
|
|
||||||
if (e.is2one && e._target === entity) return e
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const { Hierarchy } = cds.linked `aspect Hierarchy {
|
|
||||||
LimitedDescendantCount : Int16 = null;
|
|
||||||
DistanceFromRoot : Int16 = null;
|
|
||||||
DrillState : String = null;
|
|
||||||
LimitedRank : Int16 = null;
|
|
||||||
}`.definitions
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
|
|
||||||
@bookshop = http://localhost:4004
|
|
||||||
@reviews-service = {{bookshop}}/reviews
|
|
||||||
# Uncomment this when running a separate reviews service
|
|
||||||
# @reviews-service = http://localhost:4005/reviews
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#################################################
|
|
||||||
#
|
|
||||||
# Reviews Service
|
|
||||||
#
|
|
||||||
|
|
||||||
GET {{reviews-service}}/Reviews
|
|
||||||
Authorization: Basic me:
|
|
||||||
|
|
||||||
###
|
|
||||||
|
|
||||||
POST {{reviews-service}}/Reviews
|
|
||||||
Authorization: Basic me:
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{"subject":"201", "title":"boo", "rating":3 }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#################################################
|
|
||||||
#
|
|
||||||
# Bookshop Services
|
|
||||||
#
|
|
||||||
|
|
||||||
GET {{bookshop}}/browse/Books/201/reviews?
|
|
||||||
&$select=rating,date,title
|
|
||||||
&$top=3
|
|
||||||
|
|
||||||
###
|
|
||||||
|
|
||||||
GET {{bookshop}}/browse/Books(201)?
|
|
||||||
&$select=ID,title,rating
|
|
||||||
&$expand=reviews
|
|
||||||
|
|
||||||
###
|
|
||||||
|
|
||||||
GET {{bookshop}}/browse/Books?
|
|
||||||
&$select=title,author&$expand=currency
|
|
||||||
Accept-Language: de
|
|
||||||
|
|
||||||
#################################################
|
|
||||||
#
|
|
||||||
# Orders Service, incl. draft choreography
|
|
||||||
#
|
|
||||||
@newOrderID = e939604c-ab83-4d4f-bdb6-95fe30b3773e
|
|
||||||
|
|
||||||
GET {{bookshop}}/odata/v4/orders/Orders
|
|
||||||
|
|
||||||
### Create order, still inactive
|
|
||||||
POST {{bookshop}}/odata/v4/orders/Orders
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{"ID": "{{newOrderID}}"}
|
|
||||||
|
|
||||||
### Get inactive order. We have to specify `IsActiveEntity`.
|
|
||||||
GET {{bookshop}}/odata/v4/orders/Orders(ID={{newOrderID}},IsActiveEntity=false)
|
|
||||||
|
|
||||||
### Activate order using `.../<servicename>.draftActivate`
|
|
||||||
POST {{bookshop}}/odata/v4/orders/Orders(ID={{newOrderID}},IsActiveEntity=false)/OrdersService.draftActivate
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
### Get active order
|
|
||||||
GET {{bookshop}}/odata/v4/orders/Orders(ID={{newOrderID}},IsActiveEntity=true)
|
|
||||||
|
|
||||||
### Create author
|
|
||||||
POST {{bookshop}}/admin/Authors
|
|
||||||
Content-Type: application/json
|
|
||||||
Authorization: Basic alice:
|
|
||||||
|
|
||||||
{
|
|
||||||
"ID": 200,
|
|
||||||
"name": "William Shakespeare",
|
|
||||||
"dateOfBirth": "1564-04-26",
|
|
||||||
"dateOfDeath": "1616-04-23"
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
// dummy to auto-load the plugin
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using { sap } from '@sap/cds/common';
|
|
||||||
|
|
||||||
extend sap.common.Currencies with {
|
|
||||||
// Currencies.code = ISO 4217 alphabetic three-letter code
|
|
||||||
// with the first two letters being equal to ISO 3166 alphabetic country codes
|
|
||||||
// See also:
|
|
||||||
// [1] https://www.iso.org/iso-4217-currency-codes.html
|
|
||||||
// [2] https://www.currency-iso.org/en/home/tables/table-a1.html
|
|
||||||
// [3] https://www.ibm.com/support/knowledgecenter/en/SSZLC2_7.0.0/com.ibm.commerce.payments.developer.doc/refs/rpylerl2mst97.htm
|
|
||||||
numcode : Integer;
|
|
||||||
exponent : Integer; //> e.g. 2 --> 1 Dollar = 10^2 Cent
|
|
||||||
minor : String; //> e.g. 'Cent'
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
code;name;descr
|
|
||||||
AU;Australia;Commonwealth of Australia
|
|
||||||
CA;Canada;Canada
|
|
||||||
CN;China;People's Republic of China (PRC)
|
|
||||||
FR;France;French Republic
|
|
||||||
DE;Germany;Federal Republic of Germany
|
|
||||||
IN;India;Republic of India
|
|
||||||
IL;Israel;State of Israel
|
|
||||||
MM;Myanmar;Republic of the Union of Myanmar
|
|
||||||
GB;United Kingdom;United Kingdom of Great Britain and Northern Ireland
|
|
||||||
US;United States;United States of America (USA)
|
|
||||||
EU;European Union;European Union
|
|
||||||
|
@@ -1,12 +0,0 @@
|
|||||||
code;locale;name;descr
|
|
||||||
AU;de;Australien;Commonwealth Australien
|
|
||||||
CA;de;Kanada;Canada
|
|
||||||
CN;de;China;Volksrepublik China
|
|
||||||
FR;de;Frankreich;Republik Frankreich
|
|
||||||
DE;de;Deutschland;Bundesrepublik Deutschland
|
|
||||||
IN;de;Indien;Republik Indien
|
|
||||||
IL;de;Israel;Staat Israel
|
|
||||||
MM;de;Myanmar;Republik der Union Myanmar
|
|
||||||
GB;de;Vereinigtes Königreich;Vereinigtes Königreich Großbritannien und Nordirland
|
|
||||||
US;de;Vereinigte Staaten;Vereinigte Staaten von Amerika
|
|
||||||
EU;de;Europäische Union;Europäische Union
|
|
||||||
|
@@ -1,12 +0,0 @@
|
|||||||
code;symbol;name;descr;numcode;minor;exponent
|
|
||||||
EUR;€;Euro;European Euro;978;Cent;2
|
|
||||||
USD;$;US Dollar;United States Dollar;840;Cent;2
|
|
||||||
CAD;$;Canadian Dollar;Canadian Dollar;124;Cent;2
|
|
||||||
AUD;$;Australian Dollar;Australian Dollar;036;Cent;2
|
|
||||||
GBP;£;British Pound;Great Britain Pound;826;Penny;2
|
|
||||||
ILS;₪;Shekel;Israeli New Shekel;376;Agorat;2
|
|
||||||
INR;₹;Rupee;Indian Rupee;356;Paise;2
|
|
||||||
QAR;﷼;Riyal;Katar Riyal;356;Dirham;2
|
|
||||||
SAR;﷼;Riyal;Saudi Riyal;682;Halala;2
|
|
||||||
JPY;¥;Yen;Japanese Yen;392;Sen;2
|
|
||||||
CNY;¥;Yuan;Chinese Yuan Renminbi;156;Jiao;1
|
|
||||||
|
@@ -1,5 +0,0 @@
|
|||||||
code;name
|
|
||||||
de;German
|
|
||||||
fr;French
|
|
||||||
en;English
|
|
||||||
en_GB;British English
|
|
||||||
|
@@ -1,10 +0,0 @@
|
|||||||
code;locale;name
|
|
||||||
de;en;German
|
|
||||||
de;de;Deutsch
|
|
||||||
de;fr;Allemande
|
|
||||||
fr;en;French
|
|
||||||
fr;de;Französisch
|
|
||||||
fr;fr;Francais
|
|
||||||
en;en;English
|
|
||||||
en;de;Englisch
|
|
||||||
en;fr;Anglais
|
|
||||||
|
@@ -1,2 +0,0 @@
|
|||||||
using from './currencies';
|
|
||||||
using from './regions';
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@capire/common",
|
|
||||||
"description": "Provides a pre-built extension package for std @sap/cds/common",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"dependencies": {
|
|
||||||
"@sap/cds": "*"
|
|
||||||
},
|
|
||||||
"cds": {
|
|
||||||
"requires": {
|
|
||||||
"@capire/common/data": {
|
|
||||||
"model": "@capire/common"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user