|
| 1 | +import { type CataloguePredicateAPI, type OrderPredicateAPI } from "@dashboard/discounts/types"; |
1 | 2 | import { |
2 | 3 | type PromotionRuleDetailsFragment, |
3 | 4 | type PromotionRuleInput, |
@@ -35,27 +36,39 @@ export const mapAPIRuleToForm = ( |
35 | 36 | } |
36 | 37 |
|
37 | 38 | if (type === PromotionTypeEnum.CATALOGUE) { |
| 39 | + /** |
| 40 | + * TODO: Saleor stores predicate as JSON, which for Dashboard is "unknown". |
| 41 | + * We need to create a Zod schema that will parse it to known shape. If parsing fails, Sentry should be triggered. |
| 42 | + * Currently code implicitly casts, which should be ok, but is not entirely safe |
| 43 | + */ |
| 44 | + const predicate = rule.cataloguePredicate as CataloguePredicateAPI; |
| 45 | + |
38 | 46 | const catalogueConditions = prepareCatalogueRuleConditions( |
39 | | - rule.cataloguePredicate, |
| 47 | + predicate, |
40 | 48 | labelMaps.conditionsValues, |
41 | 49 | ); |
42 | 50 |
|
43 | 51 | return { |
44 | 52 | ...baseRuleData, |
45 | 53 | conditions: catalogueConditions, |
46 | | - hasPredicateNestedConditions: hasPredicateNestedConditions(rule.cataloguePredicate), |
| 54 | + hasPredicateNestedConditions: hasPredicateNestedConditions(predicate), |
47 | 55 | }; |
48 | 56 | } |
49 | 57 |
|
50 | 58 | if (type === PromotionTypeEnum.ORDER) { |
51 | | - const orderconditions = prepareOrderConditions( |
52 | | - rule.orderPredicate?.discountedObjectPredicate ?? {}, |
53 | | - ); |
| 59 | + /** |
| 60 | + * TODO: Saleor stores predicate as JSON, which for Dashboard is "unknown". |
| 61 | + * We need to create a Zod schema that will parse it to known shape. If parsing fails, Sentry should be triggered. |
| 62 | + * Currently code implicitly casts, which should be ok, but is not entirely safe |
| 63 | + */ |
| 64 | + const predicate = rule.orderPredicate as OrderPredicateAPI; |
| 65 | + |
| 66 | + const orderconditions = prepareOrderConditions(predicate?.discountedObjectPredicate ?? {}); |
54 | 67 |
|
55 | 68 | return { |
56 | 69 | ...baseRuleData, |
57 | 70 | conditions: orderconditions, |
58 | | - hasPredicateNestedConditions: hasPredicateNestedConditions(rule.orderPredicate), |
| 71 | + hasPredicateNestedConditions: hasPredicateNestedConditions(predicate), |
59 | 72 | }; |
60 | 73 | } |
61 | 74 |
|
|
0 commit comments