feat(pricing,types): price list API + price calculations with price lists (#5498)
**what:** **PriceList Service APIs:** - createPriceList - updatePriceList - addPriceListPrices - removePriceListRules - setPriceListRules - deletePriceList - listPriceLists - listAndCountPriceLists **Price Calculations** - Returns prices with price list prices - Returns a new shape with calculated and original prices Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
This commit is contained in:
co-authored by
Philip Korsholm
parent
2947f57db1
commit
1772e80ed1
@@ -6,3 +6,4 @@ export * from "./price-set-money-amount"
|
||||
export * from "./price-set-money-amount-rules"
|
||||
export * from "./price-set-rule-type"
|
||||
export * from "./rule-type"
|
||||
export * from "./price-list"
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { BaseFilterable } from "../../dal"
|
||||
import { CreateCurrencyDTO, CurrencyDTO } from "./currency"
|
||||
import { BaseFilterable } from "../../dal";
|
||||
import { CreateCurrencyDTO, CurrencyDTO } from "./currency";
|
||||
import { PriceSetMoneyAmountDTO } from "./price-set-money-amount";
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* A money amount's data. A money amount represents a price.
|
||||
*
|
||||
*
|
||||
* @prop id - The ID of the money amount.
|
||||
* @prop currency_code - The currency code of this money amount.
|
||||
* @prop currency - The money amount's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options.
|
||||
@@ -20,13 +21,14 @@ export interface MoneyAmountDTO {
|
||||
amount?: number
|
||||
min_quantity?: number
|
||||
max_quantity?: number
|
||||
price_set_money_amount?: PriceSetMoneyAmountDTO
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* The money amount to create.
|
||||
*
|
||||
*
|
||||
* @prop id - The ID of the money amount.
|
||||
* @prop currency_code - The currency code of this money amount.
|
||||
* @prop currency - The currency of this money amount.
|
||||
@@ -38,16 +40,16 @@ export interface CreateMoneyAmountDTO {
|
||||
id?: string
|
||||
currency_code: string
|
||||
currency?: CreateCurrencyDTO
|
||||
amount?: number
|
||||
amount: number
|
||||
min_quantity?: number | null
|
||||
max_quantity?: number | null
|
||||
}
|
||||
|
||||
/**
|
||||
* * @interface
|
||||
*
|
||||
*
|
||||
* The data to update in a money amount. The `id` is used to identify which money amount to update.
|
||||
*
|
||||
*
|
||||
* @prop id - The ID of the money amount to update.
|
||||
* @prop currency_code - The code of the currency to associate with the money amount.
|
||||
* @prop currency - The currency to associte with the money amount.
|
||||
@@ -65,9 +67,9 @@ export interface UpdateMoneyAmountDTO {
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* Filters to apply on a money amount.
|
||||
*
|
||||
*
|
||||
* @prop id - IDs to filter money amounts by.
|
||||
* @prop currency_code - Currency codes to filter money amounts by.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
import { CreateMoneyAmountDTO, MoneyAmountDTO } from "./money-amount"
|
||||
|
||||
import { BaseFilterable } from "../../dal"
|
||||
import { PriceSetMoneyAmountDTO } from "./price-set-money-amount"
|
||||
import { RuleTypeDTO } from "./rule-type"
|
||||
|
||||
export enum PriceListStatus {
|
||||
ACTIVE = "active",
|
||||
DRAFT = "draft",
|
||||
}
|
||||
|
||||
export enum PriceListType {
|
||||
SALE = "sale",
|
||||
OVERRIDE = "override",
|
||||
}
|
||||
|
||||
export interface PriceListDTO {
|
||||
id: string
|
||||
title?: string
|
||||
starts_at?: string | null
|
||||
status?: PriceListStatus
|
||||
ends_at?: string | null
|
||||
number_rules?: number
|
||||
price_set_money_amounts?: PriceSetMoneyAmountDTO[]
|
||||
money_amounts?: MoneyAmountDTO[]
|
||||
rule_types?: RuleTypeDTO[]
|
||||
rules?: PriceListRuleDTO[]
|
||||
price_list_rules?: PriceListRuleDTO[]
|
||||
}
|
||||
|
||||
export interface PriceListPriceDTO extends CreateMoneyAmountDTO {
|
||||
price_set_id: string
|
||||
}
|
||||
|
||||
export interface CreatePriceListRules extends Record<string, string[]> {}
|
||||
|
||||
export interface CreatePriceListDTO {
|
||||
title: string
|
||||
description: string
|
||||
starts_at?: string
|
||||
ends_at?: string
|
||||
status?: PriceListStatus
|
||||
type?: PriceListType
|
||||
number_rules?: number
|
||||
rules?: CreatePriceListRules
|
||||
prices?: PriceListPriceDTO[]
|
||||
}
|
||||
|
||||
export interface UpdatePriceListDTO {
|
||||
id: string
|
||||
title?: string
|
||||
starts_at?: string
|
||||
ends_at?: string
|
||||
status?: PriceListStatus
|
||||
number_rules?: number
|
||||
rules?: CreatePriceListRules
|
||||
}
|
||||
|
||||
export interface FilterablePriceListProps
|
||||
extends BaseFilterable<FilterablePriceListProps> {
|
||||
id?: string[]
|
||||
starts_at?: string[]
|
||||
ends_at?: string[]
|
||||
status?: PriceListStatus[]
|
||||
number_rules?: number[]
|
||||
}
|
||||
|
||||
export interface FilterablePriceListRuleProps
|
||||
extends BaseFilterable<FilterablePriceListRuleProps> {
|
||||
id?: string[]
|
||||
value?: string[]
|
||||
rule_type?: string[]
|
||||
price_list_id?: string[]
|
||||
}
|
||||
|
||||
export interface FilterablePriceListRuleValueProps
|
||||
extends BaseFilterable<FilterablePriceListRuleValueProps> {
|
||||
id?: string[]
|
||||
value?: string[]
|
||||
price_list_rule_id?: string[]
|
||||
}
|
||||
|
||||
export interface PriceListRuleDTO {
|
||||
id: string
|
||||
value: string
|
||||
rule_type: RuleTypeDTO
|
||||
price_list: PriceListDTO
|
||||
price_list_rule_values?: PriceListRuleValueDTO[]
|
||||
}
|
||||
|
||||
export interface CreatePriceListRuleDTO {
|
||||
rule_type_id?: string
|
||||
rule_type?: string | RuleTypeDTO
|
||||
price_list_id?: string
|
||||
price_list?: string | PriceListDTO
|
||||
}
|
||||
|
||||
export interface UpdatePriceListRuleDTO {
|
||||
id: string
|
||||
price_list_id?: string
|
||||
rule_type_id?: string
|
||||
price_list?: string
|
||||
rule_type?: string
|
||||
}
|
||||
|
||||
export interface PriceListRuleValueDTO {
|
||||
id: string
|
||||
value: string
|
||||
price_list_rule: PriceListRuleDTO
|
||||
}
|
||||
|
||||
export interface CreatePriceListRuleValueDTO {
|
||||
value: string
|
||||
price_list_rule_id?: string
|
||||
price_list_rule?: PriceListRuleDTO | string
|
||||
}
|
||||
|
||||
export interface UpdatePriceListRuleValueDTO {
|
||||
id: string
|
||||
value: string
|
||||
price_list_rule_id: string
|
||||
}
|
||||
|
||||
export interface AddPriceListPricesDTO {
|
||||
priceListId: string
|
||||
prices: PriceListPriceDTO[]
|
||||
}
|
||||
|
||||
export interface SetPriceListRulesDTO {
|
||||
priceListId: string
|
||||
rules: Record<string, string | string[]>
|
||||
}
|
||||
|
||||
export interface RemovePriceListRulesDTO {
|
||||
priceListId: string
|
||||
rules: string[]
|
||||
}
|
||||
@@ -64,7 +64,6 @@ export interface CreatePriceRuleDTO {
|
||||
value: string
|
||||
priority?: number
|
||||
price_set_money_amount_id: string
|
||||
price_list_id: string
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { BaseFilterable } from "../../dal"
|
||||
import { MoneyAmountDTO } from "./money-amount"
|
||||
import { PriceListDTO } from "./price-list"
|
||||
import { PriceRuleDTO } from "./price-rule"
|
||||
import { PriceSetDTO } from "./price-set"
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* A price set money amount's data.
|
||||
*
|
||||
*
|
||||
* @prop id - The ID of a price set money amount.
|
||||
* @prop title - The title of the price set money amount.
|
||||
* @prop price_set - The price set associated with the price set money amount. It may only be available if the relation `price_set` is expanded.
|
||||
@@ -17,6 +18,7 @@ export interface PriceSetMoneyAmountDTO {
|
||||
id: string
|
||||
title?: string
|
||||
price_set?: PriceSetDTO
|
||||
price_list?: PriceListDTO
|
||||
price_set_id?: string
|
||||
price_rules?: PriceRuleDTO[]
|
||||
money_amount?: MoneyAmountDTO
|
||||
@@ -32,14 +34,15 @@ export interface UpdatePriceSetMoneyAmountDTO {
|
||||
export interface CreatePriceSetMoneyAmountDTO {
|
||||
title?: string
|
||||
price_set?: PriceSetDTO | string
|
||||
price_list?: PriceListDTO | string
|
||||
money_amount?: MoneyAmountDTO | string
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* Filters to apply on price set money amounts.
|
||||
*
|
||||
*
|
||||
* @prop id - The IDs to filter the price set money amounts by.
|
||||
* @prop price_set_id - The IDs to filter the price set money amount's associated price set.
|
||||
*/
|
||||
@@ -47,4 +50,5 @@ export interface FilterablePriceSetMoneyAmountProps
|
||||
extends BaseFilterable<FilterablePriceSetMoneyAmountProps> {
|
||||
id?: string[]
|
||||
price_set_id?: string[]
|
||||
price_list_id?: string[]
|
||||
}
|
||||
|
||||
@@ -1,20 +1,16 @@
|
||||
import { BaseFilterable } from "../../dal"
|
||||
import {
|
||||
CreateMoneyAmountDTO,
|
||||
FilterableMoneyAmountProps,
|
||||
MoneyAmountDTO,
|
||||
} from "./money-amount"
|
||||
import { RuleTypeDTO } from "./rule-type"
|
||||
import { BaseFilterable } from "../../dal";
|
||||
import { CreateMoneyAmountDTO, FilterableMoneyAmountProps, MoneyAmountDTO } from "./money-amount";
|
||||
import { RuleTypeDTO } from "./rule-type";
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* The context to calculate prices. For example, you can specify the currency code to calculate prices in.
|
||||
*
|
||||
* @prop context -
|
||||
*
|
||||
* @prop context -
|
||||
* an object whose keys are the name of the context attribute. Its value can be a string or a number. For example, you can pass the `currency_code` property with its value being the currency code to calculate the price in.
|
||||
* Another example is passing the `quantity` property to calculate the price for that specified quantity, which finds a price set whose `min_quantity` and `max_quantity` conditions match the specified quantity.
|
||||
*
|
||||
*
|
||||
*/
|
||||
export interface PricingContext {
|
||||
context?: Record<string, string | number>
|
||||
@@ -22,9 +18,9 @@ export interface PricingContext {
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* Filters to apply on prices.
|
||||
*
|
||||
*
|
||||
* @prop id - IDs to filter prices.
|
||||
*/
|
||||
export interface PricingFilters {
|
||||
@@ -33,13 +29,13 @@ export interface PricingFilters {
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* A price set's data.
|
||||
*
|
||||
*
|
||||
* @prop id - The ID of the price set.
|
||||
* @prop money_amounts - The prices that belong to this price set.
|
||||
* @prop rule_types - The rule types applied on this price set.
|
||||
*
|
||||
*
|
||||
*/
|
||||
export interface PriceSetDTO {
|
||||
id: string
|
||||
@@ -49,9 +45,9 @@ export interface PriceSetDTO {
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* A calculated price set's data.
|
||||
*
|
||||
*
|
||||
* @prop id - The ID of the price set.
|
||||
* @prop amount - The calculated amount. It can possibly be `null` if there's no price set up for the provided context.
|
||||
* @prop currency_code - The currency code of the calculated price. It can possibly be `null`.
|
||||
@@ -60,17 +56,47 @@ export interface PriceSetDTO {
|
||||
*/
|
||||
export interface CalculatedPriceSetDTO {
|
||||
id: string
|
||||
amount: number | null
|
||||
price_set_id: string
|
||||
amount: string | null
|
||||
currency_code: string | null
|
||||
min_quantity: number | null
|
||||
max_quantity: number | null
|
||||
min_quantity: string | null
|
||||
max_quantity: string | null
|
||||
price_list_type: string | null
|
||||
price_list_id: string | null
|
||||
}
|
||||
|
||||
export interface CalculatedPriceSet {
|
||||
id: string
|
||||
is_calculated_price_price_list?: boolean
|
||||
calculated_amount: number | null
|
||||
|
||||
is_original_price_price_list?: boolean
|
||||
original_amount: number | null
|
||||
|
||||
currency_code: string | null
|
||||
|
||||
calculated_price?: {
|
||||
money_amount_id: string | null
|
||||
price_list_id: string | null
|
||||
price_list_type: string | null
|
||||
min_quantity: number | null
|
||||
max_quantity: number | null
|
||||
}
|
||||
|
||||
original_price?: {
|
||||
money_amount_id: string | null
|
||||
price_list_id: string | null
|
||||
price_list_type: string | null
|
||||
min_quantity: number | null
|
||||
max_quantity: number | null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* The rules to add to a price set.
|
||||
*
|
||||
*
|
||||
* @prop priceSetId - The ID of the price set to add the rules to.
|
||||
* @prop rules - The rules to add to a price set. The value of `attribute` is the value of the rule's `rule_attribute` attribute.
|
||||
*/
|
||||
@@ -81,9 +107,9 @@ export interface AddRulesDTO {
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* The prices to create part of a price set.
|
||||
*
|
||||
*
|
||||
* @prop rules - The rules to add to the price. The object's keys are rule types' `rule_attribute` attribute, and values are the value of that rule associated with this price.
|
||||
*/
|
||||
export interface CreatePricesDTO extends CreateMoneyAmountDTO {
|
||||
@@ -92,9 +118,9 @@ export interface CreatePricesDTO extends CreateMoneyAmountDTO {
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* The prices to add to a price set.
|
||||
*
|
||||
*
|
||||
* @prop priceSetId - The ID of the price set to add prices to.
|
||||
* @prop prices - The prices to add to the price set.
|
||||
*/
|
||||
@@ -105,9 +131,9 @@ export interface AddPricesDTO {
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* The rules to remove from a price set.
|
||||
*
|
||||
*
|
||||
* @prop id - The ID of the price set.
|
||||
* @prop rules - The rules to remove. Each string is the `rule_attribute` of a rule to remove.
|
||||
*/
|
||||
@@ -118,9 +144,9 @@ export interface RemovePriceSetRulesDTO {
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* A price set to create.
|
||||
*
|
||||
*
|
||||
* @prop rules - The rules to associate with the price set. The value of `attribute` is the value of the rule's `rule_attribute` attribute.
|
||||
* @prop prices -The prices to create and add to this price set.
|
||||
*/
|
||||
@@ -131,9 +157,9 @@ export interface CreatePriceSetDTO {
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* The data to update in a price set. The `id` is used to identify which price set to update.
|
||||
*
|
||||
*
|
||||
* @prop id - A string indicating the ID of the price set to update.
|
||||
*/
|
||||
export interface UpdatePriceSetDTO {
|
||||
@@ -142,9 +168,9 @@ export interface UpdatePriceSetDTO {
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* Filters to apply on price sets.
|
||||
*
|
||||
*
|
||||
* @prop id - IDs to filter price sets by.
|
||||
* @prop money_amounts - Filters to apply on a price set's associated money amounts.
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user