Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit 65eccfa

Browse files
committed
Moved dynamic constraints in a dedicated folder
1 parent c9021d0 commit 65eccfa

File tree

7 files changed

+36
-8
lines changed

7 files changed

+36
-8
lines changed

bookshop/srv/access-control.cds

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
using { AdminService } from './admin-service';
2-
annotate AdminService with @requires: false; //'admin';
2+
annotate AdminService with @requires:'admin';

bookshop/srv/admin-service.cds

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using { sap.capire.bookshop as my } from '../db/schema';
22
service AdminService @(path:'/admin') {
3-
entity Authors as projection on my.Authors excluding { books};
3+
entity Authors as projection on my.Authors;
44
entity Books as projection on my.Books;
55
entity Genres as projection on my.Genres;
66
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## Experimental Dynamic Constraints
2+
3+
This example demonstrates how to use dynamic constraints in a CAP application. It includes a service definition and a test setup to validate the constraints.
4+
5+
6+
### Prerequisites
7+
8+
You've setup the [_cap/samples_](https://github.com/sap-samples/cloud-cap-samples) like so:
9+
10+
```sh
11+
git clone -q https://github.com/sap-samples/cloud-cap-samples cap/samples
12+
cd cap/samples
13+
npm install
14+
```
15+
16+
### Testing
17+
18+
Test like that in `cds.repl` from _cap/samples_ root:
19+
20+
```sh
21+
cds repl --run bookshop/test/dynamic-constraints
22+
````
23+
24+
```javascript
25+
await AdminService.create ('Books', { title:' ', author_ID:150 })
26+
```

bookshop/server.js renamed to bookshop/test/dynamic-constraints/server.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
//
2-
// Quick and dirty implementation for cds.validate() using db-level constraints
3-
// Test in cds.repl like that:
4-
// {Books} = AdminService.entities
5-
// await cds.run (()=> INSERT.into (Books, { title:' ', author_ID:150 }) .then (cds.validate(Books)))
6-
// await AdminService.create ('Books', { title:' ', author_ID:150 })
2+
// Quick and dirty implementation for cds.validate()
3+
// using db-level constraints.
74
//
85

96
const cds = require('@sap/cds')
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using { AdminService } from '../../../srv/admin-service';
2+
annotate AdminService with @requires: false;
3+
extend AdminService.Authors with columns {
4+
null as books // to simulate the exclusion of books
5+
}

bookshop/srv/x-field-control.cds renamed to bookshop/test/dynamic-constraints/srv/field-control.cds

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
namespace sap.capire.bookshop;
2-
using from '../db/schema';
2+
using from './admin-service';
33

44
view Books.field.control as select from Books { ID,
55
genre.name == 'Drama' ? 'readonly' :
File renamed without changes.

0 commit comments

Comments
 (0)