-
Notifications
You must be signed in to change notification settings - Fork 0
@assert #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@assert #28
Changes from all commits
061364c
edad7a7
b996b13
8707fab
0747759
0105f4f
6624085
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -169,4 +169,4 @@ | |
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> | ||
| </project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| ASSERT_ENDDATE_AFTER_BEGINDATE=End date must be after begin date | ||
| ASSERT_BOOKINGS_IN_TRAVEL_PERIOD=All bookings must be within the travel period | ||
| ASSERT_BOOKING_CURRENCY_MATCHES_TRAVEL=All bookings must use the same currency as the travel | ||
| ASSERT_FLIGHT_PRICE_POSITIVE=Flight price must be a positive value | ||
| ASSERT_BOOKING_FEE_NON_NEGATIVE=Booking fee cannot be negative |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| ASSERT_ENDDATE_AFTER_BEGINDATE=Enddatum muss nach dem Anfangsdatum liegen | ||
| ASSERT_BOOKINGS_IN_TRAVEL_PERIOD=Alle Buchungen müssen innerhalb des Reisezeitraums liegen | ||
| ASSERT_BOOKING_CURRENCY_MATCHES_TRAVEL=Alle Buchungen müssen dieselbe Währung wie die Reise verwenden | ||
| ASSERT_FLIGHT_PRICE_POSITIVE=Der Flugpreis muss ein positiver Wert sein | ||
| ASSERT_BOOKING_FEE_NON_NEGATIVE=Buchungsgebühr kann nicht negativ sein |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| ASSERT_ENDDATE_AFTER_BEGINDATE=La date de fin doit être postérieure à la date de début | ||
| ASSERT_BOOKINGS_IN_TRAVEL_PERIOD=Toutes les réservations doivent être dans la période de voyage | ||
| ASSERT_BOOKING_CURRENCY_MATCHES_TRAVEL=Toutes les réservations doivent utiliser la même devise que le voyage | ||
| ASSERT_FLIGHT_PRICE_POSITIVE=Le prix du vol doit être une valeur positive | ||
| ASSERT_BOOKING_FEE_NON_NEGATIVE=Les frais de réservation ne peuvent pas être négatifs |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,54 @@ | ||||||||||
| using { TravelService } from './travel-service'; | ||||||||||
|
|
||||||||||
|
|
||||||||||
| annotate TravelService.Travels with { | ||||||||||
|
|
||||||||||
| Description @assert: (case | ||||||||||
| when length(Description) < 3 then 'Description too short' | ||||||||||
| end); | ||||||||||
|
|
||||||||||
| Agency @assert: (case | ||||||||||
| when not exists Agency then 'Agency does not exist' | ||||||||||
| end); | ||||||||||
|
|
||||||||||
| Customer @assert: (case | ||||||||||
| when Customer is null then 'Customer must be specified' | ||||||||||
| when not exists Customer then 'Customer does not exist' | ||||||||||
| end); | ||||||||||
|
|
||||||||||
| EndDate @assert: (case | ||||||||||
| when EndDate < BeginDate then error('ASSERT_ENDDATE_AFTER_BEGINDATE', null, (BeginDate, EndDate)) | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in the JS variant, an additional check is used : However, the JS variant does the check again on the Travel entity (https://github.com/capire/xtravels/blob/e89c2df28511de82a35e9da5433182d283388d9f/srv/travel-constraints.cds#L22C4-L22C98).
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic is covered by the assertion on Flight.date. I wouldn't duplicate these errors, as it leads to multiple errors with the same reason. I'd rather refer to the BeginDate/EndDate as additional targets, but I don't think this is necessary here. |
||||||||||
| end); | ||||||||||
|
|
||||||||||
| BookingFee @assert: (case | ||||||||||
| when BookingFee < 0 then 'ASSERT_BOOKING_FEE_NON_NEGATIVE' | ||||||||||
| end); | ||||||||||
|
|
||||||||||
| }; | ||||||||||
|
|
||||||||||
|
|
||||||||||
| annotate TravelService.Bookings with { | ||||||||||
|
|
||||||||||
| Flight { | ||||||||||
| date @assert: (case | ||||||||||
| when date not between $self.Travel.BeginDate and $self.Travel.EndDate then 'ASSERT_BOOKINGS_IN_TRAVEL_PERIOD' | ||||||||||
| end); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| FlightPrice @assert: (case | ||||||||||
| when FlightPrice < 0 then 'ASSERT_FLIGHT_PRICE_POSITIVE' | ||||||||||
| end); | ||||||||||
|
|
||||||||||
| Currency { | ||||||||||
| code @assert: (case | ||||||||||
| when code != $self.Travel.Currency.code then 'ASSERT_BOOKING_CURRENCY_MATCHES_TRAVEL' | ||||||||||
| end); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. taken from the JS variant:
Suggested change
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd leave this out for now. The BookingDate is defaulted to "today". This makes it very impractical to play around with the application when creating new bookings, as all test data is in the past. We can maybe add it later on, but I don't think it shows any additional feature, so I would leave it out for practical reasons. |
||||||||||
| }; | ||||||||||
|
|
||||||||||
|
|
||||||||||
| annotate TravelService.Travels with @Capabilities.FilterRestrictions.FilterExpressionRestrictions: [ | ||||||||||
| { Property: 'BeginDate', AllowedExpressions : 'SingleRange' }, | ||||||||||
| { Property: 'EndDate', AllowedExpressions : 'SingleRange' } | ||||||||||
| ]; | ||||||||||
Uh oh!
There was an error while loading. Please reload this page.