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:
@@ -1,38 +1,2 @@
|
||||
import { MedusaError } from "../common"
|
||||
|
||||
export const ReservedPricingRuleAttributes = [
|
||||
"quantity",
|
||||
"currency_code",
|
||||
"price_list_id",
|
||||
]
|
||||
|
||||
type RuleAttributeInput = string | undefined
|
||||
|
||||
export const getInvalidRuleAttributes = (
|
||||
ruleAttributes: RuleAttributeInput[]
|
||||
): string[] => {
|
||||
const invalidRuleAttributes: string[] = []
|
||||
|
||||
for (const attribute of ReservedPricingRuleAttributes) {
|
||||
if (ruleAttributes.indexOf(attribute) > -1) {
|
||||
invalidRuleAttributes.push(attribute)
|
||||
}
|
||||
}
|
||||
|
||||
return invalidRuleAttributes
|
||||
}
|
||||
|
||||
export const validateRuleAttributes = (
|
||||
ruleAttributes: RuleAttributeInput[]
|
||||
): void => {
|
||||
const invalidRuleAttributes = getInvalidRuleAttributes(ruleAttributes)
|
||||
|
||||
if (invalidRuleAttributes.length) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
`Can't create rule_attribute with reserved keywords [${ReservedPricingRuleAttributes.join(
|
||||
", "
|
||||
)}] - ${invalidRuleAttributes.join(", ")}`
|
||||
)
|
||||
}
|
||||
}
|
||||
export * from "./price-list"
|
||||
export * from "./rule-type"
|
||||
|
||||
9
packages/utils/src/pricing/price-list.ts
Normal file
9
packages/utils/src/pricing/price-list.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export enum PriceListStatus {
|
||||
ACTIVE = "active",
|
||||
DRAFT = "draft",
|
||||
}
|
||||
|
||||
export enum PriceListType {
|
||||
SALE = "sale",
|
||||
OVERRIDE = "override",
|
||||
}
|
||||
37
packages/utils/src/pricing/rule-type.ts
Normal file
37
packages/utils/src/pricing/rule-type.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { MedusaError } from "../common"
|
||||
type RuleAttributeInput = string | undefined
|
||||
|
||||
export const ReservedPricingRuleAttributes = [
|
||||
"quantity",
|
||||
"currency_code",
|
||||
"price_list_id",
|
||||
]
|
||||
|
||||
export const getInvalidRuleAttributes = (
|
||||
ruleAttributes: RuleAttributeInput[]
|
||||
): string[] => {
|
||||
const invalidRuleAttributes: string[] = []
|
||||
|
||||
for (const attribute of ReservedPricingRuleAttributes) {
|
||||
if (ruleAttributes.indexOf(attribute) > -1) {
|
||||
invalidRuleAttributes.push(attribute)
|
||||
}
|
||||
}
|
||||
|
||||
return invalidRuleAttributes
|
||||
}
|
||||
|
||||
export const validateRuleAttributes = (
|
||||
ruleAttributes: RuleAttributeInput[]
|
||||
): void => {
|
||||
const invalidRuleAttributes = getInvalidRuleAttributes(ruleAttributes)
|
||||
|
||||
if (invalidRuleAttributes.length) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
`Can't create rule_attribute with reserved keywords [${ReservedPricingRuleAttributes.join(
|
||||
", "
|
||||
)}] - ${invalidRuleAttributes.join(", ")}`
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user