import { Context, CreateMoneyAmountDTO, DAL, FindConfig, InternalModuleDeclaration, ModuleJoinerConfig, PriceSetDTO, PricingContext, PricingFilters, PricingTypes, RuleTypeDTO, } from "@medusajs/types" import { Currency, MoneyAmount, PriceRule, PriceSet, PriceSetMoneyAmount, PriceSetMoneyAmountRules, PriceSetRuleType, RuleType, } from "@models" import { CurrencyService, MoneyAmountService, PriceRuleService, PriceSetMoneyAmountRulesService, PriceSetMoneyAmountService, PriceSetRuleTypeService, PriceSetService, RuleTypeService, } from "@services" import { InjectManager, InjectTransactionManager, MedusaContext, MedusaError, groupBy, removeNullish, shouldForceTransaction, } from "@medusajs/utils" import { AddPricesDTO } from "@medusajs/types" import { joinerConfig } from "../joiner-config" import { PricingRepositoryService } from "../types" type InjectedDependencies = { baseRepository: DAL.RepositoryService pricingRepository: PricingRepositoryService currencyService: CurrencyService moneyAmountService: MoneyAmountService priceSetService: PriceSetService priceSetMoneyAmountRulesService: PriceSetMoneyAmountRulesService ruleTypeService: RuleTypeService priceRuleService: PriceRuleService priceSetRuleTypeService: PriceSetRuleTypeService priceSetMoneyAmountService: PriceSetMoneyAmountService } export default class PricingModuleService< TPriceSet extends PriceSet = PriceSet, TMoneyAmount extends MoneyAmount = MoneyAmount, TCurrency extends Currency = Currency, TRuleType extends RuleType = RuleType, TPriceSetMoneyAmountRules extends PriceSetMoneyAmountRules = PriceSetMoneyAmountRules, TPriceRule extends PriceRule = PriceRule, TPriceSetRuleType extends PriceSetRuleType = PriceSetRuleType, TPriceSetMoneyAmount extends PriceSetMoneyAmount = PriceSetMoneyAmount > implements PricingTypes.IPricingModuleService { protected baseRepository_: DAL.RepositoryService protected readonly pricingRepository_: PricingRepositoryService protected readonly currencyService_: CurrencyService protected readonly moneyAmountService_: MoneyAmountService protected readonly ruleTypeService_: RuleTypeService protected readonly priceSetService_: PriceSetService protected readonly priceSetMoneyAmountRulesService_: PriceSetMoneyAmountRulesService protected readonly priceRuleService_: PriceRuleService protected readonly priceSetRuleTypeService_: PriceSetRuleTypeService protected readonly priceSetMoneyAmountService_: PriceSetMoneyAmountService constructor( { baseRepository, pricingRepository, moneyAmountService, currencyService, ruleTypeService, priceSetService, priceSetMoneyAmountRulesService, priceRuleService, priceSetRuleTypeService, priceSetMoneyAmountService, }: InjectedDependencies, protected readonly moduleDeclaration: InternalModuleDeclaration ) { this.baseRepository_ = baseRepository this.pricingRepository_ = pricingRepository this.currencyService_ = currencyService this.moneyAmountService_ = moneyAmountService this.ruleTypeService_ = ruleTypeService this.priceSetService_ = priceSetService this.priceSetMoneyAmountRulesService_ = priceSetMoneyAmountRulesService this.ruleTypeService_ = ruleTypeService this.priceRuleService_ = priceRuleService this.priceSetRuleTypeService_ = priceSetRuleTypeService this.priceSetMoneyAmountService_ = priceSetMoneyAmountService } __joinerConfig(): ModuleJoinerConfig { return joinerConfig } @InjectManager("baseRepository_") async calculatePrices( pricingFilters: PricingFilters, pricingContext: PricingContext = { context: {} }, @MedusaContext() sharedContext: Context = {} ): Promise { const results = await this.pricingRepository_.calculatePrices( pricingFilters, pricingContext, sharedContext ) const pricesSetPricesMap = groupBy(results, "id") const calculatedPrices = pricingFilters.id.map( (priceSetId: string): PricingTypes.CalculatedPriceSetDTO => { // This is where we select prices, for now we just do a first match based on the database results // which is prioritized by number_rules first for exact match and then deafult_priority of the rule_type // inject custom price selection here const price = pricesSetPricesMap.get(priceSetId)?.[0] return { id: priceSetId, amount: price?.amount || null, currency_code: price?.currency_code || null, min_quantity: price?.min_quantity || null, max_quantity: price?.max_quantity || null, } } ) return JSON.parse(JSON.stringify(calculatedPrices)) } @InjectManager("baseRepository_") async retrieve( id: string, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} ): Promise { const priceSet = await this.priceSetService_.retrieve( id, config, sharedContext ) return this.baseRepository_.serialize(priceSet, { populate: true, }) } @InjectManager("baseRepository_") async list( filters: PricingTypes.FilterablePriceSetProps = {}, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} ): Promise { const priceSets = await this.priceSetService_.list( filters, config, sharedContext ) return this.baseRepository_.serialize( priceSets, { populate: true, } ) } @InjectManager("baseRepository_") async listAndCount( filters: PricingTypes.FilterablePriceSetProps = {}, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} ): Promise<[PricingTypes.PriceSetDTO[], number]> { const [priceSets, count] = await this.priceSetService_.listAndCount( filters, config, sharedContext ) return [ await this.baseRepository_.serialize( priceSets, { populate: true, } ), count, ] } async create( data: PricingTypes.CreatePriceSetDTO, sharedContext?: Context ): Promise async create( data: PricingTypes.CreatePriceSetDTO[], sharedContext?: Context ): Promise @InjectManager("baseRepository_") async create( data: PricingTypes.CreatePriceSetDTO | PricingTypes.CreatePriceSetDTO[], @MedusaContext() sharedContext: Context = {} ): Promise { const input = Array.isArray(data) ? data : [data] const priceSets = await this.create_(input, sharedContext) const dbPriceSets = await this.list( { id: priceSets.filter((p) => !!p).map((p) => p!.id) }, { relations: ["rule_types", "money_amounts", "price_rules"], } ) return (Array.isArray(data) ? dbPriceSets : dbPriceSets[0]) as unknown as | PriceSetDTO | PriceSetDTO[] } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") protected async create_( data: PricingTypes.CreatePriceSetDTO[], @MedusaContext() sharedContext: Context = {} ) { const ruleAttributes = data .map((d) => d.rules?.map((r) => r.rule_attribute) ?? []) .flat() const ruleTypes = await this.ruleTypeService_.list( { rule_attribute: ruleAttributes, }, {}, sharedContext ) const ruleTypeMap = ruleTypes.reduce((acc, curr) => { acc.set(curr.rule_attribute, curr) return acc }, new Map()) const invalidRuleAttributes = ruleAttributes.filter( (r) => !ruleTypeMap.has(r) ) if (invalidRuleAttributes.length > 0) { throw new MedusaError( MedusaError.Types.NOT_FOUND, `Rule types don't exist for: ${invalidRuleAttributes.join(", ")}` ) } const invalidMoneyAmountRule = data .map((d) => d.prices?.map((ma) => Object.keys(ma.rules)).flat() ?? []) .flat() .filter((r) => !ruleTypeMap.has(r)) if (invalidMoneyAmountRule.length > 0) { throw new MedusaError( MedusaError.Types.INVALID_DATA, `Rule types don't exist for money amounts with rule attribute: ${invalidMoneyAmountRule.join( ", " )}` ) } const priceSets = await Promise.all( data.map(async (d) => { const { rules, prices, ...rest } = d const [priceSet] = await this.priceSetService_.create( [rest], sharedContext ) if (rules?.length) { const priceSetRuleTypesCreate = rules!.map((r) => ({ rule_type: ruleTypeMap.get(r.rule_attribute), price_set: priceSet, })) await this.priceSetRuleTypeService_.create( priceSetRuleTypesCreate as unknown as PricingTypes.CreatePriceSetRuleTypeDTO[], sharedContext ) } if (prices?.length) { for (const ma of prices) { const [moneyAmount] = await this.moneyAmountService_.create( [ma] as unknown as CreateMoneyAmountDTO[], sharedContext ) const cleanRules = ma.rules ? removeNullish(ma.rules) : {} const numberOfRules = Object.entries(cleanRules).length const [priceSetMoneyAmount] = await this.priceSetMoneyAmountService_.create( [ { price_set: priceSet, money_amount: moneyAmount, title: "test", number_rules: numberOfRules, }, ] as unknown as PricingTypes.CreatePriceSetMoneyAmountDTO[], sharedContext ) if (numberOfRules) { const priceSetRulesCreate = Object.entries(cleanRules).map( ([k, v]) => ({ price_set_money_amount: priceSetMoneyAmount, rule_type: ruleTypeMap.get(k), price_set: priceSet, value: v, price_list_id: "test", }) ) await this.priceRuleService_.create( priceSetRulesCreate as unknown as PricingTypes.CreatePriceRuleDTO[], sharedContext ) } } } return priceSet }) ) return priceSets } async addRules( data: PricingTypes.AddRulesDTO, sharedContext?: Context ): Promise async addRules( data: PricingTypes.AddRulesDTO[], sharedContext?: Context ): Promise @InjectManager("baseRepository_") async addRules( data: PricingTypes.AddRulesDTO | PricingTypes.AddRulesDTO[], @MedusaContext() sharedContext: Context = {} ): Promise { const inputs = Array.isArray(data) ? data : [data] const priceSets = await this.addRules_(inputs, sharedContext) return (Array.isArray(data) ? priceSets : priceSets[0]) as unknown as | PricingTypes.PriceSetDTO[] | PricingTypes.PriceSetDTO } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") protected async addRules_( inputs: PricingTypes.AddRulesDTO[], @MedusaContext() sharedContext: Context = {} ): Promise { const priceSets = await this.priceSetService_.list( { id: inputs.map((d) => d.priceSetId) }, { relations: ["rule_types"] } ) const priceSetRuleTypeMap: Map> = new Map( priceSets.map((priceSet) => [ priceSet.id, new Map([...priceSet.rule_types].map((rt) => [rt.rule_attribute, rt])), ]) ) const priceSetMap = new Map(priceSets.map((p) => [p.id, p])) const invalidPriceSetInputs = inputs.filter( (d) => !priceSetMap.has(d.priceSetId) ) if (invalidPriceSetInputs.length) { throw new MedusaError( MedusaError.Types.INVALID_DATA, `PriceSets with ids: ${invalidPriceSetInputs .map((d) => d.priceSetId) .join(", ")} was not found` ) } const ruleTypes = await this.ruleTypeService_.list( { rule_attribute: inputs .map((d) => d.rules.map((r) => r.attribute)) .flat(), }, {}, sharedContext ) const ruleTypeMap: Map = new Map( ruleTypes.map((rt) => [rt.rule_attribute, rt]) ) const invalidRuleAttributeInputs = inputs .map((d) => d.rules.map((r) => r.attribute)) .flat() .filter((r) => !ruleTypeMap.has(r)) if (invalidRuleAttributeInputs.length) { throw new MedusaError( MedusaError.Types.INVALID_DATA, `Rule types don't exist for attributes: ${[ ...new Set(invalidRuleAttributeInputs), ].join(", ")}` ) } const priceSetRuleTypesCreate: PricingTypes.CreatePriceSetRuleTypeDTO[] = [] inputs.forEach((d) => { const priceSet = priceSetMap.get(d.priceSetId) for (const r of d.rules) { if (priceSetRuleTypeMap.get(d.priceSetId)!.has(r.attribute)) { continue } priceSetRuleTypesCreate.push({ rule_type: ruleTypeMap.get(r.attribute) as RuleTypeDTO, price_set: priceSet as unknown as PriceSetDTO, }) } }) await this.priceSetRuleTypeService_.create( priceSetRuleTypesCreate as unknown as PricingTypes.CreatePriceSetRuleTypeDTO[], sharedContext ) return this.baseRepository_.serialize( priceSets, { populate: true, } ) } async addPrices( data: AddPricesDTO, sharedContext?: Context ): Promise async addPrices( data: AddPricesDTO[], sharedContext?: Context ): Promise @InjectManager("baseRepository_") async addPrices( data: AddPricesDTO | AddPricesDTO[], @MedusaContext() sharedContext: Context = {} ): Promise { const input = Array.isArray(data) ? data : [data] await this.addPrices_(input, sharedContext) return (await this.list( { id: input.map((d) => d.priceSetId) }, { relations: ["money_amounts"] } )) as unknown as PricingTypes.PriceSetDTO[] | PricingTypes.PriceSetDTO } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") protected async addPrices_( input: AddPricesDTO[], @MedusaContext() sharedContext: Context = {} ) { const priceSets = await this.list( { id: input.map((d) => d.priceSetId) }, { relations: ["rule_types"] }, sharedContext ) const priceSetMap = new Map(priceSets.map((p) => [p.id, p])) const ruleTypeMap: Map> = new Map( priceSets.map((priceSet) => [ priceSet.id, new Map( priceSet.rule_types?.map((rt) => [rt.rule_attribute, rt]) ?? [] ), ]) ) input.forEach(({ priceSetId, prices }) => { const priceSet = priceSetMap.get(priceSetId) if (!priceSet) { throw new MedusaError( MedusaError.Types.INVALID_DATA, `Price set with id: ${priceSetId} not found` ) } const ruleAttributes = prices .map((d) => (d.rules ? Object.keys(d.rules) : [])) .flat() const invalidRuleAttributes = ruleAttributes.filter( (r) => !ruleTypeMap.get(priceSetId)!.has(r) ) if (invalidRuleAttributes.length > 0) { throw new MedusaError( MedusaError.Types.NOT_FOUND, `Rule types don't exist for: ${invalidRuleAttributes.join(", ")}` ) } }) for (const { priceSetId, prices } of input) { await Promise.all( prices.map(async (ma) => { const [moneyAmount] = await this.moneyAmountService_.create( [ma] as unknown as CreateMoneyAmountDTO[], sharedContext ) const numberOfRules = Object.entries(ma?.rules ?? {}).length const [priceSetMoneyAmount] = await this.priceSetMoneyAmountService_.create( [ { price_set: priceSetId, money_amount: moneyAmount, title: "test", number_rules: numberOfRules, }, ] as unknown as PricingTypes.CreatePriceSetMoneyAmountDTO[], sharedContext ) if (numberOfRules) { const priceSetRulesCreate = Object.entries(ma.rules!).map( ([k, v]) => ({ price_set_money_amount: priceSetMoneyAmount, rule_type: ruleTypeMap.get(priceSetId)!.get(k), price_set: priceSetId, value: v, price_list_id: "test", }) ) await this.priceRuleService_.create( priceSetRulesCreate as unknown as PricingTypes.CreatePriceRuleDTO[], sharedContext ) } return moneyAmount }) ) } return priceSets } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") async removeRules( data: PricingTypes.RemovePriceSetRulesDTO[], @MedusaContext() sharedContext: Context = {} ): Promise { const priceSets = await this.priceSetService_.list({ id: data.map((d) => d.id), }) const priceSetIds = priceSets.map((ps) => ps.id) const ruleTypes = await this.ruleTypeService_.list({ rule_attribute: data.map((d) => d.rules || []).flat(), }) const ruleTypeIds = ruleTypes.map((rt) => rt.id) const priceSetRuleTypes = await this.priceSetRuleTypeService_.list({ price_set_id: priceSetIds, rule_type_id: ruleTypeIds, }) const priceRules = await this.priceRuleService_.list( { price_set_id: priceSetIds, rule_type_id: ruleTypeIds, }, { select: ["price_set_money_amount"], } ) await this.priceSetRuleTypeService_.delete( priceSetRuleTypes.map((psrt) => psrt.id), sharedContext ) await this.priceSetMoneyAmountService_.delete( priceRules.map((pr) => pr.price_set_money_amount.id), sharedContext ) } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") async update( data: PricingTypes.UpdatePriceSetDTO[], @MedusaContext() sharedContext: Context = {} ) { const priceSets = await this.priceSetService_.update(data, sharedContext) return this.baseRepository_.serialize( priceSets, { populate: true, } ) } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") async delete( ids: string[], @MedusaContext() sharedContext: Context = {} ): Promise { await this.priceSetService_.delete(ids, sharedContext) } @InjectManager("baseRepository_") async retrieveMoneyAmount( id: string, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} ): Promise { const moneyAmount = await this.moneyAmountService_.retrieve( id, config, sharedContext ) return this.baseRepository_.serialize( moneyAmount, { populate: true, } ) } @InjectManager("baseRepository_") async listMoneyAmounts( filters: PricingTypes.FilterableMoneyAmountProps = {}, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} ): Promise { const moneyAmounts = await this.moneyAmountService_.list( filters, config, sharedContext ) return this.baseRepository_.serialize( moneyAmounts, { populate: true, } ) } @InjectManager("baseRepository_") async listAndCountMoneyAmounts( filters: PricingTypes.FilterableMoneyAmountProps = {}, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} ): Promise<[PricingTypes.MoneyAmountDTO[], number]> { const [moneyAmounts, count] = await this.moneyAmountService_.listAndCount( filters, config, sharedContext ) return [ await this.baseRepository_.serialize( moneyAmounts, { populate: true, } ), count, ] } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") async createMoneyAmounts( data: PricingTypes.CreateMoneyAmountDTO[], @MedusaContext() sharedContext: Context = {} ) { const moneyAmounts = await this.moneyAmountService_.create( data, sharedContext ) return this.baseRepository_.serialize( moneyAmounts, { populate: true, } ) } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") async updateMoneyAmounts( data: PricingTypes.UpdateMoneyAmountDTO[], @MedusaContext() sharedContext: Context = {} ) { const moneyAmounts = await this.moneyAmountService_.update( data, sharedContext ) return this.baseRepository_.serialize( moneyAmounts, { populate: true, } ) } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") async deleteMoneyAmounts( ids: string[], @MedusaContext() sharedContext: Context = {} ): Promise { await this.moneyAmountService_.delete(ids, sharedContext) } @InjectManager("baseRepository_") async retrieveCurrency( code: string, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} ): Promise { const currency = await this.currencyService_.retrieve( code, config, sharedContext ) return this.baseRepository_.serialize(currency, { populate: true, }) } @InjectManager("baseRepository_") async listCurrencies( filters: PricingTypes.FilterableCurrencyProps = {}, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} ): Promise { const currencies = await this.currencyService_.list( filters, config, sharedContext ) return this.baseRepository_.serialize( currencies, { populate: true, } ) } @InjectManager("baseRepository_") async listAndCountCurrencies( filters: PricingTypes.FilterableCurrencyProps = {}, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} ): Promise<[PricingTypes.CurrencyDTO[], number]> { const [currencies, count] = await this.currencyService_.listAndCount( filters, config, sharedContext ) return [ await this.baseRepository_.serialize( currencies, { populate: true, } ), count, ] } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") async createCurrencies( data: PricingTypes.CreateCurrencyDTO[], @MedusaContext() sharedContext: Context = {} ) { const currencies = await this.currencyService_.create(data, sharedContext) return this.baseRepository_.serialize( currencies, { populate: true, } ) } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") async updateCurrencies( data: PricingTypes.UpdateCurrencyDTO[], @MedusaContext() sharedContext: Context = {} ) { const currencies = await this.currencyService_.update(data, sharedContext) return this.baseRepository_.serialize( currencies, { populate: true, } ) } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") async deleteCurrencies( currencyCodes: string[], @MedusaContext() sharedContext: Context = {} ): Promise { await this.currencyService_.delete(currencyCodes, sharedContext) } @InjectManager("baseRepository_") async retrieveRuleType( id: string, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} ): Promise { const ruleType = await this.ruleTypeService_.retrieve( id, config, sharedContext ) return this.baseRepository_.serialize(ruleType, { populate: true, }) } @InjectManager("baseRepository_") async listRuleTypes( filters: PricingTypes.FilterableRuleTypeProps = {}, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} ): Promise { const ruleTypes = await this.ruleTypeService_.list( filters, config, sharedContext ) return this.baseRepository_.serialize( ruleTypes, { populate: true, } ) } @InjectManager("baseRepository_") async listAndCountRuleTypes( filters: PricingTypes.FilterableRuleTypeProps = {}, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} ): Promise<[PricingTypes.RuleTypeDTO[], number]> { const [ruleTypes, count] = await this.ruleTypeService_.listAndCount( filters, config, sharedContext ) return [ await this.baseRepository_.serialize( ruleTypes, { populate: true, } ), count, ] } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") async createRuleTypes( data: PricingTypes.CreateRuleTypeDTO[], @MedusaContext() sharedContext: Context = {} ): Promise { const ruleTypes = await this.ruleTypeService_.create(data, sharedContext) return this.baseRepository_.serialize( ruleTypes, { populate: true, } ) } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") async updateRuleTypes( data: PricingTypes.UpdateRuleTypeDTO[], @MedusaContext() sharedContext: Context = {} ): Promise { const ruleTypes = await this.ruleTypeService_.update(data, sharedContext) return this.baseRepository_.serialize( ruleTypes, { populate: true, } ) } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") async deleteRuleTypes( ruleTypeIds: string[], @MedusaContext() sharedContext: Context = {} ): Promise { await this.ruleTypeService_.delete(ruleTypeIds, sharedContext) } @InjectManager("baseRepository_") async retrievePriceSetMoneyAmountRules( id: string, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} ): Promise { const record = await this.priceSetMoneyAmountRulesService_.retrieve( id, config, sharedContext ) return this.baseRepository_.serialize( record, { populate: true, } ) } @InjectManager("baseRepository_") async listPriceSetMoneyAmountRules( filters: PricingTypes.FilterablePriceSetMoneyAmountRulesProps = {}, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} ): Promise { const records = await this.priceSetMoneyAmountRulesService_.list( filters, config, sharedContext ) return this.baseRepository_.serialize< PricingTypes.PriceSetMoneyAmountRulesDTO[] >(records, { populate: true, }) } @InjectManager("baseRepository_") async listAndCountPriceSetMoneyAmountRules( filters: PricingTypes.FilterablePriceSetMoneyAmountRulesProps = {}, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} ): Promise<[PricingTypes.PriceSetMoneyAmountRulesDTO[], number]> { const [records, count] = await this.priceSetMoneyAmountRulesService_.listAndCount( filters, config, sharedContext ) return [ await this.baseRepository_.serialize< PricingTypes.PriceSetMoneyAmountRulesDTO[] >(records, { populate: true, }), count, ] } @InjectManager("baseRepository_") async listPriceSetMoneyAmounts( filters: PricingTypes.FilterablePriceSetMoneyAmountProps = {}, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} ): Promise { const records = await this.priceSetMoneyAmountService_.list( filters, config, sharedContext ) return this.baseRepository_.serialize< PricingTypes.PriceSetMoneyAmountRulesDTO[] >(records, { populate: true, }) } @InjectManager("baseRepository_") async listAndCountPriceSetMoneyAmounts( filters: PricingTypes.FilterablePriceSetMoneyAmountProps = {}, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} ): Promise<[PricingTypes.PriceSetMoneyAmountDTO[], number]> { const [records, count] = await this.priceSetMoneyAmountService_.listAndCount( filters, config, sharedContext ) return [ await this.baseRepository_.serialize< PricingTypes.PriceSetMoneyAmountRulesDTO[] >(records, { populate: true, }), count, ] } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") async createPriceSetMoneyAmountRules( data: PricingTypes.CreatePriceSetMoneyAmountRulesDTO[], @MedusaContext() sharedContext: Context = {} ): Promise { const records = await this.priceSetMoneyAmountRulesService_.create( data, sharedContext ) return this.baseRepository_.serialize< PricingTypes.PriceSetMoneyAmountRulesDTO[] >(records, { populate: true, }) } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") async updatePriceSetMoneyAmountRules( data: PricingTypes.UpdatePriceSetMoneyAmountRulesDTO[], @MedusaContext() sharedContext: Context = {} ): Promise { const records = await this.priceSetMoneyAmountRulesService_.update( data, sharedContext ) return this.baseRepository_.serialize< PricingTypes.PriceSetMoneyAmountRulesDTO[] >(records, { populate: true, }) } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") async deletePriceSetMoneyAmountRules( ids: string[], @MedusaContext() sharedContext: Context = {} ): Promise { await this.priceSetMoneyAmountRulesService_.delete(ids, sharedContext) } @InjectManager("baseRepository_") async retrievePriceRule( id: string, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} ): Promise { const priceRule = await this.priceRuleService_.retrieve( id, config, sharedContext ) return this.baseRepository_.serialize( priceRule, { populate: true, } ) } @InjectManager("baseRepository_") async listPriceRules( filters: PricingTypes.FilterablePriceRuleProps = {}, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} ): Promise { const priceRules = await this.priceRuleService_.list( filters, config, sharedContext ) return this.baseRepository_.serialize( priceRules, { populate: true, } ) } @InjectManager("baseRepository_") async listAndCountPriceRules( filters: PricingTypes.FilterablePriceRuleProps = {}, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} ): Promise<[PricingTypes.PriceRuleDTO[], number]> { const [priceRules, count] = await this.priceRuleService_.listAndCount( filters, config, sharedContext ) return [ await this.baseRepository_.serialize( priceRules, { populate: true, } ), count, ] } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") async createPriceRules( data: PricingTypes.CreatePriceRuleDTO[], @MedusaContext() sharedContext: Context = {} ): Promise { const priceRules = await this.priceRuleService_.create(data, sharedContext) return this.baseRepository_.serialize( priceRules, { populate: true, } ) } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") async updatePriceRules( data: PricingTypes.UpdatePriceRuleDTO[], @MedusaContext() sharedContext: Context = {} ): Promise { const priceRules = await this.priceRuleService_.update(data, sharedContext) return this.baseRepository_.serialize( priceRules, { populate: true, } ) } @InjectTransactionManager(shouldForceTransaction, "baseRepository_") async deletePriceRules( priceRuleIds: string[], @MedusaContext() sharedContext: Context = {} ): Promise { await this.priceRuleService_.delete(priceRuleIds, sharedContext) } }