feat(pricing) Add Price Set Rule Type (#4977)
* initial * initial service * update pricing module service * add integration test for rule-type * update pricing-module integration tests * update pricing service interface * feat(pricing): PriceSets as entry point to pricing module * chore: add price set money amount * chore: add price set money amount * chore: change name of test * chore: added changeset * chore: use filterable props from money amount in price sets * chore: update migrations * test update integration test * fix weird behavior * Update packages/pricing/integration-tests/__fixtures__/rule-type/index.ts Co-authored-by: Riqwan Thamir <rmthamir@gmail.com> * Apply suggestions from code review Co-authored-by: Riqwan Thamir <rmthamir@gmail.com> * move rule-type to common * chore: reset migration * chore: remove incorrect conflicts * chore: address review * chore: remove ghost price list * Apply suggestions from code review Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> * update id prefix * use persist not persistAndflush * rename key_value to rule_attribute * more renaming --------- Co-authored-by: Riqwan Thamir <rmthamir@gmail.com> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
@@ -8,34 +8,42 @@ import {
|
||||
PricingFilters,
|
||||
PricingTypes,
|
||||
} from "@medusajs/types"
|
||||
import { Currency, MoneyAmount, PriceSet } from "@models"
|
||||
import { CurrencyService, MoneyAmountService, PriceSetService } from "@services"
|
||||
import { Currency, MoneyAmount, PriceSet, RuleType } from "@models"
|
||||
import {
|
||||
CurrencyService,
|
||||
MoneyAmountService,
|
||||
PriceSetService,
|
||||
RuleTypeService,
|
||||
} from "@services"
|
||||
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
shouldForceTransaction,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import { shouldForceTransaction } from "@medusajs/utils"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
currencyService: CurrencyService<any>
|
||||
moneyAmountService: MoneyAmountService<any>
|
||||
ruleTypeService: RuleTypeService<any>
|
||||
priceSetService: PriceSetService<any>
|
||||
}
|
||||
|
||||
export default class PricingModuleService<
|
||||
TPriceSet extends PriceSet = PriceSet,
|
||||
TMoneyAmount extends MoneyAmount = MoneyAmount,
|
||||
TCurrency extends Currency = Currency
|
||||
TCurrency extends Currency = Currency,
|
||||
TRuleType extends RuleType = RuleType
|
||||
> implements PricingTypes.IPricingModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected readonly currencyService_: CurrencyService<TCurrency>
|
||||
protected readonly moneyAmountService_: MoneyAmountService<TMoneyAmount>
|
||||
protected readonly ruleTypeService_: RuleTypeService<TRuleType>
|
||||
protected readonly priceSetService_: PriceSetService<TPriceSet>
|
||||
|
||||
constructor(
|
||||
@@ -43,6 +51,7 @@ export default class PricingModuleService<
|
||||
baseRepository,
|
||||
moneyAmountService,
|
||||
currencyService,
|
||||
ruleTypeService,
|
||||
priceSetService,
|
||||
}: InjectedDependencies,
|
||||
protected readonly moduleDeclaration: InternalModuleDeclaration
|
||||
@@ -50,6 +59,7 @@ export default class PricingModuleService<
|
||||
this.baseRepository_ = baseRepository
|
||||
this.currencyService_ = currencyService
|
||||
this.moneyAmountService_ = moneyAmountService
|
||||
this.ruleTypeService_ = ruleTypeService
|
||||
this.priceSetService_ = priceSetService
|
||||
}
|
||||
|
||||
@@ -412,4 +422,102 @@ export default class PricingModuleService<
|
||||
): Promise<void> {
|
||||
await this.currencyService_.delete(currencyCodes, sharedContext)
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async retrieveRuleType(
|
||||
id: string,
|
||||
config: FindConfig<PricingTypes.RuleTypeDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<PricingTypes.RuleTypeDTO> {
|
||||
const ruleType = await this.ruleTypeService_.retrieve(
|
||||
id,
|
||||
config,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return this.baseRepository_.serialize<PricingTypes.RuleTypeDTO>(ruleType, {
|
||||
populate: true,
|
||||
})
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async listRuleTypes(
|
||||
filters: PricingTypes.FilterableRuleTypeProps = {},
|
||||
config: FindConfig<PricingTypes.RuleTypeDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<PricingTypes.RuleTypeDTO[]> {
|
||||
const ruleTypes = await this.ruleTypeService_.list(
|
||||
filters,
|
||||
config,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return this.baseRepository_.serialize<PricingTypes.RuleTypeDTO[]>(
|
||||
ruleTypes,
|
||||
{
|
||||
populate: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async listAndCountRuleTypes(
|
||||
filters: PricingTypes.FilterableRuleTypeProps = {},
|
||||
config: FindConfig<PricingTypes.RuleTypeDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[PricingTypes.RuleTypeDTO[], number]> {
|
||||
const [ruleTypes, count] = await this.ruleTypeService_.listAndCount(
|
||||
filters,
|
||||
config,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return [
|
||||
await this.baseRepository_.serialize<PricingTypes.RuleTypeDTO[]>(
|
||||
ruleTypes,
|
||||
{
|
||||
populate: true,
|
||||
}
|
||||
),
|
||||
count,
|
||||
]
|
||||
}
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, "baseRepository_")
|
||||
async createRuleTypes(
|
||||
data: PricingTypes.CreateRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<PricingTypes.RuleTypeDTO[]> {
|
||||
const ruleTypes = await this.ruleTypeService_.create(data, sharedContext)
|
||||
|
||||
return this.baseRepository_.serialize<PricingTypes.RuleTypeDTO[]>(
|
||||
ruleTypes,
|
||||
{
|
||||
populate: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, "baseRepository_")
|
||||
async updateRuleTypes(
|
||||
data: PricingTypes.UpdateRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<PricingTypes.RuleTypeDTO[]> {
|
||||
const ruleTypes = await this.ruleTypeService_.update(data, sharedContext)
|
||||
|
||||
return this.baseRepository_.serialize<PricingTypes.RuleTypeDTO[]>(
|
||||
ruleTypes,
|
||||
{
|
||||
populate: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, "baseRepository_")
|
||||
async deleteRuleTypes(
|
||||
ruleTypes: string[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
await this.ruleTypeService_.delete(ruleTypes, sharedContext)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user