feat(core-flows,medusa,types,utils): rename psma to prices (#6796)
What: Renames pricesetmoneyamount to prices Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
This commit is contained in:
co-authored by
Adrien de Peretti
parent
fbc369705d
commit
9073d7aba3
@@ -1,14 +1,18 @@
|
||||
import { isDefined } from "./is-defined"
|
||||
|
||||
export const removeNullish = (
|
||||
obj: Record<string, unknown>
|
||||
): Record<string, unknown> =>
|
||||
Object.entries(obj).reduce((resultObject, [currentKey, currentValue]) => {
|
||||
if (!isDefined(currentValue) || currentValue === null) {
|
||||
export function removeNullish<T = unknown>(
|
||||
obj: Record<string, T>
|
||||
): Record<string, T> {
|
||||
return Object.entries(obj).reduce(
|
||||
(resultObject, [currentKey, currentValue]) => {
|
||||
if (!isDefined(currentValue) || currentValue === null) {
|
||||
return resultObject
|
||||
}
|
||||
|
||||
resultObject[currentKey] = currentValue
|
||||
|
||||
return resultObject
|
||||
}
|
||||
|
||||
resultObject[currentKey] = currentValue
|
||||
|
||||
return resultObject
|
||||
}, {})
|
||||
},
|
||||
{}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -248,13 +248,11 @@ export type AbstractModuleService<
|
||||
*
|
||||
* const otherModels = new Set([
|
||||
* Currency,
|
||||
* MoneyAmount,
|
||||
* Price,
|
||||
* PriceList,
|
||||
* PriceListRule,
|
||||
* PriceListRuleValue,
|
||||
* PriceRule,
|
||||
* PriceSetMoneyAmount,
|
||||
* PriceSetMoneyAmountRules,
|
||||
* PriceSetRuleType,
|
||||
* RuleType,
|
||||
* ])
|
||||
@@ -265,11 +263,7 @@ export type AbstractModuleService<
|
||||
* // The configuration of each entity also accept singular/plural properties, if not provided then it is using english pluralization
|
||||
* {
|
||||
* Currency: { dto: PricingTypes.CurrencyDTO }
|
||||
* MoneyAmount: { dto: PricingTypes.MoneyAmountDTO }
|
||||
* PriceSetMoneyAmount: { dto: PricingTypes.PriceSetMoneyAmountDTO }
|
||||
* PriceSetMoneyAmountRules: {
|
||||
* dto: PricingTypes.PriceSetMoneyAmountRulesDTO
|
||||
* }
|
||||
* Price: { dto: PricingTypes.PriceDTO }
|
||||
* PriceRule: { dto: PricingTypes.PriceRuleDTO }
|
||||
* RuleType: { dto: PricingTypes.RuleTypeDTO }
|
||||
* PriceList: { dto: PricingTypes.PriceListDTO }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
PriceDTO,
|
||||
PriceListRuleDTO,
|
||||
PriceRuleDTO,
|
||||
PriceSetMoneyAmountDTO,
|
||||
ProductVariantDTO,
|
||||
UpdatePriceListPriceDTO,
|
||||
} from "@medusajs/types"
|
||||
@@ -33,20 +33,20 @@ export function buildPriceSetRules(
|
||||
}
|
||||
|
||||
export function buildPriceSetPricesForCore(
|
||||
priceSetMoneyAmounts: (PriceSetMoneyAmountDTO & {
|
||||
price_set: PriceSetMoneyAmountDTO["price_set"] & {
|
||||
prices: (PriceDTO & {
|
||||
price_set: PriceDTO["price_set"] & {
|
||||
variant?: ProductVariantDTO
|
||||
}
|
||||
})[]
|
||||
): Record<string, any>[] {
|
||||
return priceSetMoneyAmounts.map((priceSetMoneyAmount) => {
|
||||
const productVariant = (priceSetMoneyAmount.price_set as any).variant
|
||||
const rules: Record<string, string> = priceSetMoneyAmount.price_rules
|
||||
? buildPriceSetRules(priceSetMoneyAmount.price_rules)
|
||||
return prices.map((price) => {
|
||||
const productVariant = (price.price_set as any).variant
|
||||
const rules: Record<string, string> = price.price_rules
|
||||
? buildPriceSetRules(price.price_rules)
|
||||
: {}
|
||||
|
||||
return {
|
||||
...priceSetMoneyAmount,
|
||||
...price,
|
||||
variant_id: productVariant?.id ?? null,
|
||||
rules,
|
||||
}
|
||||
@@ -54,16 +54,16 @@ export function buildPriceSetPricesForCore(
|
||||
}
|
||||
|
||||
export function buildPriceSetPricesForModule(
|
||||
priceSetMoneyAmounts: PriceSetMoneyAmountDTO[]
|
||||
prices: PriceDTO[]
|
||||
): UpdatePriceListPriceDTO[] {
|
||||
return priceSetMoneyAmounts.map((priceSetMoneyAmount) => {
|
||||
const rules: Record<string, string> = priceSetMoneyAmount.price_rules
|
||||
? buildPriceSetRules(priceSetMoneyAmount.price_rules)
|
||||
return prices.map((price) => {
|
||||
const rules: Record<string, string> = price.price_rules
|
||||
? buildPriceSetRules(price.price_rules)
|
||||
: {}
|
||||
|
||||
return {
|
||||
...priceSetMoneyAmount,
|
||||
price_set_id: priceSetMoneyAmount.price_set!?.id!,
|
||||
...price,
|
||||
price_set_id: price.price_set!?.id!,
|
||||
rules,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user