Moved dynamic constraints in a dedicated folder

This commit is contained in:
Daniel Hutzel
2025-07-24 10:38:43 +02:00
parent c9021d0f46
commit 65eccfad33
7 changed files with 36 additions and 8 deletions

View File

@@ -1,2 +1,2 @@
using { AdminService } from './admin-service';
annotate AdminService with @requires: false; //'admin';
annotate AdminService with @requires:'admin';

View File

@@ -1,6 +1,6 @@
using { sap.capire.bookshop as my } from '../db/schema';
service AdminService @(path:'/admin') {
entity Authors as projection on my.Authors excluding { books};
entity Authors as projection on my.Authors;
entity Books as projection on my.Books;
entity Genres as projection on my.Genres;
}

View File

@@ -0,0 +1,26 @@
## Experimental Dynamic Constraints
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.
### Prerequisites
You've setup the [_cap/samples_](https://github.com/sap-samples/cloud-cap-samples) like so:
```sh
git clone -q https://github.com/sap-samples/cloud-cap-samples cap/samples
cd cap/samples
npm install
```
### Testing
Test like that in `cds.repl` from _cap/samples_ root:
```sh
cds repl --run bookshop/test/dynamic-constraints
````
```javascript
await AdminService.create ('Books', { title:' ', author_ID:150 })
```

View File

@@ -1,9 +1,6 @@
//
// Quick and dirty implementation for cds.validate() using db-level constraints
// Test in cds.repl like that:
// {Books} = AdminService.entities
// await cds.run (()=> INSERT.into (Books, { title:' ', author_ID:150 }) .then (cds.validate(Books)))
// await AdminService.create ('Books', { title:' ', author_ID:150 })
// Quick and dirty implementation for cds.validate()
// using db-level constraints.
//
const cds = require('@sap/cds')

View File

@@ -0,0 +1,5 @@
using { AdminService } from '../../../srv/admin-service';
annotate AdminService with @requires: false;
extend AdminService.Authors with columns {
null as books // to simulate the exclusion of books
}

View File

@@ -1,5 +1,5 @@
namespace sap.capire.bookshop;
using from '../db/schema';
using from './admin-service';
view Books.field.control as select from Books { ID,
genre.name == 'Drama' ? 'readonly' :