feat(pricing, types): add price rule operators to price calculations (#10350)

what:

- adds price rule operators when doing price calculations
- rules now accepts a key where the value can be an array of objects `({ operator: string, value: number })`
  - validation for available types of operator and value to be a number
```
await service.createPriceSets({
  prices: [
    {
      amount: 50,
      currency_code: "usd",
      rules: {
        region_id: "de",
        cart_total: [
          { operator: "gte", value: 400 },
          { operator: "lte", value: 500 },
        ]
      },
    },
  ]
})
```
- price calculations will now account for the operators - lte, gte, lt, gt when the price context is a number

RESOLVES CMRC-747
This commit is contained in:
Riqwan Thamir
2024-11-28 20:48:00 +00:00
committed by GitHub
parent 805fe4b1db
commit 324b4ab438
8 changed files with 462 additions and 33 deletions
@@ -7,6 +7,7 @@ import {
MoneyAmountDTO,
UpdateMoneyAmountDTO,
} from "./money-amount"
import { PricingRuleOperatorValues } from "./price-rule"
export interface PricingRepositoryService {
calculatePrices(
@@ -206,6 +207,11 @@ export interface CalculatedPriceSet {
}
}
export interface RuleWithOperator {
operator: PricingRuleOperatorValues
value: number
}
/**
* @interface
*
@@ -214,7 +220,8 @@ export interface CalculatedPriceSet {
* Each key of the object is a the attribute, and its value
* is the values of the rule.
*/
export interface CreatePriceSetPriceRules extends Record<string, string> {}
export interface CreatePriceSetPriceRules
extends Record<string, string | RuleWithOperator[]> {}
/**
* @interface