Skip to content

Commit 80bc08c

Browse files
Update bookstore functions for optionality
1 parent a6f7336 commit 80bc08c

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

use-cases/bookstore/schema.tql

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,19 +263,22 @@ fun book_recommendations_by_author($user: user) -> { book }:
263263
($new-book, $shared-author) isa authoring;
264264
return { $new-book };
265265

266-
fun order_line_best_price($line: order-line) -> { double }:
266+
fun order_line_best_price($line: order-line) -> { double? }:
267267
match
268268
($order) isa action-execution, has timestamp $order-time;
269269
$line isa order-line, links ($order, $item);
270270
$item has price $retail-price;
271271
let $time_value = $order-time;
272-
let $best-discount = best_discount_for_item($item, $time_value);
273-
let $discounted-price = round(100 * $retail-price * (1 - $best-discount)) / 100;
272+
try { let $best-discount? = best_discount_for_item($item, $time_value); };
274273
$line has quantity $quantity;
275-
let $line-total = $quantity * $discounted-price;
274+
match
275+
try {
276+
let $discounted-price = round(100 * $retail-price * (1 - $best-discount)) / 100;
277+
let $line-total = $quantity * $discounted-price;
278+
};
276279
return { $line-total };
277280

278-
fun best_discount_for_item($item: book, $order-time: datetime) -> double:
281+
fun best_discount_for_item($item: book, $order-time: datetime) -> double?:
279282
match
280283
{
281284
$inclusion isa promotion-inclusion,

0 commit comments

Comments
 (0)