feat(core-flows,medusa,pricing,types,utils): added price list workflows + endpoints (#6648)
Apologies for the giant PR in advance, but most of these are removing of files and migrations from old workflows and routes to new. What: - Adds CRUD endpoints for price lists - Migrate workflows from old sdk to new - Added missing updatePriceListPrices method to pricing module
This commit is contained in:
1 parent
c3f26a6826
commit
9288f53327
81 files changed
+1959
-2410
No files matched your search
+3
-3
@@ -1,3 +1,4 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
CreatePriceRuleDTO,
|
||||
CreatePriceSetDTO,
|
||||
@@ -5,9 +6,8 @@ import {
|
||||
PricingTypes,
|
||||
} from "@medusajs/types"
|
||||
import { PriceListType } from "@medusajs/utils"
|
||||
import { SuiteOptions, moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { seedPriceData } from "../../../__fixtures__/seed-price-data"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -16,7 +16,7 @@ const defaultRules = {
|
||||
region_id: ["DE", "DK"],
|
||||
}
|
||||
|
||||
const defaultPriceListPrices: PricingTypes.PriceListPriceDTO[] = [
|
||||
const defaultPriceListPrices: PricingTypes.CreatePriceListPriceDTO[] = [
|
||||
{
|
||||
amount: 232,
|
||||
currency_code: "PLN",
|
||||
|
||||
+5
-5
@@ -1,10 +1,10 @@
|
||||
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 { createPriceLists } from "../../../__fixtures__/price-list"
|
||||
import { createPriceListRules } from "../../../__fixtures__/price-list-rules"
|
||||
import { createRuleTypes } from "../../../__fixtures__/rule-type"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -240,7 +240,7 @@ moduleIntegrationTestRunner({
|
||||
])
|
||||
|
||||
await service.setPriceListRules({
|
||||
priceListId: "price-list-1",
|
||||
price_list_id: "price-list-1",
|
||||
rules: {
|
||||
sales_channel: "sc-1",
|
||||
},
|
||||
@@ -280,7 +280,7 @@ moduleIntegrationTestRunner({
|
||||
])
|
||||
|
||||
await service.setPriceListRules({
|
||||
priceListId: "price-list-1",
|
||||
price_list_id: "price-list-1",
|
||||
rules: {
|
||||
sales_channel: ["sc-1", "sc-2"],
|
||||
},
|
||||
@@ -315,7 +315,7 @@ moduleIntegrationTestRunner({
|
||||
describe("removePriceListRules", () => {
|
||||
it("should remove a priceListRule from a priceList", async () => {
|
||||
await service.removePriceListRules({
|
||||
priceListId: "price-list-1",
|
||||
price_list_id: "price-list-1",
|
||||
rules: ["currency_code"],
|
||||
})
|
||||
|
||||
|
||||
+201
-4
@@ -1,8 +1,8 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
|
||||
import { createPriceLists } from "../../../__fixtures__/price-list"
|
||||
import { createPriceSets } from "../../../__fixtures__/price-set"
|
||||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -666,7 +666,7 @@ moduleIntegrationTestRunner({
|
||||
it("should add a price to a priceList successfully", async () => {
|
||||
await service.addPriceListPrices([
|
||||
{
|
||||
priceListId: "price-list-1",
|
||||
price_list_id: "price-list-1",
|
||||
prices: [
|
||||
{
|
||||
amount: 123,
|
||||
@@ -734,7 +734,7 @@ moduleIntegrationTestRunner({
|
||||
try {
|
||||
await service.addPriceListPrices([
|
||||
{
|
||||
priceListId: "price-list-1",
|
||||
price_list_id: "price-list-1",
|
||||
prices: [
|
||||
{
|
||||
amount: 123,
|
||||
@@ -774,7 +774,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
await service.addPriceListPrices([
|
||||
{
|
||||
priceListId: "price-list-1",
|
||||
price_list_id: "price-list-1",
|
||||
prices: [
|
||||
{
|
||||
amount: 123,
|
||||
@@ -843,6 +843,203 @@ moduleIntegrationTestRunner({
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("updatePriceListPrices", () => {
|
||||
it("should update a price to a priceList successfully", async () => {
|
||||
const [priceSet] = await service.create([
|
||||
{
|
||||
rules: [
|
||||
{ rule_attribute: "region_id" },
|
||||
{ rule_attribute: "customer_group_id" },
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
await service.addPriceListPrices([
|
||||
{
|
||||
price_list_id: "price-list-1",
|
||||
prices: [
|
||||
{
|
||||
id: "test-price-id",
|
||||
amount: 123,
|
||||
currency_code: "EUR",
|
||||
price_set_id: priceSet.id,
|
||||
rules: {
|
||||
region_id: "test",
|
||||
},
|
||||
} as any,
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
await service.updatePriceListPrices([
|
||||
{
|
||||
price_list_id: "price-list-1",
|
||||
prices: [
|
||||
{
|
||||
id: "test-price-id",
|
||||
price_set_id: priceSet.id,
|
||||
rules: {
|
||||
region_id: "new test",
|
||||
customer_group_id: "new test",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
const [priceList] = await service.listPriceLists(
|
||||
{ id: ["price-list-1"] },
|
||||
{
|
||||
relations: [
|
||||
"price_set_money_amounts.money_amount",
|
||||
"price_set_money_amounts.price_set",
|
||||
"price_set_money_amounts.price_rules",
|
||||
"price_set_money_amounts.price_rules.rule_type",
|
||||
"price_list_rules.price_list_rule_values",
|
||||
"price_list_rules.rule_type",
|
||||
],
|
||||
select: [
|
||||
"id",
|
||||
"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_list_rules.price_list_rule_values.value",
|
||||
"price_list_rules.rule_type.rule_attribute",
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
expect(priceList).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
price_set_money_amounts: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
rules_count: 2,
|
||||
price_rules: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
value: "new test",
|
||||
rule_type: expect.objectContaining({
|
||||
rule_attribute: "region_id",
|
||||
}),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
value: "new test",
|
||||
rule_type: expect.objectContaining({
|
||||
rule_attribute: "customer_group_id",
|
||||
}),
|
||||
}),
|
||||
]),
|
||||
price_list: expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
}),
|
||||
money_amount: expect.objectContaining({
|
||||
amount: 123,
|
||||
currency_code: "EUR",
|
||||
}),
|
||||
}),
|
||||
]),
|
||||
price_list_rules: [],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should fail to add a price with non-existing rule-types in the price-set to a priceList", async () => {
|
||||
await service.createRuleTypes([
|
||||
{ name: "twitter_handle", rule_attribute: "twitter_handle" },
|
||||
{ name: "region_id", rule_attribute: "region_id" },
|
||||
])
|
||||
|
||||
const [priceSet] = await service.create([
|
||||
{ rules: [{ rule_attribute: "region_id" }] },
|
||||
])
|
||||
|
||||
await service.addPriceListPrices([
|
||||
{
|
||||
price_list_id: "price-list-1",
|
||||
prices: [
|
||||
{
|
||||
id: "test-price-id",
|
||||
amount: 123,
|
||||
currency_code: "EUR",
|
||||
price_set_id: priceSet.id,
|
||||
rules: { region_id: "test" },
|
||||
} as any,
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
const error = await service
|
||||
.updatePriceListPrices([
|
||||
{
|
||||
price_list_id: "price-list-1",
|
||||
prices: [
|
||||
{
|
||||
id: "test-price-id",
|
||||
amount: 123,
|
||||
price_set_id: priceSet.id,
|
||||
rules: { twitter_handle: "owjuhl" },
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
.catch((e) => e)
|
||||
|
||||
expect(error.message).toEqual(
|
||||
`Invalid rule type configuration: Price set rules doesn't exist for rule_attribute "twitter_handle" in price set ${priceSet.id}`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("removePrices", () => {
|
||||
it("should remove prices from a priceList successfully", async () => {
|
||||
const [priceSet] = await service.create([
|
||||
{ rules: [{ rule_attribute: "region_id" }] },
|
||||
])
|
||||
|
||||
await service.addPriceListPrices([
|
||||
{
|
||||
price_list_id: "price-list-1",
|
||||
prices: [
|
||||
{
|
||||
amount: 123,
|
||||
currency_code: "EUR",
|
||||
price_set_id: priceSet.id,
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
let [priceList] = await service.listPriceLists(
|
||||
{ id: ["price-list-1"] },
|
||||
{
|
||||
relations: ["price_set_money_amounts"],
|
||||
select: ["price_set_money_amounts.id"],
|
||||
}
|
||||
)
|
||||
|
||||
await service.removePrices(
|
||||
priceList.price_set_money_amounts!.map((psma) => psma.id)
|
||||
)
|
||||
;[priceList] = await service.listPriceLists(
|
||||
{ id: ["price-list-1"] },
|
||||
{
|
||||
relations: ["price_set_money_amounts"],
|
||||
select: ["id", "price_set_money_amounts.id"],
|
||||
}
|
||||
)
|
||||
|
||||
expect(priceList).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
price_set_money_amounts: [],
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
+2
-2
@@ -5,10 +5,10 @@ import {
|
||||
} from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
import { PriceSetRuleType } from "../../../../src"
|
||||
import { seedPriceData } from "../../../__fixtures__/seed-price-data"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
|
||||
import { PriceSetRuleType } from "../../../../src"
|
||||
import { seedPriceData } from "../../../__fixtures__/seed-price-data"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
|
||||
@@ -1031,9 +1031,7 @@ export default class PricingModuleService<
|
||||
.flat()
|
||||
|
||||
const existingPriceListRules = await this.listPriceListRules(
|
||||
{
|
||||
id: priceListRuleIds,
|
||||
},
|
||||
{ id: priceListRuleIds },
|
||||
{},
|
||||
sharedContext
|
||||
)
|
||||
@@ -1046,9 +1044,7 @@ export default class PricingModuleService<
|
||||
}
|
||||
|
||||
const ruleTypes = await this.listRuleTypes(
|
||||
{
|
||||
rule_attribute: ruleAttributes,
|
||||
},
|
||||
{ rule_attribute: ruleAttributes },
|
||||
{ take: null },
|
||||
sharedContext
|
||||
)
|
||||
@@ -1059,6 +1055,7 @@ export default class PricingModuleService<
|
||||
|
||||
for (const priceListData of data) {
|
||||
const { rules, ...priceListOnlyData } = priceListData
|
||||
|
||||
const updatePriceListData: any = {
|
||||
...priceListOnlyData,
|
||||
}
|
||||
@@ -1083,12 +1080,7 @@ export default class PricingModuleService<
|
||||
|
||||
if (!ruleType) {
|
||||
;[ruleType] = await this.createRuleTypes(
|
||||
[
|
||||
{
|
||||
name: ruleAttribute,
|
||||
rule_attribute: ruleAttribute,
|
||||
},
|
||||
],
|
||||
[{ name: ruleAttribute, rule_attribute: ruleAttribute }],
|
||||
sharedContext
|
||||
)
|
||||
|
||||
@@ -1107,12 +1099,7 @@ export default class PricingModuleService<
|
||||
|
||||
for (const ruleValue of ruleValues as string[]) {
|
||||
await this.priceListRuleValueService_.create(
|
||||
[
|
||||
{
|
||||
price_list_rule: priceListRule,
|
||||
value: ruleValue,
|
||||
},
|
||||
],
|
||||
[{ price_list_rule: priceListRule, value: ruleValue }],
|
||||
sharedContext
|
||||
)
|
||||
}
|
||||
@@ -1161,6 +1148,185 @@ export default class PricingModuleService<
|
||||
})
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async updatePriceListPrices(
|
||||
data: PricingTypes.UpdatePriceListPricesDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<PricingTypes.PriceListDTO[]> {
|
||||
return await this.updatePriceListPrices_(data, sharedContext)
|
||||
}
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
protected async updatePriceListPrices_(
|
||||
data: PricingTypes.UpdatePriceListPricesDTO[],
|
||||
sharedContext: Context = {}
|
||||
): Promise<PricingTypes.PriceListDTO[]> {
|
||||
const ruleTypeAttributes: string[] = []
|
||||
const priceListIds: string[] = []
|
||||
const moneyAmountIds: string[] = []
|
||||
const priceSetIds = data
|
||||
.map((d) => d.prices.map((price) => price.price_set_id))
|
||||
.flat()
|
||||
|
||||
for (const priceListData of data) {
|
||||
priceListIds.push(priceListData.price_list_id)
|
||||
|
||||
for (const price of priceListData.prices) {
|
||||
moneyAmountIds.push(price.id)
|
||||
ruleTypeAttributes.push(...Object.keys(price.rules || {}))
|
||||
}
|
||||
}
|
||||
|
||||
const moneyAmounts = await this.listMoneyAmounts(
|
||||
{ id: moneyAmountIds },
|
||||
{
|
||||
take: null,
|
||||
relations: [
|
||||
"price_set_money_amount",
|
||||
"price_set_money_amount.price_rules",
|
||||
],
|
||||
},
|
||||
sharedContext
|
||||
)
|
||||
|
||||
const moneyAmountMap: Map<string, PricingTypes.MoneyAmountDTO> = new Map(
|
||||
moneyAmounts.map((ma) => [ma.id, ma])
|
||||
)
|
||||
|
||||
const ruleTypes = await this.listRuleTypes(
|
||||
{ rule_attribute: ruleTypeAttributes },
|
||||
{ take: null },
|
||||
sharedContext
|
||||
)
|
||||
|
||||
const ruleTypeMap: Map<string, RuleTypeDTO> = new Map(
|
||||
ruleTypes.map((rt) => [rt.rule_attribute, rt])
|
||||
)
|
||||
|
||||
const priceSets = await this.list(
|
||||
{ id: priceSetIds },
|
||||
{ relations: ["rule_types"] },
|
||||
sharedContext
|
||||
)
|
||||
|
||||
const priceSetRuleTypeMap: Map<string, Set<string>> = priceSets.reduce(
|
||||
(acc, curr) => {
|
||||
const priceSetRuleAttributeSet: Set<string> =
|
||||
acc.get(curr.id) || new Set()
|
||||
|
||||
for (const rt of curr.rule_types ?? []) {
|
||||
priceSetRuleAttributeSet.add(rt.rule_attribute)
|
||||
}
|
||||
|
||||
acc.set(curr.id, priceSetRuleAttributeSet)
|
||||
return acc
|
||||
},
|
||||
new Map()
|
||||
)
|
||||
|
||||
const ruleTypeErrors: string[] = []
|
||||
|
||||
for (const priceListData of data) {
|
||||
for (const price of priceListData.prices) {
|
||||
for (const ruleAttribute of Object.keys(price.rules ?? {})) {
|
||||
if (
|
||||
!priceSetRuleTypeMap.get(price.price_set_id)?.has(ruleAttribute)
|
||||
) {
|
||||
ruleTypeErrors.push(
|
||||
`rule_attribute "${ruleAttribute}" in price set ${price.price_set_id}`
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ruleTypeErrors.length) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
`Invalid rule type configuration: Price set rules doesn't exist for ${ruleTypeErrors.join(
|
||||
", "
|
||||
)}`
|
||||
)
|
||||
}
|
||||
|
||||
const priceLists = await this.listPriceLists(
|
||||
{ id: priceListIds },
|
||||
{ take: null },
|
||||
sharedContext
|
||||
)
|
||||
|
||||
const priceListMap = new Map(priceLists.map((p) => [p.id, p]))
|
||||
|
||||
for (const { price_list_id: priceListId, prices } of data) {
|
||||
const priceList = priceListMap.get(priceListId)
|
||||
|
||||
if (!priceList) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
`Price list with id: ${priceListId} not found`
|
||||
)
|
||||
}
|
||||
|
||||
const moneyAmountsToUpdate: PricingTypes.UpdateMoneyAmountDTO[] = []
|
||||
const priceRulesToDelete: string[] = []
|
||||
const priceRulesToCreate: PricingTypes.CreatePriceRuleDTO[] = []
|
||||
const psmaToUpdate: ServiceTypes.UpdatePriceSetMoneyAmountDTO[] = []
|
||||
|
||||
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 priceRules = priceSetMoneyAmount.price_rules!
|
||||
|
||||
moneyAmountsToUpdate.push(priceData)
|
||||
|
||||
if (typeof rules === "undefined") {
|
||||
continue
|
||||
}
|
||||
|
||||
psmaToUpdate.push({
|
||||
id: priceSetMoneyAmount!.id,
|
||||
rules_count: Object.keys(rules).length,
|
||||
})
|
||||
|
||||
priceRulesToDelete.push(...priceRules.map((pr) => pr.id))
|
||||
priceRulesToCreate.push(
|
||||
...Object.entries(rules).map(([ruleAttribute, ruleValue]) => ({
|
||||
price_set_id: price.price_set_id,
|
||||
rule_type_id: ruleTypeMap.get(ruleAttribute)!.id,
|
||||
value: ruleValue,
|
||||
price_set_money_amount_id: priceSetMoneyAmount.id,
|
||||
}))
|
||||
)
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
this.moneyAmountService_.update(moneyAmountsToUpdate),
|
||||
this.priceRuleService_.delete(priceRulesToDelete),
|
||||
this.priceRuleService_.create(priceRulesToCreate),
|
||||
this.priceSetMoneyAmountService_.update(psmaToUpdate),
|
||||
])
|
||||
}
|
||||
|
||||
return priceLists
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async removePrices(
|
||||
ids: string[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
await this.removePrices_(ids, sharedContext)
|
||||
}
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
protected async removePrices_(
|
||||
ids: string[],
|
||||
sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
await this.priceSetMoneyAmountService_.delete(ids, sharedContext)
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async addPriceListPrices(
|
||||
data: PricingTypes.AddPriceListPricesDTO[],
|
||||
@@ -1179,7 +1345,7 @@ export default class PricingModuleService<
|
||||
const priceSetIds: string[] = []
|
||||
|
||||
for (const priceListData of data) {
|
||||
priceListIds.push(priceListData.priceListId)
|
||||
priceListIds.push(priceListData.price_list_id)
|
||||
|
||||
for (const price of priceListData.prices) {
|
||||
ruleTypeAttributes.push(...Object.keys(price.rules || {}))
|
||||
@@ -1251,7 +1417,7 @@ export default class PricingModuleService<
|
||||
|
||||
const priceListMap = new Map(priceLists.map((p) => [p.id, p]))
|
||||
|
||||
for (const { priceListId, prices } of data) {
|
||||
for (const { price_list_id: priceListId, prices } of data) {
|
||||
const priceList = priceListMap.get(priceListId)
|
||||
|
||||
if (!priceList) {
|
||||
@@ -1322,7 +1488,7 @@ export default class PricingModuleService<
|
||||
sharedContext: Context = {}
|
||||
): Promise<PricingTypes.PriceListDTO[]> {
|
||||
const priceLists = await this.priceListService_.list(
|
||||
{ id: data.map((d) => d.priceListId) },
|
||||
{ id: data.map((d) => d.price_list_id) },
|
||||
{
|
||||
relations: ["price_list_rules", "price_list_rules.rule_type"],
|
||||
},
|
||||
@@ -1347,7 +1513,7 @@ export default class PricingModuleService<
|
||||
|
||||
const priceRuleValues = new Map<string, Map<string, string[]>>()
|
||||
|
||||
for (const { priceListId, rules } of data) {
|
||||
for (const { price_list_id: priceListId, rules } of data) {
|
||||
const priceList = priceListMap.get(priceListId)
|
||||
|
||||
if (!priceList) {
|
||||
@@ -1465,7 +1631,7 @@ export default class PricingModuleService<
|
||||
sharedContext: Context = {}
|
||||
): Promise<PricingTypes.PriceListDTO[]> {
|
||||
const priceLists = await this.priceListService_.list(
|
||||
{ id: data.map((d) => d.priceListId) },
|
||||
{ id: data.map((d) => d.price_list_id) },
|
||||
{
|
||||
relations: ["price_list_rules", "price_list_rules.rule_type"],
|
||||
},
|
||||
@@ -1475,7 +1641,7 @@ export default class PricingModuleService<
|
||||
const priceListMap = new Map(priceLists.map((p) => [p.id, p]))
|
||||
|
||||
const idsToDelete: string[] = []
|
||||
for (const { priceListId, rules } of data) {
|
||||
for (const { price_list_id: priceListId, rules } of data) {
|
||||
const priceList = priceListMap.get(priceListId)
|
||||
|
||||
if (!priceList) {
|
||||
|
||||
@@ -3,8 +3,8 @@ import { PriceListStatus, PriceListType } from "@medusajs/utils"
|
||||
export interface CreatePriceListDTO {
|
||||
title: string
|
||||
description: string
|
||||
starts_at?: Date | string | null
|
||||
ends_at?: Date | string | null
|
||||
starts_at?: string | null
|
||||
ends_at?: string | null
|
||||
status?: PriceListStatus
|
||||
type?: PriceListType
|
||||
rules_count?: number
|
||||
@@ -13,8 +13,8 @@ export interface CreatePriceListDTO {
|
||||
export interface UpdatePriceListDTO {
|
||||
id: string
|
||||
title?: string
|
||||
starts_at?: Date | string | null
|
||||
ends_at?: Date | string | null
|
||||
starts_at?: string | null
|
||||
ends_at?: string | null
|
||||
status?: PriceListStatus
|
||||
number_rules?: number
|
||||
}
|
||||
@@ -18,10 +18,10 @@ export interface UpdateMoneyAmountDTO {
|
||||
|
||||
export interface MoneyAmountDTO {
|
||||
id: string
|
||||
currency_code?: string
|
||||
amount?: number
|
||||
min_quantity?: number
|
||||
max_quantity?: number
|
||||
currency_code?: string | null
|
||||
amount?: number | null
|
||||
min_quantity?: number | null
|
||||
max_quantity?: number | null
|
||||
price_set_money_amount?: PriceSetMoneyAmountDTO
|
||||
created_at: Date
|
||||
updated_at: Date
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { PriceListStatus, PriceListType } from "@medusajs/utils"
|
||||
import {
|
||||
BaseFilterable,
|
||||
MoneyAmountDTO,
|
||||
@@ -6,12 +5,13 @@ import {
|
||||
PriceSetMoneyAmountDTO,
|
||||
RuleTypeDTO,
|
||||
} from "@medusajs/types"
|
||||
import { PriceListStatus, PriceListType } from "@medusajs/utils"
|
||||
|
||||
export interface CreatePriceListDTO {
|
||||
title: string
|
||||
description: string
|
||||
starts_at?: Date | string | null
|
||||
ends_at?: Date | string | null
|
||||
starts_at?: string | null
|
||||
ends_at?: string | null
|
||||
status?: PriceListStatus
|
||||
type?: PriceListType
|
||||
number_rules?: number
|
||||
@@ -20,8 +20,8 @@ export interface CreatePriceListDTO {
|
||||
export interface UpdatePriceListDTO {
|
||||
id: string
|
||||
title?: string
|
||||
starts_at?: Date | string | null
|
||||
ends_at?: Date | string | null
|
||||
starts_at?: string | null
|
||||
ends_at?: string | null
|
||||
status?: PriceListStatus
|
||||
number_rules?: number
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ export interface UpdatePriceSetMoneyAmountDTO {
|
||||
title?: string
|
||||
price_set?: PriceSetDTO
|
||||
money_amount?: MoneyAmountDTO
|
||||
rules_count?: number
|
||||
}
|
||||
|
||||
export interface CreatePriceSetMoneyAmountDTO {
|
||||
|
||||
Reference in new issue
Block a user