chore: merge money amounts and price set money amounts (#6768)

what: 

- merges price set money amounts and money amount
This commit is contained in:
Riqwan Thamir
2024-03-21 17:10:13 +01:00
committed by GitHub
parent 1ef9c78cea
commit b792c4cab5
29 changed files with 569 additions and 1534 deletions

View File

@@ -1,8 +1,8 @@
import { createAdminUser } from "../../../../helpers/create-admin-user"
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
import { simpleSalesChannelFactory } from "../../../../factories"
import { createAdminUser } from "../../../../helpers/create-admin-user"
import productSeeder from "../../../../helpers/product-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { simpleSalesChannelFactory } from "../../../../factories"
jest.setTimeout(50000)
@@ -110,8 +110,6 @@ medusaIntegrationTestRunner({
])
)
console.log(response?.data.product)
expect(response?.data.product.variants).toEqual(
expect.arrayContaining([
expect.objectContaining({

View File

@@ -1,4 +1,4 @@
import { MedusaContainer } from "@medusajs/modules-sdk"
import { MedusaContainer, Modules } from "@medusajs/modules-sdk"
import {
CreatePriceSetDTO,
IPricingModuleService,
@@ -36,15 +36,11 @@ export const createVariantPriceSet = async ({
})
await remoteLink.create({
productService: {
variant_id: variantId,
},
pricingService: {
price_set_id: priceSet.id,
},
[Modules.PRODUCT]: { variant_id: variantId },
[Modules.PRICING]: { price_set_id: priceSet.id },
})
return await pricingModuleService.retrieve(priceSet.id, {
relations: ["price_set_money_amounts.money_amount"],
relations: ["price_set_money_amounts"],
})
}

View File

@@ -13,14 +13,14 @@ export const adminPriceListRemoteQueryFields = [
"created_at",
"updated_at",
"deleted_at",
"price_set_money_amounts.money_amount.id",
"price_set_money_amounts.money_amount.currency_code",
"price_set_money_amounts.money_amount.amount",
"price_set_money_amounts.money_amount.min_quantity",
"price_set_money_amounts.money_amount.max_quantity",
"price_set_money_amounts.money_amount.created_at",
"price_set_money_amounts.money_amount.deleted_at",
"price_set_money_amounts.money_amount.updated_at",
"price_set_money_amounts.id",
"price_set_money_amounts.currency_code",
"price_set_money_amounts.amount",
"price_set_money_amounts.min_quantity",
"price_set_money_amounts.max_quantity",
"price_set_money_amounts.created_at",
"price_set_money_amounts.deleted_at",
"price_set_money_amounts.updated_at",
"price_set_money_amounts.price_set.variant.id",
"price_set_money_amounts.price_rules.value",
"price_set_money_amounts.price_rules.rule_type.rule_attribute",

View File

@@ -17,7 +17,7 @@ export const remapKeysForProduct = (selectFields: string[]) => {
.map((fieldName: string) =>
fieldName.replace(
"variants.prices.",
"variants.price_set.price_set_money_amounts.money_amount."
"variants.price_set.price_set_money_amounts."
)
)
@@ -31,10 +31,7 @@ export const remapKeysForVariant = (selectFields: string[]) => {
const pricingFields = selectFields
.filter((fieldName: string) => isPricing(fieldName))
.map((fieldName: string) =>
fieldName.replace(
"prices.",
"price_set.price_set_money_amounts.money_amount."
)
fieldName.replace("prices.", "price_set.price_set_money_amounts.")
)
return [...variantFields, ...pricingFields]
@@ -51,7 +48,7 @@ export const remapVariant = (v: ProductVariantDTO) => {
return {
...v,
prices: (v as any).price_set?.price_set_money_amounts?.map((psma) => ({
...psma.money_amount,
...psma,
variant_id: v.id,
})),
price_set: undefined,

View File

@@ -284,7 +284,7 @@ class PricingService extends TransactionBaseService {
if (calculatedPrices) {
pricingResult.prices.push({
id: calculatedPrices?.original_price?.money_amount_id,
id: calculatedPrices?.original_price?.id,
currency_code: calculatedPrices.currency_code,
amount: calculatedPrices.original_amount,
min_quantity: calculatedPrices.original_price?.min_quantity,
@@ -293,11 +293,11 @@ class PricingService extends TransactionBaseService {
} as MoneyAmount)
if (
calculatedPrices.calculated_price?.money_amount_id !==
calculatedPrices.original_price?.money_amount_id
calculatedPrices.calculated_price?.id !==
calculatedPrices.original_price?.id
) {
pricingResult.prices.push({
id: calculatedPrices.calculated_price?.money_amount_id,
id: calculatedPrices.calculated_price?.id,
currency_code: calculatedPrices.currency_code,
amount: calculatedPrices.calculated_amount,
min_quantity: calculatedPrices.calculated_price?.min_quantity,

View File

@@ -1,23 +0,0 @@
export const defaultMoneyAmountsData = [
{
id: "money-amount-USD",
currency_code: "USD",
amount: 500,
min_quantity: 1,
max_quantity: 10,
},
{
id: "money-amount-EUR",
currency_code: "EUR",
amount: 400,
min_quantity: 1,
max_quantity: 5,
},
{
id: "money-amount-CAD",
currency_code: "CAD",
amount: 600,
min_quantity: 1,
max_quantity: 8,
},
]

View File

@@ -1,22 +0,0 @@
import { SqlEntityManager } from "@mikro-orm/postgresql"
import { MoneyAmount } from "@models"
import { defaultMoneyAmountsData } from "./data"
export * from "./data"
export async function createMoneyAmounts(
manager: SqlEntityManager,
moneyAmountsData: any[] = defaultMoneyAmountsData
): Promise<MoneyAmount[]> {
const moneyAmounts: MoneyAmount[] = []
for (let moneyAmountData of moneyAmountsData) {
const moneyAmount = manager.create(MoneyAmount, moneyAmountData)
moneyAmounts.push(moneyAmount)
}
await manager.persistAndFlush(moneyAmounts)
return moneyAmounts
}

View File

@@ -1,23 +1,26 @@
export const defaultPriceSetMoneyAmountsData = [
{
id: "price-set-money-amount-USD",
currency_code: "USD",
amount: 500,
title: "price set money amount USD",
price_set_id: "price-set-1",
money_amount_id: "money-amount-USD",
rules_count: 1,
},
{
id: "price-set-money-amount-EUR",
currency_code: "EUR",
amount: 400,
title: "price set money amount EUR",
price_set_id: "price-set-2",
money_amount_id: "money-amount-EUR",
rules_count: 1,
},
{
id: "price-set-money-amount-CAD",
currency_code: "CAD",
amount: 600,
title: "price set money amount CAD",
price_set_id: "price-set-3",
money_amount_id: "money-amount-CAD",
rules_count: 1,
},
]

View File

@@ -13,17 +13,17 @@ export async function createPriceSets(
for (let priceSetData of priceSetsData) {
const priceSetDataClone = { ...priceSetData }
const moneyAmountsData = priceSetDataClone.prices || []
const psmas = priceSetDataClone.prices || []
delete priceSetDataClone.prices
let priceSet = manager.create(PriceSet, priceSetDataClone) as PriceSet
manager.persist(priceSet)
for (let moneyAmount of moneyAmountsData) {
for (let psmaData of psmas) {
const psma = manager.create(PriceSetMoneyAmount, {
price_set: priceSet,
money_amount_id: moneyAmount.id,
...psmaData,
price_set_id: priceSet.id,
title: "test",
})

View File

@@ -1,6 +1,4 @@
import { SqlEntityManager } from "@mikro-orm/postgresql"
import { createMoneyAmounts, defaultMoneyAmountsData } from "./money-amount"
import { createPriceRules, defaultPriceRuleData } from "./price-rule"
import { createPriceSets, defaultPriceSetsData } from "./price-set"
import {
@@ -14,14 +12,12 @@ jest.setTimeout(30000)
export async function seedPriceData(
testManager: SqlEntityManager,
{
moneyAmountsData = defaultMoneyAmountsData,
priceSetsData = defaultPriceSetsData,
priceRuleData = defaultPriceRuleData,
priceSetMoneyAmountsData = defaultPriceSetMoneyAmountsData,
ruleTypesData = defaultRuleTypesData,
} = {}
) {
await createMoneyAmounts(testManager, moneyAmountsData)
await createPriceSets(testManager, priceSetsData)
await createPriceSetMoneyAmounts(testManager, priceSetMoneyAmountsData)
await createRuleTypes(testManager, ruleTypesData)

View File

@@ -59,63 +59,63 @@ moduleIntegrationTestRunner({
beforeEach(async () => {
const moneyAmountsData = [
{
id: "money-amount-PLN",
id: "psma-PLN",
currency_code: "PLN",
amount: 1000,
min_quantity: 1,
max_quantity: 10,
},
{
id: "money-amount-company_id-EUR",
id: "psma-company_id-EUR",
currency_code: "EUR",
amount: 500,
min_quantity: 1,
max_quantity: 10,
},
{
id: "money-amount-company_id-PLN",
id: "psma-company_id-PLN",
currency_code: "PLN",
amount: 400,
min_quantity: 1,
max_quantity: 5,
},
{
id: "money-amount-region_id-PLN",
id: "psma-region_id-PLN",
currency_code: "PLN",
amount: 300,
min_quantity: 1,
max_quantity: 4,
},
{
id: "money-amount-region_id+company_id-PLN",
id: "psma-region_id+company_id-PLN",
currency_code: "PLN",
amount: 999,
min_quantity: 1,
max_quantity: 10,
},
{
id: "money-amount-region_id-PLN-5-qty",
id: "psma-region_id-PLN-5-qty",
currency_code: "PLN",
amount: 250,
min_quantity: 4,
max_quantity: 10,
},
{
id: "money-amount-region_id-PL-EUR",
id: "psma-region_id_company_id-PL-EUR",
currency_code: "EUR",
amount: 200,
min_quantity: 1,
max_quantity: 3,
},
{
id: "money-amount-region_id-PL-EUR-4-qty",
id: "psma-region_id_company_id-PL-EUR-4-qty",
currency_code: "EUR",
amount: 50,
min_quantity: 4,
max_quantity: 10,
},
{
id: "money-amount-region_id-PL-EUR-customer-group",
id: "psma-region_id_company_id-PL-EUR-customer-group",
currency_code: "EUR",
amount: 100,
min_quantity: 1,
@@ -137,56 +137,80 @@ moduleIntegrationTestRunner({
id: "psma-PLN",
title: "psma PLN",
price_set_id: "price-set-PLN",
money_amount_id: "money-amount-PLN",
currency_code: "PLN",
amount: 1000,
min_quantity: 1,
max_quantity: 10,
rules_count: 0,
},
{
id: "psma-company_id-EUR",
title: "psma EUR - company_id",
price_set_id: "price-set-EUR",
money_amount_id: "money-amount-company_id-EUR",
currency_code: "EUR",
amount: 500,
min_quantity: 1,
max_quantity: 10,
rules_count: 1,
},
{
id: "psma-company_id-PLN",
title: "psma PLN - company_id",
price_set_id: "price-set-PLN",
money_amount_id: "money-amount-company_id-PLN",
currency_code: "PLN",
amount: 400,
min_quantity: 1,
max_quantity: 5,
rules_count: 1,
},
{
id: "psma-region_id-PLN",
title: "psma PLN - region_id",
price_set_id: "price-set-PLN",
money_amount_id: "money-amount-region_id-PLN",
currency_code: "PLN",
amount: 300,
min_quantity: 1,
max_quantity: 4,
rules_count: 1,
},
{
id: "psma-region_id+company_id-PLN",
title: "psma region_id + company_id",
price_set_id: "price-set-PLN",
money_amount_id: "money-amount-region_id+company_id-PLN",
currency_code: "PLN",
amount: 999,
min_quantity: 1,
max_quantity: 10,
rules_count: 2,
},
{
id: "psma-region_id-PLN-5-qty",
title: "psma PLN - region_id 5 qty",
price_set_id: "price-set-PLN",
money_amount_id: "money-amount-region_id-PLN-5-qty",
currency_code: "PLN",
amount: 250,
min_quantity: 4,
max_quantity: 10,
rules_count: 1,
},
{
id: "psma-region_id_company_id-PL-EUR",
title: "psma PLN - region_id PL with EUR currency",
price_set_id: "price-set-PLN",
money_amount_id: "money-amount-region_id-PL-EUR",
currency_code: "EUR",
amount: 200,
min_quantity: 1,
max_quantity: 3,
rules_count: 2,
},
{
id: "psma-region_id_company_id-PL-EUR-4-qty",
title: "psma PLN - region_id PL with EUR currency for quantity 4",
price_set_id: "price-set-PLN",
money_amount_id: "money-amount-region_id-PL-EUR-4-qty",
currency_code: "EUR",
amount: 50,
min_quantity: 4,
max_quantity: 10,
rules_count: 2,
},
{
@@ -194,7 +218,10 @@ moduleIntegrationTestRunner({
title:
"psma PLN - region_id PL with EUR currency for customer group",
price_set_id: "price-set-PLN",
money_amount_id: "money-amount-region_id-PL-EUR-customer-group",
currency_code: "EUR",
amount: 100,
min_quantity: 1,
max_quantity: 3,
rules_count: 3,
},
]
@@ -378,14 +405,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -400,14 +427,14 @@ moduleIntegrationTestRunner({
original_amount: 1000,
currency_code: "PLN",
calculated_price: {
money_amount_id: "money-amount-PLN",
id: "psma-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
max_quantity: 10,
},
original_price: {
money_amount_id: "money-amount-PLN",
id: "psma-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
@@ -434,14 +461,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -456,14 +483,14 @@ moduleIntegrationTestRunner({
original_amount: 300,
currency_code: "PLN",
calculated_price: {
money_amount_id: "money-amount-region_id-PLN",
id: "psma-region_id-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
max_quantity: 4,
},
original_price: {
money_amount_id: "money-amount-region_id-PLN",
id: "psma-region_id-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
@@ -490,14 +517,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -512,14 +539,14 @@ moduleIntegrationTestRunner({
original_amount: 1000,
currency_code: "PLN",
calculated_price: {
money_amount_id: "money-amount-PLN",
id: "psma-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
max_quantity: 10,
},
original_price: {
money_amount_id: "money-amount-PLN",
id: "psma-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
@@ -546,14 +573,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -568,14 +595,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -602,14 +629,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -624,14 +651,14 @@ moduleIntegrationTestRunner({
original_amount: 300,
currency_code: "PLN",
calculated_price: {
money_amount_id: "money-amount-region_id-PLN",
id: "psma-region_id-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
max_quantity: 4,
},
original_price: {
money_amount_id: "money-amount-region_id-PLN",
id: "psma-region_id-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
@@ -658,14 +685,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -680,14 +707,14 @@ moduleIntegrationTestRunner({
original_amount: 1000,
currency_code: "PLN",
calculated_price: {
money_amount_id: "money-amount-PLN",
id: "psma-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
max_quantity: 10,
},
original_price: {
money_amount_id: "money-amount-PLN",
id: "psma-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
@@ -714,14 +741,14 @@ moduleIntegrationTestRunner({
original_amount: 250,
currency_code: "PLN",
calculated_price: {
money_amount_id: "money-amount-region_id-PLN-5-qty",
id: "psma-region_id-PLN-5-qty",
price_list_id: null,
price_list_type: null,
min_quantity: 4,
max_quantity: 10,
},
original_price: {
money_amount_id: "money-amount-region_id-PLN-5-qty",
id: "psma-region_id-PLN-5-qty",
price_list_id: null,
price_list_type: null,
min_quantity: 4,
@@ -753,14 +780,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -775,14 +802,14 @@ moduleIntegrationTestRunner({
original_amount: 300,
currency_code: "PLN",
calculated_price: {
money_amount_id: "money-amount-region_id-PLN",
id: "psma-region_id-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
max_quantity: 4,
},
original_price: {
money_amount_id: "money-amount-region_id-PLN",
id: "psma-region_id-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
@@ -814,14 +841,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -837,14 +864,14 @@ moduleIntegrationTestRunner({
original_amount: 100,
currency_code: "EUR",
calculated_price: {
money_amount_id: "money-amount-region_id-PL-EUR-customer-group",
id: "psma-region_id_company_id-PL-EUR-customer-group",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
max_quantity: 3,
},
original_price: {
money_amount_id: "money-amount-region_id-PL-EUR-customer-group",
id: "psma-region_id_company_id-PL-EUR-customer-group",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
@@ -876,14 +903,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -899,14 +926,14 @@ moduleIntegrationTestRunner({
original_amount: 300,
currency_code: "PLN",
calculated_price: {
money_amount_id: "money-amount-region_id-PLN",
id: "psma-region_id-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
max_quantity: 4,
},
original_price: {
money_amount_id: "money-amount-region_id-PLN",
id: "psma-region_id-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
@@ -938,14 +965,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -961,14 +988,14 @@ moduleIntegrationTestRunner({
original_amount: 1000,
currency_code: "PLN",
calculated_price: {
money_amount_id: "money-amount-PLN",
id: "psma-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
max_quantity: 10,
},
original_price: {
money_amount_id: "money-amount-PLN",
id: "psma-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
@@ -995,14 +1022,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -1017,14 +1044,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -1055,14 +1082,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -1077,14 +1104,14 @@ moduleIntegrationTestRunner({
original_amount: 300,
currency_code: "PLN",
calculated_price: {
money_amount_id: "money-amount-region_id-PLN",
id: "psma-region_id-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
max_quantity: 4,
},
original_price: {
money_amount_id: "money-amount-region_id-PLN",
id: "psma-region_id-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
@@ -1119,14 +1146,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -1141,14 +1168,14 @@ moduleIntegrationTestRunner({
original_amount: 400,
currency_code: "PLN",
calculated_price: {
money_amount_id: expect.any(String),
id: expect.any(String),
price_list_id: expect.any(String),
price_list_type: "sale",
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: expect.any(String),
id: expect.any(String),
price_list_id: null,
price_list_type: null,
min_quantity: 1,
@@ -1190,14 +1217,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -1212,14 +1239,14 @@ moduleIntegrationTestRunner({
original_amount: 400,
currency_code: "PLN",
calculated_price: {
money_amount_id: expect.any(String),
id: expect.any(String),
price_list_id: expect.any(String),
price_list_type: "sale",
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: expect.any(String),
id: expect.any(String),
price_list_id: null,
price_list_type: null,
min_quantity: 1,
@@ -1253,14 +1280,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -1275,14 +1302,14 @@ moduleIntegrationTestRunner({
original_amount: 400,
currency_code: "PLN",
calculated_price: {
money_amount_id: expect.any(String),
id: expect.any(String),
price_list_id: expect.any(String),
price_list_type: "sale",
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: expect.any(String),
id: expect.any(String),
price_list_id: null,
price_list_type: null,
min_quantity: 1,
@@ -1313,14 +1340,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -1335,14 +1362,14 @@ moduleIntegrationTestRunner({
original_amount: 1000,
currency_code: "PLN",
calculated_price: {
money_amount_id: expect.any(String),
id: expect.any(String),
price_list_id: expect.any(String),
price_list_type: "sale",
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: expect.any(String),
id: expect.any(String),
price_list_id: null,
price_list_type: null,
min_quantity: 1,
@@ -1376,14 +1403,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -1398,14 +1425,14 @@ moduleIntegrationTestRunner({
original_amount: 232,
currency_code: "PLN",
calculated_price: {
money_amount_id: expect.any(String),
id: expect.any(String),
price_list_id: expect.any(String),
price_list_type: "override",
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: expect.any(String),
id: expect.any(String),
price_list_id: expect.any(String),
price_list_type: "override",
min_quantity: null,
@@ -1438,14 +1465,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -1460,14 +1487,14 @@ moduleIntegrationTestRunner({
original_amount: 300,
currency_code: "PLN",
calculated_price: {
money_amount_id: "money-amount-region_id-PLN",
id: "psma-region_id-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
max_quantity: 4,
},
original_price: {
money_amount_id: "money-amount-region_id-PLN",
id: "psma-region_id-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
@@ -1500,14 +1527,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -1522,14 +1549,14 @@ moduleIntegrationTestRunner({
original_amount: 300,
currency_code: "PLN",
calculated_price: {
money_amount_id: expect.any(String),
id: expect.any(String),
price_list_id: null,
price_list_type: null,
min_quantity: 1,
max_quantity: 4,
},
original_price: {
money_amount_id: expect.any(String),
id: expect.any(String),
price_list_id: null,
price_list_type: null,
min_quantity: 1,
@@ -1575,14 +1602,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -1597,14 +1624,14 @@ moduleIntegrationTestRunner({
original_amount: 400,
currency_code: "PLN",
calculated_price: {
money_amount_id: expect.any(String),
id: expect.any(String),
price_list_id: expect.any(String),
price_list_type: "sale",
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: expect.any(String),
id: expect.any(String),
price_list_id: null,
price_list_type: null,
min_quantity: 1,
@@ -1651,14 +1678,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -1673,14 +1700,14 @@ moduleIntegrationTestRunner({
original_amount: 400,
currency_code: "PLN",
calculated_price: {
money_amount_id: "money-amount-company_id-PLN",
id: "psma-company_id-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
max_quantity: 5,
},
original_price: {
money_amount_id: "money-amount-company_id-PLN",
id: "psma-company_id-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
@@ -1726,14 +1753,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -1748,14 +1775,14 @@ moduleIntegrationTestRunner({
original_amount: 400,
currency_code: "PLN",
calculated_price: {
money_amount_id: "money-amount-company_id-PLN",
id: "psma-company_id-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
max_quantity: 5,
},
original_price: {
money_amount_id: "money-amount-company_id-PLN",
id: "psma-company_id-PLN",
price_list_id: null,
price_list_type: null,
min_quantity: 1,
@@ -1803,14 +1830,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: "EUR",
calculated_price: {
money_amount_id: expect.any(String),
id: expect.any(String),
price_list_id: id,
price_list_type: "sale",
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -1854,14 +1881,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -1876,14 +1903,14 @@ moduleIntegrationTestRunner({
original_amount: 400,
currency_code: "PLN",
calculated_price: {
money_amount_id: expect.any(String),
id: expect.any(String),
price_list_id: expect.any(String),
price_list_type: "sale",
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: expect.any(String),
id: expect.any(String),
price_list_id: null,
price_list_type: null,
min_quantity: 1,
@@ -1927,14 +1954,14 @@ moduleIntegrationTestRunner({
original_amount: null,
currency_code: null,
calculated_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: null,
id: null,
price_list_id: null,
price_list_type: null,
min_quantity: null,
@@ -1949,14 +1976,14 @@ moduleIntegrationTestRunner({
original_amount: 400,
currency_code: "PLN",
calculated_price: {
money_amount_id: expect.any(String),
id: expect.any(String),
price_list_id: expect.any(String),
price_list_type: "sale",
min_quantity: null,
max_quantity: null,
},
original_price: {
money_amount_id: expect.any(String),
id: expect.any(String),
price_list_id: null,
price_list_type: null,
min_quantity: 1,

View File

@@ -1,411 +0,0 @@
import { Modules } from "@medusajs/modules-sdk"
import { IPricingModuleService } from "@medusajs/types"
import { SqlEntityManager } from "@mikro-orm/postgresql"
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
import { createMoneyAmounts } from "../../../__fixtures__/money-amount"
import { createPriceRules } from "../../../__fixtures__/price-rule"
import { createPriceSets } from "../../../__fixtures__/price-set"
import { createPriceSetMoneyAmounts } from "../../../__fixtures__/price-set-money-amount"
import { createRuleTypes } from "../../../__fixtures__/rule-type"
jest.setTimeout(30000)
moduleIntegrationTestRunner({
moduleName: Modules.PRICING,
testSuite: ({
MikroOrmWrapper,
service,
}: SuiteOptions<IPricingModuleService>) => {
describe("PricingModule Service - MoneyAmount", () => {
let testManager: SqlEntityManager
beforeEach(async () => {
testManager = await MikroOrmWrapper.forkManager()
await createMoneyAmounts(testManager)
})
describe("listMoneyAmounts", () => {
it("list moneyAmounts", async () => {
const moneyAmountsResult = await service.listMoneyAmounts()
expect(moneyAmountsResult).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: "money-amount-USD",
amount: 500,
}),
expect.objectContaining({
id: "money-amount-EUR",
amount: 400,
}),
expect.objectContaining({
id: "money-amount-CAD",
amount: 600,
}),
])
)
})
it("should list moneyAmounts by id", async () => {
const moneyAmountsResult = await service.listMoneyAmounts({
id: ["money-amount-USD"],
})
expect(moneyAmountsResult).toEqual([
expect.objectContaining({
id: "money-amount-USD",
}),
])
})
it("should list moneyAmounts with relations and selects", async () => {
const moneyAmountsResult = await service.listMoneyAmounts(
{
id: ["money-amount-USD"],
},
{
select: ["id", "min_quantity", "currency_code"],
}
)
const serialized = JSON.parse(JSON.stringify(moneyAmountsResult))
expect(serialized).toEqual([
{
id: "money-amount-USD",
amount: null,
min_quantity: "1",
currency_code: "USD",
},
])
})
})
describe("listAndCountMoneyAmounts", () => {
it("should return moneyAmounts and count", async () => {
const [moneyAmountsResult, count] =
await service.listAndCountMoneyAmounts()
expect(count).toEqual(3)
expect(moneyAmountsResult).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: "money-amount-USD",
}),
expect.objectContaining({
id: "money-amount-EUR",
}),
expect.objectContaining({
id: "money-amount-CAD",
}),
])
)
})
it("should return moneyAmounts and count when filtered", async () => {
const [moneyAmountsResult, count] =
await service.listAndCountMoneyAmounts({
id: ["money-amount-USD"],
})
expect(count).toEqual(1)
expect(moneyAmountsResult).toEqual([
expect.objectContaining({
id: "money-amount-USD",
}),
])
})
it("list moneyAmounts with relations and selects", async () => {
const [moneyAmountsResult, count] =
await service.listAndCountMoneyAmounts(
{
id: ["money-amount-USD"],
},
{
select: ["id", "min_quantity", "currency_code", "amount"],
}
)
const serialized = JSON.parse(JSON.stringify(moneyAmountsResult))
expect(count).toEqual(1)
expect(serialized).toEqual([
{
id: "money-amount-USD",
amount: 500,
min_quantity: "1",
currency_code: "USD",
},
])
})
it("should return moneyAmounts and count when using skip and take", async () => {
const [moneyAmountsResult, count] =
await service.listAndCountMoneyAmounts({}, { skip: 1, take: 1 })
expect(count).toEqual(3)
expect(moneyAmountsResult).toEqual([
expect.objectContaining({
id: "money-amount-EUR",
}),
])
})
it("should return requested fields", async () => {
const [moneyAmountsResult, count] =
await service.listAndCountMoneyAmounts(
{},
{
take: 1,
select: ["id"],
}
)
const serialized = JSON.parse(JSON.stringify(moneyAmountsResult))
expect(count).toEqual(3)
expect(serialized).toEqual([
{
id: "money-amount-CAD",
amount: null,
},
])
})
})
describe("retrieveMoneyAmount", () => {
const id = "money-amount-USD"
const amount = 500
it("should return moneyAmount for the given id", async () => {
const moneyAmount = await service.retrieveMoneyAmount(id)
expect(moneyAmount).toEqual(
expect.objectContaining({
id,
})
)
})
it("should throw an error when moneyAmount with id does not exist", async () => {
let error
try {
await service.retrieveMoneyAmount("does-not-exist")
} catch (e) {
error = e
}
expect(error.message).toEqual(
"MoneyAmount with id: does-not-exist was not found"
)
})
it("should throw an error when a id is not provided", async () => {
let error
try {
await service.retrieveMoneyAmount(undefined as unknown as string)
} catch (e) {
error = e
}
expect(error.message).toEqual("moneyAmount - id must be defined")
})
it("should return moneyAmount based on config select param", async () => {
const moneyAmount = await service.retrieveMoneyAmount(id, {
select: ["id", "amount"],
})
const serialized = JSON.parse(JSON.stringify(moneyAmount))
expect(serialized).toEqual({
id,
amount,
})
})
})
describe("deleteMoneyAmounts", () => {
const id = "money-amount-USD"
it("should delete the moneyAmounts given an id successfully", async () => {
await service.deleteMoneyAmounts([id])
const moneyAmounts = await service.listMoneyAmounts({
id: [id],
})
expect(moneyAmounts).toHaveLength(0)
})
})
describe("softDeleteMoneyAmounts", () => {
const id = "money-amount-USD"
it("should softDelete money amounts successfully", async () => {
await createPriceSets(testManager)
await createRuleTypes(testManager)
await createPriceSetMoneyAmounts(testManager)
await createPriceRules(testManager)
await service.softDeleteMoneyAmounts([id])
const [moneyAmount] = await service.listMoneyAmounts(
{ id: [id] },
{
relations: [
"price_set_money_amount",
"price_set_money_amount.price_rules",
],
withDeleted: true,
}
)
expect(moneyAmount).toBeTruthy()
const deletedAt = moneyAmount.deleted_at
expect(moneyAmount).toEqual(
expect.objectContaining({
deleted_at: deletedAt,
price_set_money_amount: expect.objectContaining({
deleted_at: null,
price_rules: [
expect.objectContaining({
deleted_at: null,
}),
],
}),
})
)
})
})
describe("restoreMoneyAmounts", () => {
const id = "money-amount-USD"
it("should restore softDeleted priceSetMoneyAmount and PriceRule when restoring soft-deleting money amount", async () => {
await createPriceSets(testManager)
await createRuleTypes(testManager)
await createPriceSetMoneyAmounts(testManager)
await createPriceRules(testManager)
await service.softDeleteMoneyAmounts([id])
await service.restoreMoneyAmounts([id])
const [moneyAmount] = await service.listMoneyAmounts(
{
id: [id],
},
{
relations: [
"price_set_money_amount",
"price_set_money_amount.price_rules",
],
}
)
expect(moneyAmount).toBeTruthy()
const deletedAt = null
expect(moneyAmount).toEqual(
expect.objectContaining({
deleted_at: deletedAt,
price_set_money_amount: expect.objectContaining({
deleted_at: deletedAt,
price_rules: [
expect.objectContaining({
deleted_at: deletedAt,
}),
],
}),
})
)
})
})
describe("updateMoneyAmounts", () => {
const id = "money-amount-USD"
it("should update the amount of the moneyAmount successfully", async () => {
await service.updateMoneyAmounts([
{
id,
amount: 700,
},
])
const moneyAmount = JSON.parse(
JSON.stringify(
await service.retrieveMoneyAmount(id, { select: ["amount"] })
)
)
expect(moneyAmount.amount).toEqual(700)
})
it("should update the currency of the moneyAmount successfully", async () => {
await service.updateMoneyAmounts([
{
id,
currency_code: "EUR",
},
])
const moneyAmount = await service.retrieveMoneyAmount(id, {})
expect(moneyAmount.currency_code).toEqual("EUR")
})
it("should throw an error when a id does not exist", async () => {
let error
try {
await service.updateMoneyAmounts([
{
id: "does-not-exist",
amount: 666,
},
])
} catch (e) {
error = e
}
expect(error.message).toEqual(
'MoneyAmount with id "does-not-exist" not found'
)
})
})
describe("createMoneyAmounts", () => {
it("should create a moneyAmount successfully", async () => {
await service.createMoneyAmounts([
{
id: "money-amount-TESM",
currency_code: "USD",
amount: 333,
min_quantity: 1,
max_quantity: 4,
},
])
const [moneyAmount] = await service.listMoneyAmounts({
id: ["money-amount-TESM"],
})
expect(moneyAmount).toEqual(
expect.objectContaining({
id: "money-amount-TESM",
currency_code: "USD",
amount: 333,
min_quantity: "1",
max_quantity: "4",
})
)
})
})
})
},
})

View File

@@ -270,12 +270,10 @@ moduleIntegrationTestRunner({
])
const [priceList] = await service.listPriceLists(
{
id: [createdId],
},
{ id: [createdId] },
{
relations: [
"price_set_money_amounts.money_amount",
"price_set_money_amounts",
"price_set_money_amounts.price_set",
"price_list_rules.price_list_rule_values",
"price_list_rules.rule_type",
@@ -283,9 +281,9 @@ moduleIntegrationTestRunner({
select: [
"id",
"starts_at",
"price_set_money_amounts.money_amount.amount",
"price_set_money_amounts.money_amount.currency_code",
"price_set_money_amounts.money_amount.price_list_id",
"price_set_money_amounts.amount",
"price_set_money_amounts.currency_code",
"price_set_money_amounts.price_list_id",
"price_list_rules.price_list_rule_values.value",
"price_list_rules.rule_type.rule_attribute",
],
@@ -301,10 +299,8 @@ moduleIntegrationTestRunner({
price_list: expect.objectContaining({
id: expect.any(String),
}),
money_amount: expect.objectContaining({
amount: 400,
currency_code: "EUR",
}),
amount: 400,
currency_code: "EUR",
}),
]),
price_list_rules: expect.arrayContaining([
@@ -432,16 +428,16 @@ moduleIntegrationTestRunner({
},
{
relations: [
"price_set_money_amounts.money_amount",
"price_set_money_amounts",
"price_set_money_amounts.price_set",
"price_list_rules.price_list_rule_values",
"price_list_rules.rule_type",
],
select: [
"id",
"price_set_money_amounts.money_amount.amount",
"price_set_money_amounts.money_amount.currency_code",
"price_set_money_amounts.money_amount.price_list_id",
"price_set_money_amounts.amount",
"price_set_money_amounts.currency_code",
"price_set_money_amounts.price_list_id",
"price_list_rules.price_list_rule_values.value",
"price_list_rules.rule_type.rule_attribute",
],
@@ -456,10 +452,8 @@ moduleIntegrationTestRunner({
price_list: expect.objectContaining({
id: expect.any(String),
}),
money_amount: expect.objectContaining({
amount: 400,
currency_code: "EUR",
}),
amount: 400,
currency_code: "EUR",
}),
]),
price_list_rules: expect.arrayContaining([
@@ -540,7 +534,7 @@ moduleIntegrationTestRunner({
},
{
relations: [
"price_set_money_amounts.money_amount",
"price_set_money_amounts",
"price_set_money_amounts.price_set",
"price_set_money_amounts.price_rules",
"price_list_rules.price_list_rule_values",
@@ -550,9 +544,9 @@ moduleIntegrationTestRunner({
"id",
"price_set_money_amounts.price_rules.value",
"price_set_money_amounts.rules_count",
"price_set_money_amounts.money_amount.amount",
"price_set_money_amounts.money_amount.currency_code",
"price_set_money_amounts.money_amount.price_list_id",
"price_set_money_amounts.amount",
"price_set_money_amounts.currency_code",
"price_set_money_amounts.price_list_id",
"price_list_rules.price_list_rule_values.value",
"price_list_rules.rule_type.rule_attribute",
],
@@ -574,10 +568,8 @@ moduleIntegrationTestRunner({
price_list: expect.objectContaining({
id: expect.any(String),
}),
money_amount: expect.objectContaining({
amount: 400,
currency_code: "EUR",
}),
amount: 400,
currency_code: "EUR",
}),
expect.objectContaining({
rules_count: 0,
@@ -585,10 +577,8 @@ moduleIntegrationTestRunner({
price_list: expect.objectContaining({
id: expect.any(String),
}),
money_amount: expect.objectContaining({
amount: 600,
currency_code: "EUR",
}),
amount: 600,
currency_code: "EUR",
}),
]),
price_list_rules: expect.arrayContaining([
@@ -683,7 +673,7 @@ moduleIntegrationTestRunner({
},
{
relations: [
"price_set_money_amounts.money_amount",
"price_set_money_amounts",
"price_set_money_amounts.price_set",
"price_set_money_amounts.price_rules",
"price_list_rules.price_list_rule_values",
@@ -693,9 +683,9 @@ moduleIntegrationTestRunner({
"id",
"price_set_money_amounts.price_rules.value",
"price_set_money_amounts.rules_count",
"price_set_money_amounts.money_amount.amount",
"price_set_money_amounts.money_amount.currency_code",
"price_set_money_amounts.money_amount.price_list_id",
"price_set_money_amounts.amount",
"price_set_money_amounts.currency_code",
"price_set_money_amounts.price_list_id",
"price_list_rules.price_list_rule_values.value",
"price_list_rules.rule_type.rule_attribute",
],
@@ -711,10 +701,8 @@ moduleIntegrationTestRunner({
price_list: expect.objectContaining({
id: expect.any(String),
}),
money_amount: expect.objectContaining({
amount: 123,
currency_code: "EUR",
}),
amount: 123,
currency_code: "EUR",
}),
]),
price_list_rules: [],
@@ -794,7 +782,7 @@ moduleIntegrationTestRunner({
},
{
relations: [
"price_set_money_amounts.money_amount",
"price_set_money_amounts",
"price_set_money_amounts.price_set",
"price_set_money_amounts.price_rules",
"price_set_money_amounts.price_rules.rule_type",
@@ -806,9 +794,9 @@ moduleIntegrationTestRunner({
"price_set_money_amounts.price_rules.value",
"price_set_money_amounts.price_rules.rule_type.rule_attribute",
"price_set_money_amounts.rules_count",
"price_set_money_amounts.money_amount.amount",
"price_set_money_amounts.money_amount.currency_code",
"price_set_money_amounts.money_amount.price_list_id",
"price_set_money_amounts.amount",
"price_set_money_amounts.currency_code",
"price_set_money_amounts.price_list_id",
"price_list_rules.price_list_rule_values.value",
"price_list_rules.rule_type.rule_attribute",
],
@@ -832,10 +820,8 @@ moduleIntegrationTestRunner({
}),
}),
],
money_amount: expect.objectContaining({
amount: 123,
currency_code: "EUR",
}),
amount: 123,
currency_code: "EUR",
}),
]),
price_list_rules: [],
@@ -892,7 +878,7 @@ moduleIntegrationTestRunner({
{ id: ["price-list-1"] },
{
relations: [
"price_set_money_amounts.money_amount",
"price_set_money_amounts",
"price_set_money_amounts.price_set",
"price_set_money_amounts.price_rules",
"price_set_money_amounts.price_rules.rule_type",
@@ -904,9 +890,9 @@ moduleIntegrationTestRunner({
"price_set_money_amounts.price_rules.value",
"price_set_money_amounts.price_rules.rule_type.rule_attribute",
"price_set_money_amounts.rules_count",
"price_set_money_amounts.money_amount.amount",
"price_set_money_amounts.money_amount.currency_code",
"price_set_money_amounts.money_amount.price_list_id",
"price_set_money_amounts.amount",
"price_set_money_amounts.currency_code",
"price_set_money_amounts.price_list_id",
"price_list_rules.price_list_rule_values.value",
"price_list_rules.rule_type.rule_attribute",
],
@@ -936,10 +922,8 @@ moduleIntegrationTestRunner({
price_list: expect.objectContaining({
id: expect.any(String),
}),
money_amount: expect.objectContaining({
amount: 123,
currency_code: "EUR",
}),
amount: 123,
currency_code: "EUR",
}),
]),
price_list_rules: [],

View File

@@ -3,7 +3,6 @@ import { CreatePriceRuleDTO, IPricingModuleService } from "@medusajs/types"
import { SqlEntityManager } from "@mikro-orm/postgresql"
import { SuiteOptions, moduleIntegrationTestRunner } from "medusa-test-utils"
import { PriceSetMoneyAmount } from "../../../../src"
import { createMoneyAmounts } from "../../../__fixtures__/money-amount"
import { createPriceRules } from "../../../__fixtures__/price-rule"
import { createPriceSets } from "../../../__fixtures__/price-set"
import { createPriceSetMoneyAmounts } from "../../../__fixtures__/price-set-money-amount"
@@ -22,7 +21,6 @@ moduleIntegrationTestRunner({
beforeEach(async () => {
testManager = await MikroOrmWrapper.forkManager()
await createMoneyAmounts(testManager)
await createPriceSets(testManager)
await createRuleTypes(testManager)
await createPriceSetMoneyAmounts(testManager)
@@ -274,18 +272,12 @@ moduleIntegrationTestRunner({
})
it("should create a PriceRule successfully", async () => {
const [ma] = await createMoneyAmounts(testManager, [
{
amount: 100,
currency_code: "EUR",
},
])
const psma: PriceSetMoneyAmount = testManager.create(
PriceSetMoneyAmount,
{
currency_code: "EUR",
amount: 100,
price_set_id: "price-set-1",
money_amount_id: ma.id,
title: "test",
rules_count: 0,
}

View File

@@ -86,10 +86,10 @@ moduleIntegrationTestRunner({
{
select: [
"id",
"price_set_money_amounts.money_amount.id",
"price_set_money_amounts.money_amount.amount",
"price_set_money_amounts.id",
"price_set_money_amounts.amount",
],
relations: ["price_set_money_amounts.money_amount"],
relations: ["price_set_money_amounts"],
}
)
@@ -100,10 +100,8 @@ moduleIntegrationTestRunner({
id: "price-set-1",
price_set_money_amounts: [
expect.objectContaining({
money_amount: expect.objectContaining({
id: "money-amount-USD",
amount: 500,
}),
id: "price-set-money-amount-USD",
amount: 500,
}),
],
},
@@ -148,8 +146,12 @@ moduleIntegrationTestRunner({
id: ["price-set-1"],
},
{
select: ["id", "min_quantity", "money_amounts.id"],
relations: ["price_set_money_amounts.money_amount"],
select: [
"id",
"price_set_money_amounts.amount",
"price_set_money_amounts.id",
],
relations: ["price_set_money_amounts"],
}
)
@@ -161,9 +163,8 @@ moduleIntegrationTestRunner({
id: "price-set-1",
price_set_money_amounts: [
expect.objectContaining({
money_amount: expect.objectContaining({
id: "money-amount-USD",
}),
id: "price-set-money-amount-USD",
amount: 500,
}),
],
},
@@ -380,10 +381,9 @@ moduleIntegrationTestRunner({
],
price_set_money_amounts: [
expect.objectContaining({
money_amount: expect.objectContaining({
amount: 100,
currency_code: "USD",
}),
amount: 100,
currency_code: "USD",
rules_count: 1,
}),
],
})
@@ -419,16 +419,12 @@ moduleIntegrationTestRunner({
],
price_set_money_amounts: expect.arrayContaining([
expect.objectContaining({
money_amount: expect.objectContaining({
amount: 100,
currency_code: "USD",
}),
amount: 100,
currency_code: "USD",
}),
expect.objectContaining({
money_amount: expect.objectContaining({
amount: 150,
currency_code: "USD",
}),
amount: 150,
currency_code: "USD",
}),
]),
})
@@ -460,10 +456,8 @@ moduleIntegrationTestRunner({
],
price_set_money_amounts: [
expect.objectContaining({
money_amount: expect.objectContaining({
amount: 100,
currency_code: "USD",
}),
amount: 100,
currency_code: "USD",
}),
],
price_rules: [
@@ -540,7 +534,7 @@ moduleIntegrationTestRunner({
{
relations: [
"rule_types",
"price_set_money_amounts.money_amount",
"price_set_money_amounts",
"price_rules",
],
}
@@ -560,10 +554,8 @@ moduleIntegrationTestRunner({
],
price_set_money_amounts: [
expect.objectContaining({
money_amount: expect.objectContaining({
amount: 500,
currency_code: "EUR",
}),
amount: 500,
currency_code: "EUR",
}),
],
rule_types: [
@@ -625,7 +617,7 @@ moduleIntegrationTestRunner({
const [priceSet] = await service.list(
{ id: ["price-set-1"] },
{ relations: ["price_set_money_amounts.money_amount"] }
{ relations: ["price_set_money_amounts"] }
)
expect(priceSet).toEqual(
@@ -633,10 +625,8 @@ moduleIntegrationTestRunner({
id: "price-set-1",
price_set_money_amounts: expect.arrayContaining([
expect.objectContaining({
money_amount: expect.objectContaining({
amount: 100,
currency_code: "USD",
}),
amount: 100,
currency_code: "USD",
}),
]),
})
@@ -669,7 +659,7 @@ moduleIntegrationTestRunner({
const priceSets = await service.list(
{ id: ["price-set-1", "price-set-2"] },
{ relations: ["price_set_money_amounts.money_amount"] }
{ relations: ["price_set_money_amounts"] }
)
expect(priceSets).toEqual([
@@ -677,10 +667,8 @@ moduleIntegrationTestRunner({
id: "price-set-1",
price_set_money_amounts: expect.arrayContaining([
expect.objectContaining({
money_amount: expect.objectContaining({
amount: 100,
currency_code: "USD",
}),
amount: 100,
currency_code: "USD",
}),
]),
}),
@@ -688,10 +676,8 @@ moduleIntegrationTestRunner({
id: "price-set-2",
price_set_money_amounts: expect.arrayContaining([
expect.objectContaining({
money_amount: expect.objectContaining({
amount: 150,
currency_code: "EUR",
}),
amount: 150,
currency_code: "EUR",
}),
]),
}),

View File

@@ -1,11 +1,10 @@
import { Modules } from "@medusajs/modules-sdk"
import { ModuleJoinerConfig } from "@medusajs/types"
import { MapToConfig } from "@medusajs/utils"
import { MoneyAmount, PriceList, PriceSet, PriceSetMoneyAmount } from "@models"
import { PriceList, PriceSet, PriceSetMoneyAmount } from "@models"
import schema from "./schema"
export const LinkableKeys = {
money_amount_id: MoneyAmount.name,
price_set_id: PriceSet.name,
price_list_id: PriceList.name,
price_set_money_amount_id: PriceSetMoneyAmount.name,
@@ -34,13 +33,6 @@ export const joinerConfig: ModuleJoinerConfig = {
entity: "PriceSet",
},
},
{
name: ["money_amount", "money_amounts"],
args: {
methodSuffix: "MoneyAmounts",
entity: "MoneyAmount",
},
},
{
name: ["price_list", "price_lists"],
args: {

View File

@@ -1,5 +1,7 @@
{
"namespaces": ["public"],
"namespaces": [
"public"
],
"name": "public",
"tables": [
{
@@ -87,7 +89,9 @@
"indexes": [
{
"keyName": "IDX_money_amount_currency_code",
"columnNames": ["currency_code"],
"columnNames": [
"currency_code"
],
"composite": false,
"primary": false,
"unique": false,
@@ -95,7 +99,9 @@
},
{
"keyName": "IDX_money_amount_deleted_at",
"columnNames": ["deleted_at"],
"columnNames": [
"deleted_at"
],
"composite": false,
"primary": false,
"unique": false,
@@ -103,7 +109,9 @@
},
{
"keyName": "money_amount_pkey",
"columnNames": ["id"],
"columnNames": [
"id"
],
"composite": false,
"primary": true,
"unique": true
@@ -149,7 +157,10 @@
"primary": false,
"nullable": false,
"default": "'draft'",
"enumItems": ["active", "draft"],
"enumItems": [
"active",
"draft"
],
"mappedType": "enum"
},
"type": {
@@ -160,7 +171,10 @@
"primary": false,
"nullable": false,
"default": "'sale'",
"enumItems": ["sale", "override"],
"enumItems": [
"sale",
"override"
],
"mappedType": "enum"
},
"starts_at": {
@@ -231,7 +245,9 @@
"indexes": [
{
"keyName": "IDX_price_list_deleted_at",
"columnNames": ["deleted_at"],
"columnNames": [
"deleted_at"
],
"composite": false,
"primary": false,
"unique": false,
@@ -239,7 +255,9 @@
},
{
"keyName": "price_list_pkey",
"columnNames": ["id"],
"columnNames": [
"id"
],
"composite": false,
"primary": true,
"unique": true
@@ -297,7 +315,9 @@
"indexes": [
{
"keyName": "IDX_price_set_deleted_at",
"columnNames": ["deleted_at"],
"columnNames": [
"deleted_at"
],
"composite": false,
"primary": false,
"unique": false,
@@ -305,7 +325,9 @@
},
{
"keyName": "price_set_pkey",
"columnNames": ["id"],
"columnNames": [
"id"
],
"composite": false,
"primary": true,
"unique": true
@@ -334,8 +356,8 @@
"nullable": true,
"mappedType": "text"
},
"price_set_id": {
"name": "price_set_id",
"currency_code": {
"name": "currency_code",
"type": "text",
"unsigned": false,
"autoincrement": false,
@@ -343,8 +365,35 @@
"nullable": false,
"mappedType": "text"
},
"money_amount_id": {
"name": "money_amount_id",
"amount": {
"name": "amount",
"type": "numeric",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "decimal"
},
"min_quantity": {
"name": "min_quantity",
"type": "numeric",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "decimal"
},
"max_quantity": {
"name": "max_quantity",
"type": "numeric",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "decimal"
},
"price_set_id": {
"name": "price_set_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
@@ -408,31 +457,30 @@
"schema": "public",
"indexes": [
{
"columnNames": ["money_amount_id"],
"keyName": "IDX_price_set_money_amount_currency_code",
"columnNames": [
"currency_code"
],
"composite": false,
"keyName": "price_set_money_amount_money_amount_id_unique",
"primary": false,
"unique": true
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_set_money_amount_currency_code\" ON \"price_set_money_amount\" (currency_code) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_price_set_money_amount_price_set_id",
"columnNames": ["price_set_id"],
"columnNames": [
"price_set_id"
],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_set_money_amount_price_set_id\" ON \"price_set_money_amount\" (price_set_id) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_price_set_money_amount_money_amount_id",
"columnNames": ["money_amount_id"],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_set_money_amount_money_amount_id\" ON \"price_set_money_amount\" (money_amount_id) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_price_set_money_amount_price_list_id",
"columnNames": ["price_list_id"],
"columnNames": [
"price_list_id"
],
"composite": false,
"primary": false,
"unique": false,
@@ -440,7 +488,9 @@
},
{
"keyName": "IDX_price_set_money_amount_deleted_at",
"columnNames": ["deleted_at"],
"columnNames": [
"deleted_at"
],
"composite": false,
"primary": false,
"unique": false,
@@ -448,7 +498,9 @@
},
{
"keyName": "price_set_money_amount_pkey",
"columnNames": ["id"],
"columnNames": [
"id"
],
"composite": false,
"primary": true,
"unique": true
@@ -458,27 +510,26 @@
"foreignKeys": {
"price_set_money_amount_price_set_id_foreign": {
"constraintName": "price_set_money_amount_price_set_id_foreign",
"columnNames": ["price_set_id"],
"columnNames": [
"price_set_id"
],
"localTableName": "public.price_set_money_amount",
"referencedColumnNames": ["id"],
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.price_set",
"deleteRule": "cascade",
"updateRule": "cascade"
},
"price_set_money_amount_money_amount_id_foreign": {
"constraintName": "price_set_money_amount_money_amount_id_foreign",
"columnNames": ["money_amount_id"],
"localTableName": "public.price_set_money_amount",
"referencedColumnNames": ["id"],
"referencedTableName": "public.money_amount",
"deleteRule": "cascade",
"updateRule": "cascade"
},
"price_set_money_amount_price_list_id_foreign": {
"constraintName": "price_set_money_amount_price_list_id_foreign",
"columnNames": ["price_list_id"],
"columnNames": [
"price_list_id"
],
"localTableName": "public.price_set_money_amount",
"referencedColumnNames": ["id"],
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.price_list",
"deleteRule": "cascade",
"updateRule": "cascade"
@@ -562,7 +613,9 @@
"indexes": [
{
"keyName": "IDX_rule_type_rule_attribute",
"columnNames": ["rule_attribute"],
"columnNames": [
"rule_attribute"
],
"composite": false,
"primary": false,
"unique": false,
@@ -570,7 +623,9 @@
},
{
"keyName": "IDX_rule_type_deleted_at",
"columnNames": ["deleted_at"],
"columnNames": [
"deleted_at"
],
"composite": false,
"primary": false,
"unique": false,
@@ -578,7 +633,9 @@
},
{
"keyName": "rule_type_pkey",
"columnNames": ["id"],
"columnNames": [
"id"
],
"composite": false,
"primary": true,
"unique": true
@@ -654,7 +711,9 @@
"indexes": [
{
"keyName": "IDX_price_set_rule_type_price_set_id",
"columnNames": ["price_set_id"],
"columnNames": [
"price_set_id"
],
"composite": false,
"primary": false,
"unique": false,
@@ -662,7 +721,9 @@
},
{
"keyName": "IDX_price_set_rule_type_rule_type_id",
"columnNames": ["rule_type_id"],
"columnNames": [
"rule_type_id"
],
"composite": false,
"primary": false,
"unique": false,
@@ -670,7 +731,9 @@
},
{
"keyName": "IDX_price_set_rule_type_deleted_at",
"columnNames": ["deleted_at"],
"columnNames": [
"deleted_at"
],
"composite": false,
"primary": false,
"unique": false,
@@ -678,7 +741,9 @@
},
{
"keyName": "price_set_rule_type_pkey",
"columnNames": ["id"],
"columnNames": [
"id"
],
"composite": false,
"primary": true,
"unique": true
@@ -688,18 +753,26 @@
"foreignKeys": {
"price_set_rule_type_price_set_id_foreign": {
"constraintName": "price_set_rule_type_price_set_id_foreign",
"columnNames": ["price_set_id"],
"columnNames": [
"price_set_id"
],
"localTableName": "public.price_set_rule_type",
"referencedColumnNames": ["id"],
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.price_set",
"deleteRule": "cascade",
"updateRule": "cascade"
},
"price_set_rule_type_rule_type_id_foreign": {
"constraintName": "price_set_rule_type_rule_type_id_foreign",
"columnNames": ["rule_type_id"],
"columnNames": [
"rule_type_id"
],
"localTableName": "public.price_set_rule_type",
"referencedColumnNames": ["id"],
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.rule_type",
"deleteRule": "cascade",
"updateRule": "cascade"
@@ -801,7 +874,9 @@
"indexes": [
{
"keyName": "IDX_price_rule_price_set_id",
"columnNames": ["price_set_id"],
"columnNames": [
"price_set_id"
],
"composite": false,
"primary": false,
"unique": false,
@@ -809,7 +884,9 @@
},
{
"keyName": "IDX_price_rule_rule_type_id",
"columnNames": ["rule_type_id"],
"columnNames": [
"rule_type_id"
],
"composite": false,
"primary": false,
"unique": false,
@@ -817,7 +894,9 @@
},
{
"keyName": "IDX_price_rule_price_set_money_amount_id_unique",
"columnNames": ["price_set_money_amount_id"],
"columnNames": [
"price_set_money_amount_id"
],
"composite": false,
"primary": false,
"unique": false,
@@ -825,7 +904,9 @@
},
{
"keyName": "IDX_price_rule_deleted_at",
"columnNames": ["deleted_at"],
"columnNames": [
"deleted_at"
],
"composite": false,
"primary": false,
"unique": false,
@@ -833,7 +914,9 @@
},
{
"keyName": "price_rule_pkey",
"columnNames": ["id"],
"columnNames": [
"id"
],
"composite": false,
"primary": true,
"unique": true
@@ -843,26 +926,38 @@
"foreignKeys": {
"price_rule_price_set_id_foreign": {
"constraintName": "price_rule_price_set_id_foreign",
"columnNames": ["price_set_id"],
"columnNames": [
"price_set_id"
],
"localTableName": "public.price_rule",
"referencedColumnNames": ["id"],
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.price_set",
"deleteRule": "cascade",
"updateRule": "cascade"
},
"price_rule_rule_type_id_foreign": {
"constraintName": "price_rule_rule_type_id_foreign",
"columnNames": ["rule_type_id"],
"columnNames": [
"rule_type_id"
],
"localTableName": "public.price_rule",
"referencedColumnNames": ["id"],
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.rule_type",
"updateRule": "cascade"
},
"price_rule_price_set_money_amount_id_foreign": {
"constraintName": "price_rule_price_set_money_amount_id_foreign",
"columnNames": ["price_set_money_amount_id"],
"columnNames": [
"price_set_money_amount_id"
],
"localTableName": "public.price_rule",
"referencedColumnNames": ["id"],
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.price_set_money_amount",
"deleteRule": "cascade",
"updateRule": "cascade"
@@ -880,6 +975,15 @@
"nullable": false,
"mappedType": "text"
},
"rule_type_id": {
"name": "rule_type_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"price_list_id": {
"name": "price_list_id",
"type": "text",
@@ -920,15 +1024,6 @@
"nullable": true,
"length": 6,
"mappedType": "datetime"
},
"rule_type_id": {
"name": "rule_type_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
}
},
"name": "price_list_rule",
@@ -936,7 +1031,9 @@
"indexes": [
{
"keyName": "IDX_price_list_rule_rule_type_id_unique",
"columnNames": ["rule_type_id"],
"columnNames": [
"rule_type_id"
],
"composite": false,
"primary": false,
"unique": false,
@@ -944,7 +1041,9 @@
},
{
"keyName": "IDX_price_list_rule_price_list_id",
"columnNames": ["price_list_id"],
"columnNames": [
"price_list_id"
],
"composite": false,
"primary": false,
"unique": false,
@@ -952,7 +1051,9 @@
},
{
"keyName": "IDX_price_list_rule_deleted_at",
"columnNames": ["deleted_at"],
"columnNames": [
"deleted_at"
],
"composite": false,
"primary": false,
"unique": false,
@@ -960,7 +1061,9 @@
},
{
"keyName": "price_list_rule_pkey",
"columnNames": ["id"],
"columnNames": [
"id"
],
"composite": false,
"primary": true,
"unique": true
@@ -968,22 +1071,30 @@
],
"checks": [],
"foreignKeys": {
"price_list_rule_price_list_id_foreign": {
"constraintName": "price_list_rule_price_list_id_foreign",
"columnNames": ["price_list_id"],
"localTableName": "public.price_list_rule",
"referencedColumnNames": ["id"],
"referencedTableName": "public.price_list",
"deleteRule": "cascade",
"updateRule": "cascade"
},
"price_list_rule_rule_type_id_foreign": {
"constraintName": "price_list_rule_rule_type_id_foreign",
"columnNames": ["rule_type_id"],
"columnNames": [
"rule_type_id"
],
"localTableName": "public.price_list_rule",
"referencedColumnNames": ["id"],
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.rule_type",
"updateRule": "cascade"
},
"price_list_rule_price_list_id_foreign": {
"constraintName": "price_list_rule_price_list_id_foreign",
"columnNames": [
"price_list_id"
],
"localTableName": "public.price_list_rule",
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.price_list",
"deleteRule": "cascade",
"updateRule": "cascade"
}
}
},
@@ -1054,7 +1165,9 @@
"indexes": [
{
"keyName": "IDX_price_list_rule_value_price_list_rule_id",
"columnNames": ["price_list_rule_id"],
"columnNames": [
"price_list_rule_id"
],
"composite": false,
"primary": false,
"unique": false,
@@ -1062,7 +1175,9 @@
},
{
"keyName": "IDX_price_list_rule_value_deleted_at",
"columnNames": ["deleted_at"],
"columnNames": [
"deleted_at"
],
"composite": false,
"primary": false,
"unique": false,
@@ -1070,7 +1185,9 @@
},
{
"keyName": "price_list_rule_value_pkey",
"columnNames": ["id"],
"columnNames": [
"id"
],
"composite": false,
"primary": true,
"unique": true
@@ -1080,9 +1197,13 @@
"foreignKeys": {
"price_list_rule_value_price_list_rule_id_foreign": {
"constraintName": "price_list_rule_value_price_list_rule_id_foreign",
"columnNames": ["price_list_rule_id"],
"columnNames": [
"price_list_rule_id"
],
"localTableName": "public.price_list_rule_value",
"referencedColumnNames": ["id"],
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.price_list_rule",
"deleteRule": "cascade",
"updateRule": "cascade"

View File

@@ -206,5 +206,29 @@ export class Migration20230929122253 extends Migration {
this.addSql(
'alter table if exists "price_set_rule_type" add constraint "price_set_rule_type_rule_type_id_foreign" foreign key ("rule_type_id") references "rule_type" ("id") on update cascade on delete cascade;'
)
this.addSql(
'alter table if exists "price_set_money_amount" drop constraint if exists "price_set_money_amount_money_amount_id_foreign";'
)
this.addSql(
'alter table if exists "price_set_money_amount" add column if not exists "amount" numeric not null, add column "min_quantity" numeric null, add column "max_quantity" numeric null;'
)
this.addSql(
'alter table if exists "price_set_money_amount" drop constraint if exists "price_set_money_amount_money_amount_id_unique";'
)
this.addSql(
'drop index if exists "IDX_price_set_money_amount_money_amount_id";'
)
this.addSql(
'alter table if exists "price_set_money_amount" rename column "money_amount_id" to "currency_code";'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_price_set_money_amount_currency_code" ON "price_set_money_amount" (currency_code) WHERE deleted_at IS NULL;'
)
}
}

View File

@@ -1,4 +1,3 @@
export { default as MoneyAmount } from "./money-amount"
export { default as PriceList } from "./price-list"
export { default as PriceListRule } from "./price-list-rule"
export { default as PriceListRuleValue } from "./price-list-rule-value"

View File

@@ -1,95 +0,0 @@
import { DAL } from "@medusajs/types"
import {
DALUtils,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Entity,
Filter,
OnInit,
OneToOne,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import { PriceSetMoneyAmount } from "./index"
type OptionalFields = DAL.SoftDeletableEntityDateColumns
const tableName = "money_amount"
const MoneyAmountDeletedAtIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})
const MoneyAmountCurrencyCodeIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "currency_code",
where: "deleted_at IS NULL",
})
@Entity({ tableName })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
class MoneyAmount {
[OptionalProps]?: OptionalFields
@PrimaryKey({ columnType: "text" })
id!: string
@MoneyAmountCurrencyCodeIndex.MikroORMIndex()
@Property({ columnType: "text" })
currency_code: string
@Property({
columnType: "numeric",
serializer: Number,
})
amount: number
@Property({ columnType: "numeric", nullable: true })
min_quantity: number | null
@Property({ columnType: "numeric", nullable: true })
max_quantity: number | null
@OneToOne({
entity: () => PriceSetMoneyAmount,
mappedBy: (psma) => psma.money_amount,
onDelete: "cascade",
})
price_set_money_amount: PriceSetMoneyAmount
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date
@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
@MoneyAmountDeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "ma")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "ma")
}
}
export default MoneyAmount

View File

@@ -13,12 +13,10 @@ import {
ManyToOne,
OnInit,
OneToMany,
OneToOne,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import MoneyAmount from "./money-amount"
import PriceList from "./price-list"
import PriceRule from "./price-rule"
import PriceSet from "./price-set"
@@ -50,6 +48,12 @@ const PriceSetMoneyAmountPriceListIdIndex = createPsqlIndexStatementHelper({
where: "deleted_at IS NULL",
})
const PriceSetMoneyAmountCurrencyCodeIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "currency_code",
where: "deleted_at IS NULL",
})
@Entity({ tableName })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class PriceSetMoneyAmount {
@@ -61,6 +65,19 @@ export default class PriceSetMoneyAmount {
@Property({ columnType: "text", nullable: true })
title: string | null = null
@PriceSetMoneyAmountCurrencyCodeIndex.MikroORMIndex()
@Property({ columnType: "text" })
currency_code: string
@Property({ columnType: "numeric", serializer: Number })
amount: number
@Property({ columnType: "numeric", nullable: true })
min_quantity: number | null = null
@Property({ columnType: "numeric", nullable: true })
max_quantity: number | null = null
@PriceSetMoneyAmountPriceSetIdIndex.MikroORMIndex()
@ManyToOne(() => PriceSet, {
columnType: "text",
@@ -73,18 +90,6 @@ export default class PriceSetMoneyAmount {
@ManyToOne(() => PriceSet, { persist: false })
price_set?: PriceSet
@PriceSetMoneyAmountMoneyAmountIdIndex.MikroORMIndex()
@OneToOne(() => MoneyAmount, {
columnType: "text",
mapToPk: true,
fieldName: "money_amount_id",
onDelete: "cascade",
})
money_amount_id: string
@OneToOne(() => MoneyAmount, { persist: false })
money_amount?: MoneyAmount
@Property({ columnType: "integer", default: 0 })
rules_count: number = 0
@@ -103,10 +108,10 @@ export default class PriceSetMoneyAmount {
fieldName: "price_list_id",
onDelete: "cascade",
})
price_list_id: string
price_list_id: string | null = null
@ManyToOne(() => PriceList, { persist: false, nullable: true })
price_list?: PriceList
price_list: PriceList | null = null
@Property({
onCreate: () => new Date(),

View File

@@ -62,8 +62,11 @@ export class PricingRepository
})
.select({
id: "psma1.id",
amount: "psma1.amount",
min_quantity: "psma1.min_quantity",
max_quantity: "psma1.max_quantity",
currency_code: "psma1.currency_code",
price_set_id: "psma1.price_set_id",
money_amount_id: "psma1.money_amount_id",
rules_count: "psma1.rules_count",
price_list_id: "psma1.price_list_id",
pl_rules_count: "pl.rules_count",
@@ -149,12 +152,12 @@ export class PricingRepository
ps: "price_set",
})
.select({
id: "ma.id",
id: "psma.id",
price_set_id: "ps.id",
amount: "ma.amount",
min_quantity: "ma.min_quantity",
max_quantity: "ma.max_quantity",
currency_code: "ma.currency_code",
amount: "psma.amount",
min_quantity: "psma.min_quantity",
max_quantity: "psma.max_quantity",
currency_code: "psma.currency_code",
default_priority: "rt.default_priority",
rules_count: "psma.rules_count",
pl_rules_count: "psma.pl_rules_count",
@@ -162,11 +165,10 @@ export class PricingRepository
price_list_id: "psma.price_list_id",
})
.join(psmaSubQueryKnex.as("psma"), "psma.price_set_id", "ps.id")
.join("money_amount as ma", "ma.id", "psma.money_amount_id")
.leftJoin("price_rule as pr", "pr.price_set_money_amount_id", "psma.id")
.leftJoin("rule_type as rt", "rt.id", "pr.rule_type_id")
.whereIn("ps.id", pricingFilters.id)
.andWhere("ma.currency_code", "=", currencyCode)
.andWhere("psma.currency_code", "=", currencyCode)
.orderBy([
{ column: "psma.has_price_list", order: "asc" },
@@ -176,12 +178,12 @@ export class PricingRepository
])
if (quantity) {
priceSetQueryKnex.where("ma.min_quantity", "<=", quantity)
priceSetQueryKnex.andWhere("ma.max_quantity", ">=", quantity)
priceSetQueryKnex.where("psma.min_quantity", "<=", quantity)
priceSetQueryKnex.andWhere("psma.max_quantity", ">=", quantity)
} else {
priceSetQueryKnex.andWhere(function () {
this.andWhere("ma.min_quantity", "<=", "1").orWhereNull(
"ma.min_quantity"
this.andWhere("psma.min_quantity", "<=", "1").orWhereNull(
"psma.min_quantity"
)
})
}

View File

@@ -22,13 +22,14 @@ export async function run({
logger.info(`Loading seed data from ${path}...`)
const { moneyAmountsData, priceSetsData, priceSetMoneyAmountsData } =
await import(resolve(process.cwd(), path)).catch((e) => {
logger?.error(
`Failed to load seed data from ${path}. Please, provide a relative path and check that you export the following: priceSetsData, moneyAmountsData and priceSetMoneyAmountsData.${EOL}${e}`
)
throw e
})
const { priceSetsData, priceSetMoneyAmountsData } = await import(
resolve(process.cwd(), path)
).catch((e) => {
logger?.error(
`Failed to load seed data from ${path}. Please, provide a relative path and check that you export the following: priceSetsData and priceSetMoneyAmountsData.${EOL}${e}`
)
throw e
})
const dbData = ModulesSdkUtils.loadDatabaseConfig("pricing", options)!
const entities = Object.values(PricingModels) as unknown as EntitySchema[]
@@ -43,9 +44,8 @@ export async function run({
const manager = orm.em.fork()
try {
logger.info("Inserting price_sets & money_amounts")
logger.info("Inserting price_set & price_set_money_amount")
await createMoneyAmounts(manager as any, moneyAmountsData)
await createPriceSets(manager as any, priceSetsData)
await createPriceSetMoneyAmounts(manager as any, priceSetMoneyAmountsData)
} catch (e) {
@@ -57,19 +57,6 @@ export async function run({
await orm.close(true)
}
async function createMoneyAmounts(
manager: SqlEntityManager<PostgreSqlDriver>,
data: RequiredEntityData<PricingModels.MoneyAmount>[]
) {
const moneyAmounts = data.map((moneyAmountData) => {
return manager.create(PricingModels.MoneyAmount, moneyAmountData)
})
await manager.persistAndFlush(moneyAmounts)
return moneyAmounts
}
async function createPriceSets(
manager: SqlEntityManager<PostgreSqlDriver>,
data: RequiredEntityData<PricingModels.PriceSet>[]

View File

@@ -1,7 +1,6 @@
import {
AddPricesDTO,
Context,
CreateMoneyAmountDTO,
CreatePriceListRuleDTO,
DAL,
InternalModuleDeclaration,
@@ -28,7 +27,6 @@ import {
} from "@medusajs/utils"
import {
MoneyAmount,
PriceList,
PriceListRule,
PriceListRuleValue,
@@ -47,7 +45,6 @@ import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
type InjectedDependencies = {
baseRepository: DAL.RepositoryService
pricingRepository: PricingRepositoryService
moneyAmountService: ModulesSdkTypes.InternalModuleService<any>
priceSetService: ModulesSdkTypes.InternalModuleService<any>
ruleTypeService: RuleTypeService<any>
priceRuleService: ModulesSdkTypes.InternalModuleService<any>
@@ -59,7 +56,6 @@ type InjectedDependencies = {
}
const generateMethodForModels = [
MoneyAmount,
PriceList,
PriceListRule,
PriceListRuleValue,
@@ -71,7 +67,6 @@ const generateMethodForModels = [
export default class PricingModuleService<
TPriceSet extends PriceSet = PriceSet,
TMoneyAmount extends MoneyAmount = MoneyAmount,
TRuleType extends RuleType = RuleType,
TPriceRule extends PriceRule = PriceRule,
TPriceSetRuleType extends PriceSetRuleType = PriceSetRuleType,
@@ -84,11 +79,6 @@ export default class PricingModuleService<
InjectedDependencies,
PricingTypes.PriceSetDTO,
{
MoneyAmount: {
dto: PricingTypes.MoneyAmountDTO
create: PricingTypes.CreateMoneyAmountDTO
update: PricingTypes.UpdateMoneyAmountDTO
}
PriceSetMoneyAmount: { dto: PricingTypes.PriceSetMoneyAmountDTO }
PriceRule: {
dto: PricingTypes.PriceRuleDTO
@@ -108,7 +98,6 @@ export default class PricingModuleService<
{
protected baseRepository_: DAL.RepositoryService
protected readonly pricingRepository_: PricingRepositoryService
protected readonly moneyAmountService_: ModulesSdkTypes.InternalModuleService<TMoneyAmount>
protected readonly ruleTypeService_: RuleTypeService<TRuleType>
protected readonly priceSetService_: ModulesSdkTypes.InternalModuleService<TPriceSet>
protected readonly priceRuleService_: ModulesSdkTypes.InternalModuleService<TPriceRule>
@@ -122,7 +111,6 @@ export default class PricingModuleService<
{
baseRepository,
pricingRepository,
moneyAmountService,
ruleTypeService,
priceSetService,
priceRuleService,
@@ -139,7 +127,6 @@ export default class PricingModuleService<
this.baseRepository_ = baseRepository
this.pricingRepository_ = pricingRepository
this.moneyAmountService_ = moneyAmountService
this.ruleTypeService_ = ruleTypeService
this.priceSetService_ = priceSetService
this.ruleTypeService_ = ruleTypeService
@@ -202,7 +189,7 @@ export default class PricingModuleService<
currency_code: calculatedPrice?.currency_code || null,
calculated_price: {
money_amount_id: calculatedPrice?.id || null,
id: calculatedPrice?.id || null,
price_list_id: calculatedPrice?.price_list_id || null,
price_list_type: calculatedPrice?.price_list_type || null,
min_quantity:
@@ -212,7 +199,7 @@ export default class PricingModuleService<
},
original_price: {
money_amount_id: originalPrice?.id || null,
id: originalPrice?.id || null,
price_list_id: originalPrice?.price_list_id || null,
price_list_type: originalPrice?.price_list_type || null,
min_quantity: parseInt(originalPrice?.min_quantity || "") || null,
@@ -247,11 +234,7 @@ export default class PricingModuleService<
const dbPriceSets = await this.list(
{ id: priceSets.filter((p) => !!p).map((p) => p!.id) },
{
relations: [
"rule_types",
"price_set_money_amounts.money_amount",
"price_rules",
],
relations: ["rule_types", "price_set_money_amounts", "price_rules"],
},
sharedContext
)
@@ -333,25 +316,17 @@ export default class PricingModuleService<
)
}
// Money amounts
const moneyAmountData = data.flatMap((item) => item.prices || [])
const createdMoneyAmounts = await this.moneyAmountService_.create(
moneyAmountData,
sharedContext
)
let moneyAmountIndex = 0
const priceSetMoneyAmountData: unknown[] = []
const priceRulesData: unknown[] = []
for (const [index, item] of data.entries()) {
for (const ma of item.prices || []) {
const cleanRules = ma.rules ? removeNullish(ma.rules) : {}
for (const price of item.prices || []) {
const cleanRules = price.rules ? removeNullish(price.rules) : {}
const numberOfRules = Object.entries(cleanRules).length
const priceSetMoneyAmount = {
...price,
price_set_id: createdPriceSets[index].id,
money_amount_id: createdMoneyAmounts[moneyAmountIndex++].id,
title: "test", // TODO: accept title
rules_count: numberOfRules,
}
@@ -359,7 +334,7 @@ export default class PricingModuleService<
for (const [k, v] of Object.entries(cleanRules)) {
priceRulesData.push({
price_set_money_amount: null, // Updated later
price_set_money_amount_id: null, // Updated later
rule_type_id: ruleTypeMap.get(k).id,
price_set_id: createdPriceSets[index].id,
value: v,
@@ -583,31 +558,20 @@ export default class PricingModuleService<
}
})
// Money amounts
const moneyAmountsBulkData = input.flatMap((entry) => entry.prices)
const createdMoneyAmounts = await this.moneyAmountService_.create(
moneyAmountsBulkData as unknown as CreateMoneyAmountDTO[],
sharedContext
)
// Price set money amounts
let maCursor = 0
const priceSetMoneyAmountsBulkData: unknown[] = input.flatMap(
({ priceSetId, prices }) =>
prices.map(() => {
const ma = createdMoneyAmounts[maCursor]
const numberOfRules = Object.entries(
prices[maCursor]?.rules ?? {}
).length
maCursor++
prices.map((price) => {
const numberOfRules = Object.entries(price?.rules ?? {}).length
return {
...price,
price_set_id: priceSetId,
money_amount_id: ma.id,
title: "test", // TODO: accept title
rules_count: numberOfRules,
}
})
)
const createdPriceSetMoneyAmounts =
await this.priceSetMoneyAmountService_.create(
priceSetMoneyAmountsBulkData as ServiceTypes.CreatePriceSetMoneyAmountDTO[],
@@ -807,23 +771,18 @@ export default class PricingModuleService<
const {
price_set_id: priceSetId,
rules: priceRules = {},
...moneyAmountData
...psmaData
} = price
const [moneyAmount] = await this.moneyAmountService_.create(
[moneyAmountData],
sharedContext
)
const [priceSetMoneyAmount] =
await this.priceSetMoneyAmountService_.create(
[
{
price_set_id: priceSetId,
price_list_id: priceList.id,
money_amount_id: moneyAmount.id,
title: "test",
rules_count: Object.keys(priceRules).length,
...psmaData,
},
],
sharedContext
@@ -1020,7 +979,7 @@ export default class PricingModuleService<
): Promise<PricingTypes.PriceListDTO[]> {
const ruleTypeAttributes: string[] = []
const priceListIds: string[] = []
const moneyAmountIds: string[] = []
const psmaIds: string[] = []
const priceSetIds = data
.map((d) => d.prices.map((price) => price.price_set_id))
.flat()
@@ -1029,25 +988,22 @@ export default class PricingModuleService<
priceListIds.push(priceListData.price_list_id)
for (const price of priceListData.prices) {
moneyAmountIds.push(price.id)
psmaIds.push(price.id)
ruleTypeAttributes.push(...Object.keys(price.rules || {}))
}
}
const moneyAmounts = await this.listMoneyAmounts(
{ id: moneyAmountIds },
const psmas = await this.listPriceSetMoneyAmounts(
{ id: psmaIds },
{
take: null,
relations: [
"price_set_money_amount",
"price_set_money_amount.price_rules",
],
relations: ["price_rules"],
},
sharedContext
)
const moneyAmountMap: Map<string, PricingTypes.MoneyAmountDTO> = new Map(
moneyAmounts.map((ma) => [ma.id, ma])
const psmaMap: Map<string, PricingTypes.PriceSetMoneyAmountDTO> = new Map(
psmas.map((psma) => [psma.id, psma])
)
const ruleTypes = await this.listRuleTypes(
@@ -1131,18 +1087,15 @@ export default class PricingModuleService<
for (const price of prices) {
const { rules, price_set_id, ...priceData } = price
const moneyAmount = moneyAmountMap.get(price.id)!
const priceSetMoneyAmount = moneyAmount.price_set_money_amount!
const priceSetMoneyAmount = psmaMap.get(price.id)!
const priceRules = priceSetMoneyAmount.price_rules!
moneyAmountsToUpdate.push(priceData)
if (typeof rules === "undefined") {
continue
}
psmaToUpdate.push({
id: priceSetMoneyAmount!.id,
...priceData,
rules_count: Object.keys(rules).length,
})
@@ -1158,7 +1111,6 @@ export default class PricingModuleService<
}
await Promise.all([
this.moneyAmountService_.update(moneyAmountsToUpdate),
this.priceRuleService_.delete(priceRulesToDelete),
this.priceRuleService_.create(priceRulesToCreate),
this.priceSetMoneyAmountService_.update(psmaToUpdate),
@@ -1289,16 +1241,11 @@ export default class PricingModuleService<
const priceRules = price.rules || {}
const noOfRules = Object.keys(priceRules).length
const [moneyAmount] = await this.moneyAmountService_.create(
[price] as unknown as CreateMoneyAmountDTO[],
sharedContext
)
const [psma] = await this.priceSetMoneyAmountService_.create(
[
{
...price,
price_set_id: price.price_set_id,
money_amount_id: moneyAmount.id,
title: "test",
price_list_id: priceList.id,
rules_count: noOfRules,

View File

@@ -1,4 +1,3 @@
export * from "./money-amount"
export * from "./price-list"
export * from "./price-list-rule"
export * from "./price-list-rule-value"

View File

@@ -1,15 +0,0 @@
export interface CreateMoneyAmountDTO {
id?: string
currency_code: string
amount: number
min_quantity?: number | null
max_quantity?: number | null
}
export interface UpdateMoneyAmountDTO {
id: string
currency_code?: string
amount?: number
min_quantity?: number
max_quantity?: number
}

View File

@@ -1,12 +1,12 @@
import { BaseFilterable } from "../../dal"
import { CreatePriceSetPriceRules } from "./price-list"
import { Context } from "../../shared-context"
import {
CreateMoneyAmountDTO,
FilterableMoneyAmountProps,
MoneyAmountDTO,
} from "./money-amount"
import { CreatePriceSetPriceRules } from "./price-list"
import { RuleTypeDTO } from "./rule-type"
import { Context } from "../../shared-context"
export interface PricingRepositoryService {
calculatePrices(
@@ -145,9 +145,9 @@ export interface CalculatedPriceSet {
*/
calculated_price?: {
/**
* The ID of the money amount selected as the calculated price.
* The ID of the price selected as the calculated price.
*/
money_amount_id: string | null
id: string | null
/**
* The ID of the associated price list, if any.
*/
@@ -157,11 +157,11 @@ export interface CalculatedPriceSet {
*/
price_list_type: string | null
/**
* The `min_quantity` field defined on a money amount.
* The `min_quantity` field defined on a price.
*/
min_quantity: number | null
/**
* The `max_quantity` field defined on a money amount.
* The `max_quantity` field defined on a price.
*/
max_quantity: number | null
}
@@ -171,9 +171,9 @@ export interface CalculatedPriceSet {
*/
original_price?: {
/**
* The ID of the money amount selected as the original price.
* The ID of the price selected as the original price.
*/
money_amount_id: string | null
id: string | null
/**
* The ID of the associated price list, if any.
*/
@@ -183,11 +183,11 @@ export interface CalculatedPriceSet {
*/
price_list_type: string | null
/**
* The `min_quantity` field defined on a money amount.
* The `min_quantity` field defined on a price.
*/
min_quantity: number | null
/**
* The `max_quantity` field defined on a money amount.
* The `max_quantity` field defined on a price.
*/
max_quantity: number | null
}

View File

@@ -3,20 +3,17 @@ import {
AddPricesDTO,
AddRulesDTO,
CalculatedPriceSet,
CreateMoneyAmountDTO,
CreatePriceListDTO,
CreatePriceListRuleDTO,
CreatePriceRuleDTO,
CreatePriceSetDTO,
CreateRuleTypeDTO,
FilterableMoneyAmountProps,
FilterablePriceListProps,
FilterablePriceListRuleProps,
FilterablePriceRuleProps,
FilterablePriceSetMoneyAmountProps,
FilterablePriceSetProps,
FilterableRuleTypeProps,
MoneyAmountDTO,
PriceListDTO,
PriceListRuleDTO,
PriceRuleDTO,
@@ -28,7 +25,6 @@ import {
RemovePriceSetRulesDTO,
RuleTypeDTO,
SetPriceListRulesDTO,
UpdateMoneyAmountDTO,
UpdatePriceListDTO,
UpdatePriceListPricesDTO,
UpdatePriceListRuleDTO,
@@ -886,456 +882,6 @@ export interface IPricingModuleService extends IModuleService {
*/
addRules(data: AddRulesDTO[], sharedContext?: Context): Promise<PriceSetDTO[]>
/**
* This method retrieves a money amount by its ID.
*
* @param {string} id - The ID of the money amount to retrieve.
* @param {FindConfig<MoneyAmountDTO>} config -
* The configurations determining how a money amount is retrieved. Its properties, such as `select` or `relations`, accept the
* attributes or relations associated with a money amount.
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<MoneyAmountDTO>} The retrieved money amount.
*
* @example
* To retrieve a money amount by its ID:
*
* ```ts
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrieveMoneyAmount (moneyAmountId: string) {
* const pricingService = await initializePricingModule()
*
* const moneyAmount = await pricingService.retrieveMoneyAmount(
* moneyAmountId,
* )
*
* // do something with the money amount or return it
* }
* ```
*
* To retrieve relations along with the money amount:
*
* ```ts
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrieveMoneyAmount (moneyAmountId: string) {
* const pricingService = await initializePricingModule()
*
* const moneyAmount = await pricingService.retrieveMoneyAmount(
* moneyAmountId,
* {
* relations: ["price_set_money_amount"]
* }
* )
*
* // do something with the money amount or return it
* }
* ```
*/
retrieveMoneyAmount(
id: string,
config?: FindConfig<MoneyAmountDTO>,
sharedContext?: Context
): Promise<MoneyAmountDTO>
/**
* This method is used to retrieve a paginated list of money amounts based on optional filters and configuration.
*
* @param {FilterableMoneyAmountProps} filters - The filtes to apply on the retrieved money amounts.
* @param {FindConfig<MoneyAmountDTO>} config -
* The configurations determining how the money amounts are retrieved. Its properties, such as `select` or `relations`, accept the
* attributes or relations associated with a money amount.
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<MoneyAmountDTO[]>} The list of money amounts.
*
* @example
*
* To retrieve a list of money amounts using their IDs:
*
* ```ts
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrieveMoneyAmounts (moneyAmountIds: string[]) {
* const pricingService = await initializePricingModule()
*
* const moneyAmounts = await pricingService.listMoneyAmounts(
* {
* id: moneyAmountIds
* }
* )
*
* // do something with the money amounts or return them
* }
* ```
*
* To specify relations that should be retrieved within the money amounts:
*
* ```ts
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrieveMoneyAmounts (moneyAmountIds: string[]) {
* const pricingService = await initializePricingModule()
*
* const moneyAmounts = await pricingService.listMoneyAmounts(
* {
* id: moneyAmountIds
* },
* {
* relations: ["price_set_money_amount"]
* }
* )
*
* // do something with the money amounts or return them
* }
* ```
*
* By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
*
* ```ts
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrieveMoneyAmounts (moneyAmountIds: string[], skip: number, take: number) {
* const pricingService = await initializePricingModule()
*
* const moneyAmounts = await pricingService.listMoneyAmounts(
* {
* id: moneyAmountIds
* },
* {
* relations: ["price_set_money_amount"],
* skip,
* take
* }
* )
*
* // do something with the money amounts or return them
* }
* ```
*
* You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
*
* ```ts
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrieveMoneyAmounts (moneyAmountIds: string[], currencyCode: string[], skip: number, take: number) {
* const pricingService = await initializePricingModule()
*
* const moneyAmounts = await pricingService.listMoneyAmounts(
* {
* $and: [
* {
* id: moneyAmountIds
* },
* {
* currency_code: currencyCode
* }
* ]
* },
* {
* relations: ["price_set_money_amount"],
* skip,
* take
* }
* )
*
* // do something with the money amounts or return them
* }
* ```
*/
listMoneyAmounts(
filters?: FilterableMoneyAmountProps,
config?: FindConfig<MoneyAmountDTO>,
sharedContext?: Context
): Promise<MoneyAmountDTO[]>
/**
* This method is used to retrieve a paginated list of money amounts along with the total count of available money amounts satisfying the provided filters.
*
* @param {FilterableMoneyAmountProps} filters - The filters to apply on the retrieved money amounts.
* @param {FindConfig<MoneyAmountDTO>} config -
* The configurations determining how the money amounts are retrieved. Its properties, such as `select` or `relations`, accept the
* attributes or relations associated with a money amount.
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<[MoneyAmountDTO[], number]>} The list of money amounts along with their total count.
*
* @example
*
* To retrieve a list of money amounts using their IDs:
*
* ```ts
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrieveMoneyAmounts (moneyAmountIds: string[]) {
* const pricingService = await initializePricingModule()
*
* const [moneyAmounts, count] = await pricingService.listAndCountMoneyAmounts(
* {
* id: moneyAmountIds
* }
* )
*
* // do something with the money amounts or return them
* }
* ```
*
* To specify relations that should be retrieved within the money amounts:
*
* ```ts
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrieveMoneyAmounts (moneyAmountIds: string[]) {
* const pricingService = await initializePricingModule()
*
* const [moneyAmounts, count] = await pricingService.listAndCountMoneyAmounts(
* {
* id: moneyAmountIds
* },
* {
* relations: ["price_set_money_amount"]
* }
* )
*
* // do something with the money amounts or return them
* }
* ```
*
* By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
*
* ```ts
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrieveMoneyAmounts (moneyAmountIds: string[], skip: number, take: number) {
* const pricingService = await initializePricingModule()
*
* const [moneyAmounts, count] = await pricingService.listAndCountMoneyAmounts(
* {
* id: moneyAmountIds
* },
* {
* relations: ["price_set_money_amount"],
* skip,
* take
* }
* )
*
* // do something with the money amounts or return them
* }
* ```
*
* You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
*
* ```ts
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrieveMoneyAmounts (moneyAmountIds: string[], currencyCode: string[], skip: number, take: number) {
* const pricingService = await initializePricingModule()
*
* const [moneyAmounts, count] = await pricingService.listAndCountMoneyAmounts(
* {
* $and: [
* {
* id: moneyAmountIds
* },
* {
* currency_code: currencyCode
* }
* ]
* },
* {
* relations: ["price_set_money_amount"],
* skip,
* take
* }
* )
*
* // do something with the money amounts or return them
* }
* ```
*/
listAndCountMoneyAmounts(
filters?: FilterableMoneyAmountProps,
config?: FindConfig<MoneyAmountDTO>,
sharedContext?: Context
): Promise<[MoneyAmountDTO[], number]>
/**
* This method creates money amounts.
*
* @param {CreateMoneyAmountDTO[]} data - The money amounts to create.
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<MoneyAmountDTO[]>} The list of created money amounts.
*
* @example
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrieveMoneyAmounts () {
* const pricingService = await initializePricingModule()
*
* const moneyAmounts = await pricingService.createMoneyAmounts([
* {
* amount: 500,
* currency_code: "USD",
* },
* {
* amount: 400,
* currency_code: "USD",
* min_quantity: 0,
* max_quantity: 4
* }
* ])
*
* // do something with the money amounts or return them
* }
*/
createMoneyAmounts(
data: CreateMoneyAmountDTO[],
sharedContext?: Context
): Promise<MoneyAmountDTO[]>
createMoneyAmounts(
data: CreateMoneyAmountDTO,
sharedContext?: Context
): Promise<MoneyAmountDTO>
/**
* This method updates existing money amounts.
*
* @param {UpdateMoneyAmountDTO[]} data - The money amounts to update, each having the attributes that should be updated in a money amount.
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<MoneyAmountDTO[]>} The list of updated money amounts.
*
* @example
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function updateMoneyAmounts (moneyAmountId: string, amount: number) {
* const pricingService = await initializePricingModule()
*
* const moneyAmounts = await pricingService.updateMoneyAmounts([
* {
* id: moneyAmountId,
* amount
* }
* ])
*
* // do something with the money amounts or return them
* }
*/
updateMoneyAmounts(
data: UpdateMoneyAmountDTO[],
sharedContext?: Context
): Promise<MoneyAmountDTO[]>
updateMoneyAmounts(
data: UpdateMoneyAmountDTO,
sharedContext?: Context
): Promise<MoneyAmountDTO>
/**
* This method deletes money amounts by their IDs.
*
* @param {string[]} ids - The IDs of the money amounts to delete.
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<void>} Resolves when the money amounts are successfully deleted.
*
* @example
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function deleteMoneyAmounts (moneyAmountIds: string[]) {
* const pricingService = await initializePricingModule()
*
* await pricingService.deleteMoneyAmounts(
* moneyAmountIds
* )
* }
*/
deleteMoneyAmounts(ids: string[], sharedContext?: Context): Promise<void>
/**
* This method soft deletes money amounts by their IDs.
*
* @param {string[]} ids - The IDs of the money amounts to delete.
* @param {SoftDeleteReturn<TReturnableLinkableKeys>} config
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<void>} Resolves when the money amounts are successfully deleted.
*
* @example
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function softDeleteMoneyAmounts (moneyAmountIds: string[]) {
* const pricingService = await initializePricingModule()
*
* await pricingService.softDeleteMoneyAmounts(
* moneyAmountIds
* )
* }
*/
softDeleteMoneyAmounts<TReturnableLinkableKeys extends string = string>(
ids: string[],
config?: SoftDeleteReturn<TReturnableLinkableKeys>,
sharedContext?: Context
): Promise<Record<string, string[]> | void>
/**
* This method restores soft deleted money amounts by their IDs.
*
* @param {string[]} ids - The IDs of the money amounts to delete.
* @param {RestoreReturn<TReturnableLinkableKeys>} config -
* Configurations determining which relations to restore along with each of the money amounts. You can pass to its `returnLinkableKeys`
* property any of the money amount's relation attribute names, such as `price_set_money_amount`.
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<Record<string, string[]> | void>}
* An object that includes the IDs of related records that were restored, such as the ID of associated price set money amounts.
* The object's keys are the ID attribute names of the money amount entity's relations, such as `price_set_money_amount_id`,
* and its value is an array of strings, each being the ID of the record associated with the money amount through this relation,
* such as the IDs of associated price set money amounts.
*
* @example
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function softDeleteMoneyAmounts (moneyAmountIds: string[]) {
* const pricingService = await initializePricingModule()
*
* await pricingService.softDeleteMoneyAmounts(
* moneyAmountIds
* )
* }
*/
restoreMoneyAmounts<TReturnableLinkableKeys extends string = string>(
ids: string[],
config?: RestoreReturn<TReturnableLinkableKeys>,
sharedContext?: Context
): Promise<Record<string, string[]> | void>
/**
* This method is used to retrieve a rule type by its ID and and optionally based on the provided configurations.
*

View File

@@ -46,7 +46,7 @@ export function buildPriceSetPricesForCore(
: {}
return {
...priceSetMoneyAmount.money_amount,
...priceSetMoneyAmount,
variant_id: productVariant?.id ?? null,
rules,
}
@@ -62,7 +62,7 @@ export function buildPriceSetPricesForModule(
: {}
return {
...priceSetMoneyAmount.money_amount!,
...priceSetMoneyAmount,
price_set_id: priceSetMoneyAmount.price_set!?.id!,
rules,
}