feat(core-flows,medusa,utils): promotion and campaign create/update endpoint (#6130)
what: - adds create endpoint for promotions including workflows and endpoint (RESOLVES CORE-1678) - adds update endpoint for promotions including workflows and endpoint (RESOLVES CORE-1679) - adds create endpoint for campaigns including workflows and endpoint (RESOLVES CORE-1684) - adds update endpoint for campaigns including workflows and endpoint (RESOLVES CORE-1685)
This commit is contained in:
@@ -441,6 +441,7 @@ export default class PromotionModuleService<
|
||||
"rules",
|
||||
"rules.values",
|
||||
"campaign",
|
||||
"campaign.budget",
|
||||
],
|
||||
},
|
||||
sharedContext
|
||||
@@ -558,7 +559,7 @@ export default class PromotionModuleService<
|
||||
}
|
||||
}
|
||||
|
||||
await this.createPromotionRulesAndValues(
|
||||
await this.createPromotionRulesAndValues_(
|
||||
promotionCodeRulesDataMap.get(promotion.code) || [],
|
||||
"promotions",
|
||||
promotion,
|
||||
@@ -577,7 +578,7 @@ export default class PromotionModuleService<
|
||||
}
|
||||
|
||||
for (const applicationMethod of createdApplicationMethods) {
|
||||
await this.createPromotionRulesAndValues(
|
||||
await this.createPromotionRulesAndValues_(
|
||||
applicationMethodRuleMap.get(applicationMethod.promotion.id) || [],
|
||||
"application_methods",
|
||||
applicationMethod,
|
||||
@@ -614,9 +615,11 @@ export default class PromotionModuleService<
|
||||
relations: [
|
||||
"application_method",
|
||||
"application_method.target_rules",
|
||||
"application_method.target_rules.values",
|
||||
"rules",
|
||||
"rules.values",
|
||||
"campaign",
|
||||
"campaign.budget",
|
||||
],
|
||||
},
|
||||
sharedContext
|
||||
@@ -686,7 +689,10 @@ export default class PromotionModuleService<
|
||||
existingApplicationMethod.max_quantity,
|
||||
})
|
||||
|
||||
applicationMethodsData.push(applicationMethodData)
|
||||
applicationMethodsData.push({
|
||||
...applicationMethodData,
|
||||
id: existingApplicationMethod.id,
|
||||
})
|
||||
}
|
||||
|
||||
const updatedPromotions = this.promotionService_.update(
|
||||
@@ -705,7 +711,6 @@ export default class PromotionModuleService<
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
async addPromotionRules(
|
||||
promotionId: string,
|
||||
rulesData: PromotionTypes.CreatePromotionRuleDTO[],
|
||||
@@ -713,20 +718,21 @@ export default class PromotionModuleService<
|
||||
): Promise<PromotionTypes.PromotionDTO> {
|
||||
const promotion = await this.promotionService_.retrieve(promotionId)
|
||||
|
||||
await this.createPromotionRulesAndValues(
|
||||
await this.createPromotionRulesAndValues_(
|
||||
rulesData,
|
||||
"promotions",
|
||||
promotion,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return this.retrieve(promotionId, {
|
||||
relations: ["rules", "rules.values"],
|
||||
})
|
||||
return this.retrieve(
|
||||
promotionId,
|
||||
{ relations: ["rules", "rules.values"] },
|
||||
sharedContext
|
||||
)
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
async addPromotionTargetRules(
|
||||
promotionId: string,
|
||||
rulesData: PromotionTypes.CreatePromotionRuleDTO[],
|
||||
@@ -745,29 +751,34 @@ export default class PromotionModuleService<
|
||||
)
|
||||
}
|
||||
|
||||
await this.createPromotionRulesAndValues(
|
||||
await this.createPromotionRulesAndValues_(
|
||||
rulesData,
|
||||
"application_methods",
|
||||
applicationMethod,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return this.retrieve(promotionId, {
|
||||
relations: [
|
||||
"rules",
|
||||
"rules.values",
|
||||
"application_method",
|
||||
"application_method.target_rules",
|
||||
"application_method.target_rules.values",
|
||||
],
|
||||
})
|
||||
return this.retrieve(
|
||||
promotionId,
|
||||
{
|
||||
relations: [
|
||||
"rules",
|
||||
"rules.values",
|
||||
"application_method",
|
||||
"application_method.target_rules",
|
||||
"application_method.target_rules.values",
|
||||
],
|
||||
},
|
||||
sharedContext
|
||||
)
|
||||
}
|
||||
|
||||
protected async createPromotionRulesAndValues(
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
protected async createPromotionRulesAndValues_(
|
||||
rulesData: PromotionTypes.CreatePromotionRuleDTO[],
|
||||
relationName: "promotions" | "application_methods",
|
||||
relation: Promotion | ApplicationMethod,
|
||||
sharedContext: Context
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
) {
|
||||
validatePromotionRuleAttributes(rulesData)
|
||||
|
||||
@@ -789,7 +800,10 @@ export default class PromotionModuleService<
|
||||
promotion_rule: createdPromotionRule,
|
||||
}))
|
||||
|
||||
await this.promotionRuleValueService_.create(promotionRuleValuesData)
|
||||
await this.promotionRuleValueService_.create(
|
||||
promotionRuleValuesData,
|
||||
sharedContext
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -980,7 +994,7 @@ export default class PromotionModuleService<
|
||||
const campaigns = await this.listCampaigns(
|
||||
{ id: createdCampaigns.map((p) => p!.id) },
|
||||
{
|
||||
relations: ["budget"],
|
||||
relations: ["budget", "promotions"],
|
||||
},
|
||||
sharedContext
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user