feat(utils): autogenerates create and update methods when dto is provided (#6751)
what:
when you provide an optional create_dto or update_dto to the model factory types, the abstract service will generate a simple service method for the public services of the modules.
```
MoneyAmount: {
dto: PricingTypes.MoneyAmountDTO
create_dto: PricingTypes.CreateMoneyAmountDTO
}
```
In the above example, only a create method will be generated, but the update will be skipped.
This commit is contained in:
@@ -94,13 +94,21 @@ export default class PricingModuleService<
|
||||
InjectedDependencies,
|
||||
PricingTypes.PriceSetDTO,
|
||||
{
|
||||
MoneyAmount: { dto: PricingTypes.MoneyAmountDTO }
|
||||
MoneyAmount: {
|
||||
dto: PricingTypes.MoneyAmountDTO
|
||||
create: PricingTypes.CreateMoneyAmountDTO
|
||||
update: PricingTypes.UpdateMoneyAmountDTO
|
||||
}
|
||||
PriceSetMoneyAmount: { dto: PricingTypes.PriceSetMoneyAmountDTO }
|
||||
PriceSetMoneyAmountRules: {
|
||||
dto: PricingTypes.PriceSetMoneyAmountRulesDTO
|
||||
}
|
||||
PriceRule: { dto: PricingTypes.PriceRuleDTO }
|
||||
RuleType: { dto: PricingTypes.RuleTypeDTO }
|
||||
RuleType: {
|
||||
dto: PricingTypes.RuleTypeDTO
|
||||
create: PricingTypes.CreateRuleTypeDTO
|
||||
update: PricingTypes.UpdateRuleTypeDTO
|
||||
}
|
||||
PriceList: { dto: PricingTypes.PriceListDTO }
|
||||
PriceListRule: { dto: PricingTypes.PriceListRuleDTO }
|
||||
}
|
||||
@@ -705,72 +713,6 @@ export default class PricingModuleService<
|
||||
)
|
||||
}
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
async createMoneyAmounts(
|
||||
data: PricingTypes.CreateMoneyAmountDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
) {
|
||||
const moneyAmounts = await this.moneyAmountService_.create(
|
||||
data,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return await this.baseRepository_.serialize<PricingTypes.MoneyAmountDTO[]>(
|
||||
moneyAmounts,
|
||||
{
|
||||
populate: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
async updateMoneyAmounts(
|
||||
data: PricingTypes.UpdateMoneyAmountDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
) {
|
||||
const moneyAmounts = await this.moneyAmountService_.update(
|
||||
data,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return await this.baseRepository_.serialize<PricingTypes.MoneyAmountDTO[]>(
|
||||
moneyAmounts,
|
||||
{
|
||||
populate: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
async createRuleTypes(
|
||||
data: PricingTypes.CreateRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<PricingTypes.RuleTypeDTO[]> {
|
||||
const ruleTypes = await this.ruleTypeService_.create(data, sharedContext)
|
||||
|
||||
return await this.baseRepository_.serialize<PricingTypes.RuleTypeDTO[]>(
|
||||
ruleTypes,
|
||||
{
|
||||
populate: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
async updateRuleTypes(
|
||||
data: PricingTypes.UpdateRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<PricingTypes.RuleTypeDTO[]> {
|
||||
const ruleTypes = await this.ruleTypeService_.update(data, sharedContext)
|
||||
|
||||
return await this.baseRepository_.serialize<PricingTypes.RuleTypeDTO[]>(
|
||||
ruleTypes,
|
||||
{
|
||||
populate: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
async createPriceSetMoneyAmountRules(
|
||||
data: PricingTypes.CreatePriceSetMoneyAmountRulesDTO[],
|
||||
|
||||
Reference in New Issue
Block a user