fix(medusa, pricing, types): pass dates as Date-objects rather than strings to the pricing module (#5768)
* init * remove date string validator; * add transformOptionalDate transformer to api * move type conversion to the datalayer * fix final module integration test * update arrow-function * make string optional * move work to utils * make check for value exists * move util back to pricng * change utils * refactor get-iso-string * fix build * flip transform condition * add null check for isDate * feat(pricing): Separate Pricing Module internal types from `@medusajs/types` (#5777) * create types for pricing repositories * create RepositoryTypes input * add service types * use models for repository types * fix build * update types to match interface types * add aliases * types instead of moduletypes * move repository to types for pricing module * add changeset * fix merge error * fix conflict * fix build * re-add validation of dates in updatePriceLists_
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import { Currency } from "@models"
|
||||
import { CurrencyRepository } from "@repositories"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
currencyRepository: DAL.RepositoryService
|
||||
@@ -23,10 +24,10 @@ export default class CurrencyService<TEntity extends Currency = Currency> {
|
||||
@InjectManager("currencyRepository_")
|
||||
async retrieve(
|
||||
currencyCode: string,
|
||||
config: FindConfig<PricingTypes.CurrencyDTO> = {},
|
||||
config: FindConfig<ServiceTypes.CurrencyDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<Currency, PricingTypes.CurrencyDTO>({
|
||||
return (await retrieveEntity<Currency, ServiceTypes.CurrencyDTO>({
|
||||
id: currencyCode,
|
||||
identifierColumn: "code",
|
||||
entityName: Currency.name,
|
||||
@@ -38,8 +39,8 @@ export default class CurrencyService<TEntity extends Currency = Currency> {
|
||||
|
||||
@InjectManager("currencyRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterableCurrencyProps = {},
|
||||
config: FindConfig<PricingTypes.CurrencyDTO> = {},
|
||||
filters: ServiceTypes.FilterableCurrencyProps = {},
|
||||
config: FindConfig<ServiceTypes.CurrencyDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.currencyRepository_.find(
|
||||
@@ -50,8 +51,8 @@ export default class CurrencyService<TEntity extends Currency = Currency> {
|
||||
|
||||
@InjectManager("currencyRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterableCurrencyProps = {},
|
||||
config: FindConfig<PricingTypes.CurrencyDTO> = {},
|
||||
filters: ServiceTypes.FilterableCurrencyProps = {},
|
||||
config: FindConfig<ServiceTypes.CurrencyDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
return (await this.currencyRepository_.findAndCount(
|
||||
@@ -61,8 +62,8 @@ export default class CurrencyService<TEntity extends Currency = Currency> {
|
||||
}
|
||||
|
||||
private buildQueryForList(
|
||||
filters: PricingTypes.FilterableCurrencyProps = {},
|
||||
config: FindConfig<PricingTypes.CurrencyDTO> = {}
|
||||
filters: ServiceTypes.FilterableCurrencyProps = {},
|
||||
config: FindConfig<ServiceTypes.CurrencyDTO> = {}
|
||||
) {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<Currency>(filters, config)
|
||||
|
||||
@@ -75,7 +76,7 @@ export default class CurrencyService<TEntity extends Currency = Currency> {
|
||||
|
||||
@InjectTransactionManager("currencyRepository_")
|
||||
async create(
|
||||
data: PricingTypes.CreateCurrencyDTO[],
|
||||
data: ServiceTypes.CreateCurrencyDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.currencyRepository_ as CurrencyRepository).create(
|
||||
@@ -86,7 +87,7 @@ export default class CurrencyService<TEntity extends Currency = Currency> {
|
||||
|
||||
@InjectTransactionManager("currencyRepository_")
|
||||
async update(
|
||||
data: PricingTypes.UpdateCurrencyDTO[],
|
||||
data: ServiceTypes.UpdateCurrencyDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.currencyRepository_ as CurrencyRepository).update(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import { MoneyAmount } from "@models"
|
||||
import { MoneyAmountRepository } from "@repositories"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
moneyAmountRepository: DAL.RepositoryService
|
||||
@@ -25,10 +26,10 @@ export default class MoneyAmountService<
|
||||
@InjectManager("moneyAmountRepository_")
|
||||
async retrieve(
|
||||
moneyAmountId: string,
|
||||
config: FindConfig<PricingTypes.MoneyAmountDTO> = {},
|
||||
config: FindConfig<ServiceTypes.MoneyAmountDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<MoneyAmount, PricingTypes.MoneyAmountDTO>({
|
||||
return (await retrieveEntity<MoneyAmount, ServiceTypes.MoneyAmountDTO>({
|
||||
id: moneyAmountId,
|
||||
entityName: MoneyAmount.name,
|
||||
repository: this.moneyAmountRepository_,
|
||||
@@ -39,8 +40,8 @@ export default class MoneyAmountService<
|
||||
|
||||
@InjectManager("moneyAmountRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterableMoneyAmountProps = {},
|
||||
config: FindConfig<PricingTypes.MoneyAmountDTO> = {},
|
||||
filters: ServiceTypes.FilterableMoneyAmountProps = {},
|
||||
config: FindConfig<ServiceTypes.MoneyAmountDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<MoneyAmount>(
|
||||
@@ -56,8 +57,8 @@ export default class MoneyAmountService<
|
||||
|
||||
@InjectManager("moneyAmountRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterableMoneyAmountProps = {},
|
||||
config: FindConfig<PricingTypes.MoneyAmountDTO> = {},
|
||||
filters: ServiceTypes.FilterableMoneyAmountProps = {},
|
||||
config: FindConfig<ServiceTypes.MoneyAmountDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<MoneyAmount>(
|
||||
@@ -73,7 +74,7 @@ export default class MoneyAmountService<
|
||||
|
||||
@InjectTransactionManager("moneyAmountRepository_")
|
||||
async create(
|
||||
data: PricingTypes.CreateMoneyAmountDTO[],
|
||||
data: ServiceTypes.CreateMoneyAmountDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.moneyAmountRepository_ as MoneyAmountRepository).create(
|
||||
@@ -84,7 +85,7 @@ export default class MoneyAmountService<
|
||||
|
||||
@InjectTransactionManager("moneyAmountRepository_")
|
||||
async update(
|
||||
data: PricingTypes.UpdateMoneyAmountDTO[],
|
||||
data: ServiceTypes.UpdateMoneyAmountDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.moneyAmountRepository_ as MoneyAmountRepository).update(
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
doNotForceTransaction,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
doNotForceTransaction,
|
||||
retrieveEntity,
|
||||
shouldForceTransaction,
|
||||
} from "@medusajs/utils"
|
||||
import { PriceListRuleValue } from "@models"
|
||||
import { PriceListRuleValueRepository } from "@repositories"
|
||||
|
||||
import { CreatePriceListRuleValueDTO } from "../types"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
priceListRuleValueRepository: DAL.RepositoryService
|
||||
@@ -29,12 +28,12 @@ export default class PriceListRuleValueService<
|
||||
@InjectManager("priceListRuleValueRepository_")
|
||||
async retrieve(
|
||||
priceSetId: string,
|
||||
config: FindConfig<PricingTypes.PriceListRuleValueDTO> = {},
|
||||
config: FindConfig<ServiceTypes.PriceListRuleValueDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<
|
||||
PriceListRuleValue,
|
||||
PricingTypes.PriceListRuleValueDTO
|
||||
ServiceTypes.PriceListRuleValueDTO
|
||||
>({
|
||||
id: priceSetId,
|
||||
entityName: PriceListRuleValue.name,
|
||||
@@ -46,8 +45,8 @@ export default class PriceListRuleValueService<
|
||||
|
||||
@InjectManager("priceListRuleValueRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterablePriceListRuleValueProps = {},
|
||||
config: FindConfig<PricingTypes.PriceListRuleValueDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceListRuleValueProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceListRuleValueDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceListRuleValue>(
|
||||
@@ -63,8 +62,8 @@ export default class PriceListRuleValueService<
|
||||
|
||||
@InjectManager("priceListRuleValueRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterablePriceListRuleValueProps = {},
|
||||
config: FindConfig<PricingTypes.PriceListRuleValueDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceListRuleValueProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceListRuleValueDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceListRuleValue>(
|
||||
@@ -83,7 +82,7 @@ export default class PriceListRuleValueService<
|
||||
"priceListRuleValueRepository_"
|
||||
)
|
||||
async create(
|
||||
data: CreatePriceListRuleValueDTO[],
|
||||
data: ServiceTypes.CreatePriceListRuleValueDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
@@ -96,7 +95,7 @@ export default class PriceListRuleValueService<
|
||||
"priceListRuleValueRepository_"
|
||||
)
|
||||
async update(
|
||||
data: PricingTypes.UpdatePriceListRuleValueDTO[],
|
||||
data: ServiceTypes.UpdatePriceListRuleValueDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
doNotForceTransaction,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
doNotForceTransaction,
|
||||
retrieveEntity,
|
||||
shouldForceTransaction,
|
||||
} from "@medusajs/utils"
|
||||
import { PriceListRule } from "@models"
|
||||
import { PriceListRuleRepository } from "@repositories"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
priceListRuleRepository: DAL.RepositoryService
|
||||
@@ -27,10 +28,10 @@ export default class PriceListRuleService<
|
||||
@InjectManager("priceListRuleRepository_")
|
||||
async retrieve(
|
||||
priceSetId: string,
|
||||
config: FindConfig<PricingTypes.PriceListRuleDTO> = {},
|
||||
config: FindConfig<ServiceTypes.PriceListRuleDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<PriceListRule, PricingTypes.PriceListRuleDTO>({
|
||||
return (await retrieveEntity<PriceListRule, ServiceTypes.PriceListRuleDTO>({
|
||||
id: priceSetId,
|
||||
entityName: PriceListRule.name,
|
||||
repository: this.priceListRuleRepository_,
|
||||
@@ -41,8 +42,8 @@ export default class PriceListRuleService<
|
||||
|
||||
@InjectManager("priceListRuleRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterablePriceListRuleProps = {},
|
||||
config: FindConfig<PricingTypes.PriceListRuleDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceListRuleProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceListRuleDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceListRule>(
|
||||
@@ -58,8 +59,8 @@ export default class PriceListRuleService<
|
||||
|
||||
@InjectManager("priceListRuleRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterablePriceListRuleProps = {},
|
||||
config: FindConfig<PricingTypes.PriceListRuleDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceListRuleProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceListRuleDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceListRule>(
|
||||
@@ -75,7 +76,7 @@ export default class PriceListRuleService<
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, "priceListRuleRepository_")
|
||||
async create(
|
||||
data: PricingTypes.CreatePriceListRuleDTO[],
|
||||
data: ServiceTypes.CreatePriceListRuleDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
@@ -85,7 +86,7 @@ export default class PriceListRuleService<
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, "priceListRuleRepository_")
|
||||
async update(
|
||||
data: PricingTypes.UpdatePriceListRuleDTO[],
|
||||
data: ServiceTypes.UpdatePriceListRuleDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
doNotForceTransaction,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
doNotForceTransaction,
|
||||
retrieveEntity,
|
||||
shouldForceTransaction,
|
||||
} from "@medusajs/utils"
|
||||
import { PriceList } from "@models"
|
||||
import { PriceListRepository } from "@repositories"
|
||||
import { CreatePriceListDTO } from "../types"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
priceListRepository: DAL.RepositoryService
|
||||
@@ -26,10 +26,10 @@ export default class PriceListService<TEntity extends PriceList = PriceList> {
|
||||
@InjectManager("priceListRepository_")
|
||||
async retrieve(
|
||||
priceListId: string,
|
||||
config: FindConfig<PricingTypes.PriceListDTO> = {},
|
||||
config: FindConfig<ServiceTypes.PriceListDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<PriceList, PricingTypes.PriceListDTO>({
|
||||
return (await retrieveEntity<PriceList, ServiceTypes.PriceListDTO>({
|
||||
id: priceListId,
|
||||
entityName: PriceList.name,
|
||||
repository: this.priceListRepository_,
|
||||
@@ -40,8 +40,8 @@ export default class PriceListService<TEntity extends PriceList = PriceList> {
|
||||
|
||||
@InjectManager("priceListRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterablePriceListProps = {},
|
||||
config: FindConfig<PricingTypes.PriceListDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceListProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceListDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceList>(filters, config)
|
||||
@@ -54,8 +54,8 @@ export default class PriceListService<TEntity extends PriceList = PriceList> {
|
||||
|
||||
@InjectManager("priceListRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterablePriceListProps = {},
|
||||
config: FindConfig<PricingTypes.PriceListDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceListProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceListDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceList>(filters, config)
|
||||
@@ -68,7 +68,7 @@ export default class PriceListService<TEntity extends PriceList = PriceList> {
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, "priceListRepository_")
|
||||
async create(
|
||||
data: CreatePriceListDTO[],
|
||||
data: ServiceTypes.CreatePriceListDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.priceListRepository_ as PriceListRepository).create(
|
||||
@@ -79,7 +79,7 @@ export default class PriceListService<TEntity extends PriceList = PriceList> {
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, "priceListRepository_")
|
||||
async update(
|
||||
data: Omit<PricingTypes.UpdatePriceListDTO, "rules">[],
|
||||
data: Omit<ServiceTypes.UpdatePriceListDTO, "rules">[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.priceListRepository_ as PriceListRepository).update(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
@@ -9,6 +9,8 @@ import {
|
||||
import { PriceRule } from "@models"
|
||||
import { PriceRuleRepository } from "@repositories"
|
||||
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
priceRuleRepository: DAL.RepositoryService
|
||||
}
|
||||
@@ -23,10 +25,10 @@ export default class PriceRuleService<TEntity extends PriceRule = PriceRule> {
|
||||
@InjectManager("priceRuleRepository_")
|
||||
async retrieve(
|
||||
priceRuleId: string,
|
||||
config: FindConfig<PricingTypes.PriceRuleDTO> = {},
|
||||
config: FindConfig<ServiceTypes.PriceRuleDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<PriceRule, PricingTypes.PriceRuleDTO>({
|
||||
return (await retrieveEntity<PriceRule, ServiceTypes.PriceRuleDTO>({
|
||||
id: priceRuleId,
|
||||
entityName: PriceRule.name,
|
||||
repository: this.priceRuleRepository_,
|
||||
@@ -37,8 +39,8 @@ export default class PriceRuleService<TEntity extends PriceRule = PriceRule> {
|
||||
|
||||
@InjectManager("priceRuleRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterablePriceRuleProps = {},
|
||||
config: FindConfig<PricingTypes.PriceRuleDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceRuleProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceRuleDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryConfig = ModulesSdkUtils.buildQuery<PriceRule>(filters, config)
|
||||
@@ -51,8 +53,8 @@ export default class PriceRuleService<TEntity extends PriceRule = PriceRule> {
|
||||
|
||||
@InjectManager("priceRuleRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterablePriceRuleProps = {},
|
||||
config: FindConfig<PricingTypes.PriceRuleDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceRuleProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceRuleDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryConfig = ModulesSdkUtils.buildQuery<PriceRule>(filters, config)
|
||||
@@ -65,7 +67,7 @@ export default class PriceRuleService<TEntity extends PriceRule = PriceRule> {
|
||||
|
||||
@InjectTransactionManager("priceRuleRepository_")
|
||||
async create(
|
||||
data: PricingTypes.CreatePriceRuleDTO[],
|
||||
data: ServiceTypes.CreatePriceRuleDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.priceRuleRepository_ as PriceRuleRepository).create(
|
||||
@@ -76,7 +78,7 @@ export default class PriceRuleService<TEntity extends PriceRule = PriceRule> {
|
||||
|
||||
@InjectTransactionManager("priceRuleRepository_")
|
||||
async update(
|
||||
data: PricingTypes.UpdatePriceRuleDTO[],
|
||||
data: ServiceTypes.UpdatePriceRuleDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.priceRuleRepository_ as PriceRuleRepository).update(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
retrieveEntity,
|
||||
} from "@medusajs/utils"
|
||||
import { PriceSetMoneyAmountRules } from "@models"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
priceSetMoneyAmountRulesRepository: DAL.RepositoryService
|
||||
@@ -25,12 +26,12 @@ export default class PriceSetMoneyAmountRulesService<
|
||||
@InjectManager("priceSetMoneyAmountRulesRepository_")
|
||||
async retrieve(
|
||||
priceSetMoneyAmountRulesId: string,
|
||||
config: FindConfig<PricingTypes.PriceSetMoneyAmountRulesDTO> = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountRulesDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<
|
||||
PriceSetMoneyAmountRules,
|
||||
PricingTypes.PriceSetMoneyAmountRulesDTO
|
||||
ServiceTypes.PriceSetMoneyAmountRulesDTO
|
||||
>({
|
||||
id: priceSetMoneyAmountRulesId,
|
||||
identifierColumn: "id",
|
||||
@@ -43,8 +44,8 @@ export default class PriceSetMoneyAmountRulesService<
|
||||
|
||||
@InjectManager("priceSetMoneyAmountRulesRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterablePriceSetMoneyAmountRulesProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetMoneyAmountRulesDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountRulesProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountRulesDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.priceSetMoneyAmountRulesRepository_.find(
|
||||
@@ -55,8 +56,8 @@ export default class PriceSetMoneyAmountRulesService<
|
||||
|
||||
@InjectManager("priceSetMoneyAmountRulesRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterablePriceSetMoneyAmountRulesProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetMoneyAmountRulesDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountRulesProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountRulesDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
return (await this.priceSetMoneyAmountRulesRepository_.findAndCount(
|
||||
@@ -66,8 +67,8 @@ export default class PriceSetMoneyAmountRulesService<
|
||||
}
|
||||
|
||||
private buildQueryForList(
|
||||
filters: PricingTypes.FilterablePriceSetMoneyAmountRulesProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetMoneyAmountRulesDTO> = {}
|
||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountRulesProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountRulesDTO> = {}
|
||||
) {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceSetMoneyAmountRules>(
|
||||
filters,
|
||||
@@ -79,7 +80,7 @@ export default class PriceSetMoneyAmountRulesService<
|
||||
|
||||
@InjectTransactionManager("priceSetMoneyAmountRulesRepository_")
|
||||
async create(
|
||||
data: PricingTypes.CreatePriceSetMoneyAmountRulesDTO[],
|
||||
data: ServiceTypes.CreatePriceSetMoneyAmountRulesDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.priceSetMoneyAmountRulesRepository_.create(
|
||||
@@ -90,7 +91,7 @@ export default class PriceSetMoneyAmountRulesService<
|
||||
|
||||
@InjectTransactionManager("priceSetMoneyAmountRulesRepository_")
|
||||
async update(
|
||||
data: PricingTypes.UpdatePriceSetMoneyAmountRulesDTO[],
|
||||
data: ServiceTypes.UpdatePriceSetMoneyAmountRulesDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.priceSetMoneyAmountRulesRepository_.update(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import { PriceSet, PriceSetMoneyAmount } from "@models"
|
||||
import { PriceSetMoneyAmountRepository } from "@repositories"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
priceSetMoneyAmountRepository: DAL.RepositoryService
|
||||
@@ -25,12 +26,12 @@ export default class PriceSetMoneyAmountService<
|
||||
@InjectManager("priceSetMoneyAmountRepository_")
|
||||
async retrieve(
|
||||
priceSetId: string,
|
||||
config: FindConfig<PricingTypes.PriceSetRuleTypeDTO> = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<
|
||||
PriceSetMoneyAmount,
|
||||
PricingTypes.PriceSetRuleTypeDTO
|
||||
ServiceTypes.PriceSetMoneyAmountDTO
|
||||
>({
|
||||
id: priceSetId,
|
||||
entityName: PriceSet.name,
|
||||
@@ -42,8 +43,8 @@ export default class PriceSetMoneyAmountService<
|
||||
|
||||
@InjectManager("priceSetMoneyAmountRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.priceSetMoneyAmountRepository_.find(
|
||||
@@ -54,8 +55,8 @@ export default class PriceSetMoneyAmountService<
|
||||
|
||||
@InjectManager("priceSetMoneyAmountRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
return (await this.priceSetMoneyAmountRepository_.findAndCount(
|
||||
@@ -65,8 +66,8 @@ export default class PriceSetMoneyAmountService<
|
||||
}
|
||||
|
||||
private buildQueryForList(
|
||||
filters: PricingTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> = {}
|
||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {}
|
||||
) {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceSet>(filters, config)
|
||||
|
||||
@@ -79,7 +80,7 @@ export default class PriceSetMoneyAmountService<
|
||||
|
||||
@InjectTransactionManager("priceSetMoneyAmountRepository_")
|
||||
async create(
|
||||
data: PricingTypes.CreatePriceSetMoneyAmountDTO[],
|
||||
data: ServiceTypes.CreatePriceSetMoneyAmountDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
@@ -90,7 +91,7 @@ export default class PriceSetMoneyAmountService<
|
||||
|
||||
@InjectTransactionManager("priceSetMoneyAmountRepository_")
|
||||
async update(
|
||||
data: PricingTypes.UpdatePriceSetMoneyAmountDTO[],
|
||||
data: ServiceTypes.UpdatePriceSetMoneyAmountDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import { PriceSet, PriceSetRuleType } from "@models"
|
||||
import { PriceSetRuleTypeRepository } from "src/repositories/price-set-rule-type"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
priceSetRuleTypeRepository: DAL.RepositoryService
|
||||
@@ -25,12 +26,12 @@ export default class PriceSetRuleTypeService<
|
||||
@InjectManager("priceSetRuleTypeRepository_")
|
||||
async retrieve(
|
||||
priceSetId: string,
|
||||
config: FindConfig<PricingTypes.PriceSetRuleTypeDTO> = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetRuleTypeDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<
|
||||
PriceSetRuleType,
|
||||
PricingTypes.PriceSetRuleTypeDTO
|
||||
ServiceTypes.PriceSetRuleTypeDTO
|
||||
>({
|
||||
id: priceSetId,
|
||||
entityName: PriceSet.name,
|
||||
@@ -42,8 +43,8 @@ export default class PriceSetRuleTypeService<
|
||||
|
||||
@InjectManager("priceSetRuleTypeRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.priceSetRuleTypeRepository_.find(
|
||||
@@ -54,8 +55,8 @@ export default class PriceSetRuleTypeService<
|
||||
|
||||
@InjectManager("priceSetRuleTypeRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
return (await this.priceSetRuleTypeRepository_.findAndCount(
|
||||
@@ -65,8 +66,8 @@ export default class PriceSetRuleTypeService<
|
||||
}
|
||||
|
||||
private buildQueryForList(
|
||||
filters: PricingTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> = {}
|
||||
filters: ServiceTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {}
|
||||
) {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceSet>(filters, config)
|
||||
|
||||
@@ -79,7 +80,7 @@ export default class PriceSetRuleTypeService<
|
||||
|
||||
@InjectTransactionManager("priceSetRuleTypeRepository_")
|
||||
async create(
|
||||
data: PricingTypes.CreatePriceSetRuleTypeDTO[],
|
||||
data: ServiceTypes.CreatePriceSetRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
@@ -89,7 +90,7 @@ export default class PriceSetRuleTypeService<
|
||||
|
||||
@InjectTransactionManager("priceSetRuleTypeRepository_")
|
||||
async update(
|
||||
data: PricingTypes.UpdatePriceSetRuleTypeDTO[],
|
||||
data: ServiceTypes.UpdatePriceSetRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
@@ -9,6 +9,8 @@ import {
|
||||
import { PriceSet } from "@models"
|
||||
import { PriceSetRepository } from "@repositories"
|
||||
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
priceSetRepository: DAL.RepositoryService
|
||||
}
|
||||
@@ -23,10 +25,10 @@ export default class PriceSetService<TEntity extends PriceSet = PriceSet> {
|
||||
@InjectManager("priceSetRepository_")
|
||||
async retrieve(
|
||||
priceSetId: string,
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<PriceSet, PricingTypes.PriceSetDTO>({
|
||||
return (await retrieveEntity<PriceSet, ServiceTypes.PriceSetDTO>({
|
||||
id: priceSetId,
|
||||
entityName: PriceSet.name,
|
||||
repository: this.priceSetRepository_,
|
||||
@@ -37,8 +39,8 @@ export default class PriceSetService<TEntity extends PriceSet = PriceSet> {
|
||||
|
||||
@InjectManager("priceSetRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterablePriceSetProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceSetProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceSet>(filters, config)
|
||||
@@ -51,8 +53,8 @@ export default class PriceSetService<TEntity extends PriceSet = PriceSet> {
|
||||
|
||||
@InjectManager("priceSetRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterablePriceSetProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceSetProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceSet>(filters, config)
|
||||
@@ -65,7 +67,7 @@ export default class PriceSetService<TEntity extends PriceSet = PriceSet> {
|
||||
|
||||
@InjectTransactionManager("priceSetRepository_")
|
||||
async create(
|
||||
data: Omit<PricingTypes.CreatePriceSetDTO, "rules">[],
|
||||
data: Omit<ServiceTypes.CreatePriceSetDTO, "rules">[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.priceSetRepository_ as PriceSetRepository).create(
|
||||
@@ -76,7 +78,7 @@ export default class PriceSetService<TEntity extends PriceSet = PriceSet> {
|
||||
|
||||
@InjectTransactionManager("priceSetRepository_")
|
||||
async update(
|
||||
data: Omit<PricingTypes.UpdatePriceSetDTO, "rules">[],
|
||||
data: Omit<ServiceTypes.UpdatePriceSetDTO, "rules">[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.priceSetRepository_ as PriceSetRepository).update(
|
||||
|
||||
@@ -7,9 +7,11 @@ import {
|
||||
FindConfig,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
MoneyAmountDTO,
|
||||
PriceSetDTO,
|
||||
PricingContext,
|
||||
PricingFilters,
|
||||
PricingRepositoryService,
|
||||
PricingTypes,
|
||||
RuleTypeDTO,
|
||||
} from "@medusajs/types"
|
||||
@@ -53,8 +55,9 @@ import {
|
||||
RuleTypeService,
|
||||
} from "@services"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import { CreatePriceListRuleValueDTO, PricingRepositoryService } from "../types"
|
||||
|
||||
import { validatePriceListDates } from "@utils"
|
||||
import { ServiceTypes } from "@types"
|
||||
import { CreatePriceListRuleValueDTO } from "src/types/services"
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
pricingRepository: PricingRepositoryService
|
||||
@@ -426,7 +429,7 @@ export default class PricingModuleService<
|
||||
// Price rules
|
||||
if (priceRulesData.length > 0) {
|
||||
await this.priceRuleService_.create(
|
||||
priceRulesData as PricingTypes.CreatePriceRuleDTO[],
|
||||
priceRulesData as ServiceTypes.CreatePriceRuleDTO[],
|
||||
sharedContext
|
||||
)
|
||||
}
|
||||
@@ -630,8 +633,8 @@ export default class PricingModuleService<
|
||||
|
||||
// Price set money amounts
|
||||
let maCursor = 0
|
||||
const priceSetMoneyAmountsBulkData = input.flatMap(
|
||||
({ priceSetId, prices }) =>
|
||||
const priceSetMoneyAmountsBulkData: unknown[] =
|
||||
input.flatMap(({ priceSetId, prices }) =>
|
||||
prices.map(() => {
|
||||
const ma = createdMoneyAmounts[maCursor]
|
||||
const numberOfRules = Object.entries(
|
||||
@@ -645,10 +648,10 @@ export default class PricingModuleService<
|
||||
rules_count: numberOfRules,
|
||||
}
|
||||
})
|
||||
)
|
||||
)
|
||||
const createdPriceSetMoneyAmounts =
|
||||
await this.priceSetMoneyAmountService_.create(
|
||||
priceSetMoneyAmountsBulkData as unknown as PricingTypes.CreatePriceSetMoneyAmountDTO[],
|
||||
priceSetMoneyAmountsBulkData as ServiceTypes.CreatePriceSetMoneyAmountDTO[],
|
||||
sharedContext
|
||||
)
|
||||
|
||||
@@ -661,19 +664,15 @@ export default class PricingModuleService<
|
||||
rulesCursor++
|
||||
return Object.entries(rules).map(([k, v]) => ({
|
||||
price_set_money_amount: priceSetMoneyAmount,
|
||||
rule_type: ruleTypeMap.get(priceSetId)!.get(k),
|
||||
rule_type_id: ruleTypeMap.get(priceSetId)!.get(k)!.id,
|
||||
price_set: priceSetId,
|
||||
value: v,
|
||||
price_list_id: "test", // TODO: accept title
|
||||
}))
|
||||
})
|
||||
)
|
||||
|
||||
if (priceRulesBulkData.length > 0) {
|
||||
await this.priceRuleService_.create(
|
||||
priceRulesBulkData as unknown as PricingTypes.CreatePriceRuleDTO[],
|
||||
sharedContext
|
||||
)
|
||||
await this.priceRuleService_.create(priceRulesBulkData, sharedContext)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1272,7 +1271,10 @@ export default class PricingModuleService<
|
||||
data: PricingTypes.CreatePriceRuleDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<PricingTypes.PriceRuleDTO[]> {
|
||||
const priceRules = await this.priceRuleService_.create(data, sharedContext)
|
||||
const priceRules = await this.priceRuleService_.create(
|
||||
data as ServiceTypes.CreatePriceRuleDTO[],
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return this.baseRepository_.serialize<PricingTypes.PriceRuleDTO[]>(
|
||||
priceRules,
|
||||
@@ -1428,7 +1430,9 @@ export default class PricingModuleService<
|
||||
const priceListsToCreate: PricingTypes.CreatePriceListDTO[] = []
|
||||
|
||||
for (const priceListData of data) {
|
||||
const { rules = {}, ...priceListOnlyData } = priceListData
|
||||
const { rules = {}, prices = [], ...priceListOnlyData } = priceListData
|
||||
|
||||
validatePriceListDates(priceListData)
|
||||
|
||||
priceListsToCreate.push({
|
||||
...priceListOnlyData,
|
||||
@@ -1494,7 +1498,7 @@ export default class PricingModuleService<
|
||||
title: "test",
|
||||
rules_count: Object.keys(priceRules).length,
|
||||
},
|
||||
] as unknown as PricingTypes.CreatePriceSetMoneyAmountDTO[],
|
||||
] as unknown as ServiceTypes.CreatePriceSetMoneyAmountDTO[],
|
||||
sharedContext
|
||||
)
|
||||
|
||||
@@ -1587,10 +1591,13 @@ export default class PricingModuleService<
|
||||
|
||||
for (const priceListData of data) {
|
||||
const { rules, ...priceListOnlyData } = priceListData
|
||||
const updatePriceListData = {
|
||||
const updatePriceListData: any = {
|
||||
...priceListOnlyData,
|
||||
}
|
||||
|
||||
validatePriceListDates(updatePriceListData)
|
||||
|
||||
|
||||
if (typeof rules === "object") {
|
||||
updatePriceListData.rules_count = Object.keys(rules).length
|
||||
}
|
||||
@@ -2012,7 +2019,7 @@ export default class PricingModuleService<
|
||||
),
|
||||
])
|
||||
|
||||
const priceListRuleValuesToCreate: CreatePriceListRuleValueDTO[] = []
|
||||
const priceListRuleValuesToCreate: unknown[] = []
|
||||
|
||||
for (const { id, price_list, rule_type } of createdRules) {
|
||||
const ruleValues = priceRuleValues.get(
|
||||
@@ -2041,7 +2048,9 @@ export default class PricingModuleService<
|
||||
this.priceListRuleValueService_.delete(
|
||||
priceListValuesToDelete.map((p) => p.id)
|
||||
),
|
||||
this.priceListRuleValueService_.create(priceListRuleValuesToCreate),
|
||||
this.priceListRuleValueService_.create(
|
||||
priceListRuleValuesToCreate as CreatePriceListRuleValueDTO[]
|
||||
),
|
||||
])
|
||||
|
||||
return this.baseRepository_.serialize<PricingTypes.PriceListDTO[]>(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
retrieveEntity,
|
||||
} from "@medusajs/utils"
|
||||
import { RuleType } from "@models"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
ruleTypeRepository: DAL.RepositoryService
|
||||
@@ -22,10 +23,10 @@ export default class RuleTypeService<TEntity extends RuleType = RuleType> {
|
||||
@InjectManager("ruleTypeRepository_")
|
||||
async retrieve(
|
||||
ruleTypeId: string,
|
||||
config: FindConfig<PricingTypes.RuleTypeDTO> = {},
|
||||
config: FindConfig<ServiceTypes.RuleTypeDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<RuleType, PricingTypes.RuleTypeDTO>({
|
||||
return (await retrieveEntity<RuleType, ServiceTypes.RuleTypeDTO>({
|
||||
id: ruleTypeId,
|
||||
identifierColumn: "id",
|
||||
entityName: RuleType.name,
|
||||
@@ -37,8 +38,8 @@ export default class RuleTypeService<TEntity extends RuleType = RuleType> {
|
||||
|
||||
@InjectManager("ruleTypeRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterableRuleTypeProps = {},
|
||||
config: FindConfig<PricingTypes.RuleTypeDTO> = {},
|
||||
filters: ServiceTypes.FilterableRuleTypeProps = {},
|
||||
config: FindConfig<ServiceTypes.RuleTypeDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<RuleType>(filters, config)
|
||||
@@ -51,8 +52,8 @@ export default class RuleTypeService<TEntity extends RuleType = RuleType> {
|
||||
|
||||
@InjectManager("ruleTypeRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterableRuleTypeProps = {},
|
||||
config: FindConfig<PricingTypes.RuleTypeDTO> = {},
|
||||
filters: ServiceTypes.FilterableRuleTypeProps = {},
|
||||
config: FindConfig<ServiceTypes.RuleTypeDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<RuleType>(filters, config)
|
||||
@@ -65,7 +66,7 @@ export default class RuleTypeService<TEntity extends RuleType = RuleType> {
|
||||
|
||||
@InjectTransactionManager("ruleTypeRepository_")
|
||||
async create(
|
||||
data: PricingTypes.CreateRuleTypeDTO[],
|
||||
data: ServiceTypes.CreateRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.ruleTypeRepository_.create(
|
||||
@@ -76,7 +77,7 @@ export default class RuleTypeService<TEntity extends RuleType = RuleType> {
|
||||
|
||||
@InjectTransactionManager("ruleTypeRepository_")
|
||||
async update(
|
||||
data: PricingTypes.UpdateRuleTypeDTO[],
|
||||
data: ServiceTypes.UpdateRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.ruleTypeRepository_.update(
|
||||
|
||||
Reference in New Issue
Block a user