Moved dynamic constraints in a dedicated folder
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
using { AdminService } from './admin-service';
|
||||
annotate AdminService with @requires: false; //'admin';
|
||||
annotate AdminService with @requires:'admin';
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
26
bookshop/test/dynamic-constraints/readme.md
Normal file
26
bookshop/test/dynamic-constraints/readme.md
Normal 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 })
|
||||
```
|
||||
@@ -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')
|
||||
5
bookshop/test/dynamic-constraints/srv/admin-service.cds
Normal file
5
bookshop/test/dynamic-constraints/srv/admin-service.cds
Normal 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
|
||||
}
|
||||
@@ -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' :
|
||||
Reference in New Issue
Block a user