chore(): Upgrade mikro orm (#13390)
* chore(): Upgrade mikro orm * handle 'null' value for big number props * 6.5.2 * remove only * fix pricing module rule value * switch select in strategy for balances * revert to select in strategy for order module * fix defining DML ManyToOne * fix define relationship * test fix * more fixes * change order strategy to balanced * change order strategy to balanced * prevent unnecessary manager fork * revert generated www changes * remove unnecessary changes * Create real-cobras-deny.md * address feedback --------- Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
fc4d5f0ac9
commit
a095245d71
@@ -12,7 +12,7 @@ export async function createCampaigns(
|
||||
campaignsData?: CreateCampaignDTO[]
|
||||
): Promise<Campaign[]> {
|
||||
if (!campaignsData) {
|
||||
const cp = JSON.parse(JSON.stringify(defaultCampaignsData))
|
||||
const cp = structuredClone(defaultCampaignsData)
|
||||
|
||||
const starts_at = new Date(TODAY)
|
||||
starts_at.setDate(starts_at.getDate() - 1)
|
||||
|
||||
@@ -39,10 +39,10 @@
|
||||
"devDependencies": {
|
||||
"@medusajs/framework": "2.10.1",
|
||||
"@medusajs/test-utils": "2.10.1",
|
||||
"@mikro-orm/cli": "6.4.3",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"@mikro-orm/cli": "6.5.2",
|
||||
"@mikro-orm/core": "6.5.2",
|
||||
"@mikro-orm/migrations": "6.5.2",
|
||||
"@mikro-orm/postgresql": "6.5.2",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"jest": "^29.7.0",
|
||||
@@ -52,9 +52,9 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@medusajs/framework": "2.10.1",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"@mikro-orm/core": "6.5.2",
|
||||
"@mikro-orm/migrations": "6.5.2",
|
||||
"@mikro-orm/postgresql": "6.5.2",
|
||||
"awilix": "^8.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
CampaignBudgetType,
|
||||
ComputedActions,
|
||||
deduplicate,
|
||||
EmitEvents,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
isDefined,
|
||||
@@ -139,11 +140,26 @@ export default class PromotionModuleService
|
||||
}
|
||||
|
||||
@InjectManager()
|
||||
listActivePromotions(
|
||||
async listActivePromotions(
|
||||
filters?: FilterablePromotionProps,
|
||||
config?: FindConfig<PromotionDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<PromotionDTO[]> {
|
||||
const activePromotions = await this.listActivePromotions_(
|
||||
filters,
|
||||
config,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return this.baseRepository_.serialize<PromotionDTO[]>(activePromotions)
|
||||
}
|
||||
|
||||
@InjectManager()
|
||||
protected async listActivePromotions_(
|
||||
filters?: FilterablePromotionProps,
|
||||
config?: FindConfig<PromotionDTO>,
|
||||
@MedusaContext() sharedContext?: Context
|
||||
): Promise<InferEntityType<typeof Promotion>[]> {
|
||||
// Ensure we share the same now date across all filters
|
||||
const now = new Date()
|
||||
const activeFilters = {
|
||||
@@ -170,7 +186,11 @@ export default class PromotionModuleService
|
||||
],
|
||||
}
|
||||
|
||||
return this.listPromotions(activeFilters, config, sharedContext)
|
||||
return await this.promotionService_.list(
|
||||
activeFilters,
|
||||
config,
|
||||
sharedContext
|
||||
)
|
||||
}
|
||||
|
||||
@InjectTransactionManager()
|
||||
@@ -185,7 +205,7 @@ export default class PromotionModuleService
|
||||
const campaignBudgetMap = new Map<string, UpdateCampaignBudgetDTO>()
|
||||
const promotionCodeUsageMap = new Map<string, boolean>()
|
||||
|
||||
const existingPromotions = await this.listActivePromotions(
|
||||
const existingPromotions = await this.listActivePromotions_(
|
||||
{ code: promotionCodes },
|
||||
{ relations: ["campaign", "campaign.budget"] },
|
||||
sharedContext
|
||||
@@ -200,9 +220,10 @@ export default class PromotionModuleService
|
||||
}
|
||||
}
|
||||
|
||||
const existingPromotionsMap = new Map<string, PromotionTypes.PromotionDTO>(
|
||||
existingPromotions.map((promotion) => [promotion.code!, promotion])
|
||||
)
|
||||
const existingPromotionsMap = new Map<
|
||||
string,
|
||||
InferEntityType<typeof Promotion>
|
||||
>(existingPromotions.map((promotion) => [promotion.code!, promotion]))
|
||||
|
||||
for (let computedAction of computedActions) {
|
||||
const promotion = existingPromotionsMap.get(computedAction.code)
|
||||
@@ -293,7 +314,7 @@ export default class PromotionModuleService
|
||||
const promotionCodeUsageMap = new Map<string, boolean>()
|
||||
const campaignBudgetMap = new Map<string, UpdateCampaignBudgetDTO>()
|
||||
|
||||
const existingPromotions = await this.listActivePromotions(
|
||||
const existingPromotions = await this.listActivePromotions_(
|
||||
{
|
||||
code: computedActions
|
||||
.map((computedAction) => computedAction.code)
|
||||
@@ -312,9 +333,10 @@ export default class PromotionModuleService
|
||||
}
|
||||
}
|
||||
|
||||
const existingPromotionsMap = new Map<string, PromotionTypes.PromotionDTO>(
|
||||
existingPromotions.map((promotion) => [promotion.code!, promotion])
|
||||
)
|
||||
const existingPromotionsMap = new Map<
|
||||
string,
|
||||
InferEntityType<typeof Promotion>
|
||||
>(existingPromotions.map((promotion) => [promotion.code!, promotion]))
|
||||
|
||||
for (let computedAction of computedActions) {
|
||||
const promotion = existingPromotionsMap.get(computedAction.code)
|
||||
@@ -433,25 +455,18 @@ export default class PromotionModuleService
|
||||
|
||||
const methodIdPromoValueMap = new Map<string, number>()
|
||||
|
||||
const automaticPromotions = preventAutoPromotions
|
||||
? []
|
||||
: await this.listActivePromotions(
|
||||
{ is_automatic: true },
|
||||
{ select: ["code"] },
|
||||
sharedContext
|
||||
)
|
||||
|
||||
const automaticPromotionCodes = automaticPromotions.map((p) => p.code!)
|
||||
const promotionCodesToApply = [
|
||||
...promotionCodes,
|
||||
...automaticPromotionCodes,
|
||||
...appliedCodes,
|
||||
]
|
||||
const promotionCodesToApply = [...promotionCodes, ...appliedCodes]
|
||||
|
||||
const uniquePromotionCodes = Array.from(new Set(promotionCodesToApply))
|
||||
|
||||
const queryFilter = preventAutoPromotions
|
||||
? { code: uniquePromotionCodes }
|
||||
: {
|
||||
$or: [{ code: uniquePromotionCodes }, { is_automatic: true }],
|
||||
}
|
||||
|
||||
const promotions = await this.listActivePromotions(
|
||||
{ code: uniquePromotionCodes },
|
||||
queryFilter,
|
||||
{
|
||||
take: null,
|
||||
order: { application_method: { value: "DESC" } },
|
||||
@@ -474,6 +489,9 @@ export default class PromotionModuleService
|
||||
promotions.map((promotion) => [promotion.code!, promotion])
|
||||
)
|
||||
|
||||
const automaticPromotions = promotions.filter((p) => p.is_automatic)
|
||||
const automaticPromotionCodes = automaticPromotions.map((p) => p.code!)
|
||||
|
||||
for (const [code, adjustments] of codeAdjustmentMap.entries()) {
|
||||
for (const adjustment of adjustments.items) {
|
||||
computedActions.push({
|
||||
@@ -628,7 +646,9 @@ export default class PromotionModuleService
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return Array.isArray(data) ? promotions : promotions[0]
|
||||
return await this.baseRepository_.serialize<
|
||||
PromotionTypes.PromotionDTO | PromotionTypes.PromotionDTO[]
|
||||
>(Array.isArray(data) ? promotions : promotions[0])
|
||||
}
|
||||
|
||||
@InjectTransactionManager()
|
||||
@@ -887,6 +907,7 @@ export default class PromotionModuleService
|
||||
): Promise<PromotionTypes.PromotionDTO[]>
|
||||
|
||||
@InjectManager()
|
||||
@EmitEvents()
|
||||
// @ts-expect-error
|
||||
async updatePromotions(
|
||||
data:
|
||||
@@ -1040,7 +1061,7 @@ export default class PromotionModuleService
|
||||
) {
|
||||
const promotionRuleIds = data.map((d) => d.id)
|
||||
|
||||
const promotionRules = await this.listPromotionRules(
|
||||
const promotionRules = await this.promotionRuleService_.list(
|
||||
{ id: promotionRuleIds },
|
||||
{ relations: ["values"] },
|
||||
sharedContext
|
||||
@@ -1097,6 +1118,7 @@ export default class PromotionModuleService
|
||||
}
|
||||
|
||||
@InjectManager()
|
||||
@EmitEvents()
|
||||
async addPromotionRules(
|
||||
promotionId: string,
|
||||
rulesData: PromotionTypes.CreatePromotionRuleDTO[],
|
||||
@@ -1218,6 +1240,8 @@ export default class PromotionModuleService
|
||||
|
||||
validatePromotionRuleAttributes(rulesData)
|
||||
|
||||
const promotionRuleValuesDataToCreate: CreatePromotionRuleValueDTO[] = []
|
||||
|
||||
for (const ruleData of rulesData) {
|
||||
const { values, ...rest } = ruleData
|
||||
const promotionRuleData: CreatePromotionRuleDTO = {
|
||||
@@ -1238,12 +1262,14 @@ export default class PromotionModuleService
|
||||
promotion_rule: createdPromotionRule,
|
||||
}))
|
||||
|
||||
await this.promotionRuleValueService_.create(
|
||||
promotionRuleValuesData,
|
||||
sharedContext
|
||||
)
|
||||
promotionRuleValuesDataToCreate.push(...promotionRuleValuesData)
|
||||
}
|
||||
|
||||
await this.promotionRuleValueService_.create(
|
||||
promotionRuleValuesDataToCreate,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return createdPromotionRules
|
||||
}
|
||||
|
||||
@@ -1489,15 +1515,16 @@ export default class PromotionModuleService
|
||||
const updateBudgetData: UpdateCampaignBudgetDTO[] = []
|
||||
const createBudgetData: CreateCampaignBudgetDTO[] = []
|
||||
|
||||
const existingCampaigns = await this.listCampaigns(
|
||||
const existingCampaigns = await this.campaignService_.list(
|
||||
{ id: campaignIds },
|
||||
{ relations: ["budget"] },
|
||||
sharedContext
|
||||
)
|
||||
|
||||
const existingCampaignsMap = new Map<string, PromotionTypes.CampaignDTO>(
|
||||
existingCampaigns.map((campaign) => [campaign.id, campaign])
|
||||
)
|
||||
const existingCampaignsMap = new Map<
|
||||
string,
|
||||
InferEntityType<typeof Campaign>
|
||||
>(existingCampaigns.map((campaign) => [campaign.id, campaign]))
|
||||
|
||||
for (const updateCampaignData of data) {
|
||||
const { budget: budgetData, ...campaignData } = updateCampaignData
|
||||
@@ -1554,7 +1581,7 @@ export default class PromotionModuleService
|
||||
@InjectManager()
|
||||
async addPromotionsToCampaign(
|
||||
data: PromotionTypes.AddPromotionsToCampaignDTO,
|
||||
sharedContext?: Context
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<{ ids: string[] }> {
|
||||
const ids = await this.addPromotionsToCampaign_(data, sharedContext)
|
||||
|
||||
@@ -1621,7 +1648,7 @@ export default class PromotionModuleService
|
||||
@InjectManager()
|
||||
async removePromotionsFromCampaign(
|
||||
data: PromotionTypes.AddPromotionsToCampaignDTO,
|
||||
sharedContext?: Context
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<{ ids: string[] }> {
|
||||
const ids = await this.removePromotionsFromCampaign_(data, sharedContext)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user