Compare commits

..

1 Commits

Author SHA1 Message Date
d049904
73f438d3c0 Test extend with composition 2024-03-06 14:59:24 +01:00
10 changed files with 3682 additions and 3447 deletions

31
.eslintrc Normal file
View File

@@ -0,0 +1,31 @@
{
"extends": [
"plugin:@sap/cds/recommended",
"eslint:recommended"
],
"env": {
"browser": true,
"es2022": true,
"node": true,
"jest": true,
"mocha": true
},
"globals": {
"SELECT": true,
"INSERT": true,
"UPSERT": true,
"UPDATE": true,
"DELETE": true,
"CREATE": true,
"DROP": true,
"CDL": true,
"CQL": true,
"cds": true
},
"rules": {
"no-console": "off",
"require-atomic-updates": "off",
"require-await":"warn",
"no-unused-vars": ["warn", { "argsIgnorePattern": "_" }]
}
}

View File

@@ -11,6 +11,7 @@ on:
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
@@ -18,21 +19,10 @@ jobs:
node-version: [20.x, 18.x] node-version: [20.x, 18.x]
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }} - name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4 uses: actions/setup-node@v1
with: with:
node-version: ${{ matrix.node-version }} node-version: ${{ matrix.node-version }}
- run: npm ci - run: npm ci
- run: npm test - run: npm test
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
- run: npm ci
- run: npm run lint

View File

@@ -13,7 +13,7 @@
"@cap-js/sqlite": "*" "@cap-js/sqlite": "*"
}, },
"dependencies": { "dependencies": {
"@sap/cds": ">=7", "@sap/cds": "^7",
"express": "^4.17.1" "express": "^4.17.1"
}, },
"scripts": { "scripts": {

View File

@@ -4,8 +4,8 @@ module.exports = class CatalogService extends cds.ApplicationService { init() {
const { ListOfBooks } = this.entities const { ListOfBooks } = this.entities
// Add some discount for overstocked books // Add some discount for overstocked books
this.after('each', ListOfBooks, book => { this.after('READ', ListOfBooks, each => {
if (book.stock > 111) book.title += ` -- 11% discount!` if (each.stock > 111) each.title += ` -- 11% discount!`
}) })
// Reduce stock of ordered books if available stock suffices // Reduce stock of ordered books if available stock suffices

View File

@@ -10,12 +10,22 @@
// //
using { sap.capire.bookshop.Books } from '@capire/bookshop'; using { sap.capire.bookshop.Books } from '@capire/bookshop';
using { ReviewsService.Reviews } from '@capire/reviews'; using { ReviewsService.Reviews } from '@capire/reviews';
using { managed, cuid } from '@sap/cds/common';
extend Books with { extend Books with {
reviews : Composition of many Reviews on reviews.subject = $self.ID; reviews : Composition of many Reviews on reviews.subject = $self.ID;
rating : type of Reviews:rating; // average rating rating : type of Reviews:rating; // average rating
numberOfReviews : Integer @title : '{i18n>NumberOfReviews}'; numberOfReviews : Integer @title : '{i18n>NumberOfReviews}';
Y_characteristics : Composition of many Y_Characteristic on Y_characteristics.parent = $self;
} }
entity Y_Characteristic : cuid, managed {
parent : Association to one Books;
characteristicId : String;
name : String;
value : String;
uom : String;
}
// //
// Extend Orders with Books as Products // Extend Orders with Books as Products

View File

@@ -79,3 +79,36 @@ Authorization: Basic alice:
"dateOfBirth": "1564-04-26", "dateOfBirth": "1564-04-26",
"dateOfDeath": "1616-04-23" "dateOfDeath": "1616-04-23"
} }
### Create book
POST {{bookshop}}/admin/Books
Content-Type: application/json
Authorization: Basic alice:
{
"ID": 291,
"title": "Ttile1",
"author_ID": 107,
"numberOfReviews": 3,
"Y_characteristics": [{
"ID": "e326afd9-4688-4bf5-9664-783ff997cdf5",
"characteristicId": "myid",
"name": "myname"
}]
}
### Update book
PUT {{bookshop}}/admin/Books(291)
Content-Type: application/json
Authorization: Basic alice:
{
"title": "Ttile111111111",
"author_ID": 107,
"numberOfReviews": 4,
"Y_characteristics": [{
"ID": "e326afd9-4688-4bf5-9664-783ff997cdf5",
"characteristicId": "myid123",
"name": "myname123"
}]
}

View File

@@ -1,27 +0,0 @@
const eslintCds = require('@sap/eslint-plugin-cds')
const eslintJs = require('@eslint/js')
const globals = require('globals')
module.exports = [
eslintJs.configs.recommended,
eslintCds.configs.recommended,
{
languageOptions: {
globals: {
sap: true,
...globals.es2022,
...globals.browser,
...globals.node,
...globals.jest,
...globals.mocha,
...eslintCds.configs.recommended.languageOptions.globals
}
},
rules: {
'no-console': 'off',
'no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
'require-atomic-updates': 'off',
'require-await': 'warn'
}
}
]

View File

@@ -1,4 +1,4 @@
import { Request } from "@sap/cds" import type { Request } from "@sap/cds/apis/services"
module.exports = class say { module.exports = class say {
hello(req: Request) { hello(req: Request) {

6892
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,58 +1,56 @@
{ {
"name": "@capire/samples", "name": "@capire/samples",
"version": "2.0.0", "version": "2.0.0",
"description": "A monorepo with several samples for CAP.", "description": "A monorepo with several samples for CAP.",
"repository": "https://github.com/sap-samples/cloud-cap-samples.git", "repository": "https://github.com/sap-samples/cloud-cap-samples.git",
"author": "daniel.hutzel@sap.com", "author": "daniel.hutzel@sap.com",
"dependencies": { "dependencies": {
"@sap/cds": ">=7" "@sap/cds": ">=7"
}, },
"workspaces": [ "workspaces": [
"./bookshop", "./bookshop",
"./bookstore", "./bookstore",
"./common", "./common",
"./data-viewer", "./data-viewer",
"./fiori", "./fiori",
"./hello", "./hello",
"./media", "./media",
"./orders", "./orders",
"./loggers", "./loggers",
"./reviews" "./reviews"
], ],
"devDependencies": { "devDependencies": {
"@cap-js/sqlite": "^1", "@cap-js/sqlite": "^1",
"@sap/eslint-plugin-cds": "^3", "@sap/eslint-plugin-cds": "^2.6.1",
"axios": "^1", "axios": "^1",
"chai": "^4.3.4", "chai": "^4.3.4",
"chai-as-promised": "^7.1.1", "chai-as-promised": "^7.1.1",
"chai-subset": "^1.6.0", "chai-subset": "^1.6.0",
"eslint": "^9", "semver": "^7"
"semver": "^7" },
}, "scripts": {
"scripts": { "cleanup": "rm -rf node_modules && rm -rf */node_modules && rm -rf */*/node_modules",
"cleanup": "rm -rf node_modules && rm -rf */node_modules && rm -rf */*/node_modules", "bookshop": "cds watch bookshop",
"bookshop": "cds watch bookshop", "fiori": "cds watch fiori",
"fiori": "cds watch fiori", "hello": "cds watch hello",
"hello": "cds watch hello", "media": "cds watch media",
"media": "cds watch media", "mocha": "CDS_TEST_SILENT=y npx mocha",
"mocha": "CDS_TEST_SILENT=y npx mocha", "jest": "npx jest --silent",
"jest": "npx jest --silent", "start": "cds watch fiori",
"start": "cds watch fiori", "test": "npm run jest -- --silent",
"test": "npm run jest -- --silent", "test:hello": "cd hello && npm test"
"test:hello": "cd hello && npm test", },
"lint": "eslint ." "jest": {
}, "testTimeout": 20000,
"jest": { "testMatch": [
"testTimeout": 20000, "**/*.test.js"
"testMatch": [ ]
"**/*.test.js" },
] "mocha": {
}, "recursive": true,
"mocha": { "parallel": true,
"recursive": true, "timeout": 6666
"parallel": true, },
"timeout": 6666 "license": "SEE LICENSE IN LICENSE",
}, "private": true
"license": "SEE LICENSE IN LICENSE", }
"private": true
}