From 91499081f4584d53690db07f6a9c9f104cd5674e Mon Sep 17 00:00:00 2001 From: Adrien de Peretti Date: Thu, 27 Nov 2025 12:45:17 +0100 Subject: [PATCH] chore(): Promotion auto managed joiner config (#14115) * chore(): Promotion auto managed joiner config * Create light-trainers-tie.md * chore(): align tests expectactions --- .changeset/light-trainers-tie.md | 5 + .../promotion-module/promotion.spec.ts | 40 ++++++++ .../modules/promotion/src/joiner-config.ts | 8 -- .../modules/promotion/src/schema/index.ts | 97 ------------------- .../src/services/promotion-module.ts | 6 -- 5 files changed, 45 insertions(+), 111 deletions(-) create mode 100644 .changeset/light-trainers-tie.md delete mode 100644 packages/modules/promotion/src/joiner-config.ts delete mode 100644 packages/modules/promotion/src/schema/index.ts diff --git a/.changeset/light-trainers-tie.md b/.changeset/light-trainers-tie.md new file mode 100644 index 0000000000..2610a6da09 --- /dev/null +++ b/.changeset/light-trainers-tie.md @@ -0,0 +1,5 @@ +--- +"@medusajs/promotion": patch +--- + +chore(): Promotion auto managed joiner config diff --git a/packages/modules/promotion/integration-tests/__tests__/services/promotion-module/promotion.spec.ts b/packages/modules/promotion/integration-tests/__tests__/services/promotion-module/promotion.spec.ts index 6c51d406dc..85525e3f30 100644 --- a/packages/modules/promotion/integration-tests/__tests__/services/promotion-module/promotion.spec.ts +++ b/packages/modules/promotion/integration-tests/__tests__/services/promotion-module/promotion.spec.ts @@ -35,8 +35,12 @@ moduleIntegrationTestRunner({ expect(Object.keys(linkable)).toEqual([ "promotion", + "applicationMethod", "campaign", + "campaignBudget", + "campaignBudgetUsage", "promotionRule", + "promotionRuleValue", ]) Object.keys(linkable).forEach((key) => { @@ -53,6 +57,15 @@ moduleIntegrationTestRunner({ field: "promotion", }, }, + applicationMethod: { + id: { + linkable: "application_method_id", + entity: "ApplicationMethod", + primaryKey: "id", + serviceName: "promotion", + field: "applicationMethod", + }, + }, campaign: { id: { linkable: "campaign_id", @@ -62,6 +75,24 @@ moduleIntegrationTestRunner({ field: "campaign", }, }, + campaignBudget: { + id: { + linkable: "campaign_budget_id", + entity: "CampaignBudget", + primaryKey: "id", + serviceName: "promotion", + field: "campaignBudget", + }, + }, + campaignBudgetUsage: { + id: { + linkable: "campaign_budget_usage_id", + entity: "CampaignBudgetUsage", + primaryKey: "id", + serviceName: "promotion", + field: "campaignBudgetUsage", + }, + }, promotionRule: { id: { linkable: "promotion_rule_id", @@ -71,6 +102,15 @@ moduleIntegrationTestRunner({ field: "promotionRule", }, }, + promotionRuleValue: { + id: { + linkable: "promotion_rule_value_id", + entity: "PromotionRuleValue", + primaryKey: "id", + serviceName: "promotion", + field: "promotionRuleValue", + }, + }, }) }) diff --git a/packages/modules/promotion/src/joiner-config.ts b/packages/modules/promotion/src/joiner-config.ts deleted file mode 100644 index af471f3cc3..0000000000 --- a/packages/modules/promotion/src/joiner-config.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { defineJoinerConfig, Modules } from "@medusajs/framework/utils" -import { Campaign, Promotion, PromotionRule } from "@models" -import { default as schema } from "./schema" - -export const joinerConfig = defineJoinerConfig(Modules.PROMOTION, { - schema, - models: [Promotion, Campaign, PromotionRule], -}) diff --git a/packages/modules/promotion/src/schema/index.ts b/packages/modules/promotion/src/schema/index.ts deleted file mode 100644 index 3d26104783..0000000000 --- a/packages/modules/promotion/src/schema/index.ts +++ /dev/null @@ -1,97 +0,0 @@ -export default ` -enum PromotionTypeValues { - standard - buyget -} - -enum PromotionRuleOperatorValues { - gt - lt - eq - ne - in - lte - gte -} - -enum CampaignBudgetTypeValues { - spend - usage -} - -enum ApplicationMethodTypeValues { - fixed - percentage -} - -enum ApplicationMethodTargetTypeValues { - order - shipping_methods - items -} - -enum ApplicationMethodAllocationValues { - each - across - once -} - -type Promotion { - id: ID! - code: String - type: PromotionTypeValues - is_automatic: Boolean - application_method: ApplicationMethod - rules: [PromotionRule] - campaign_id: String - campaign: Campaign -} - -type PromotionRule { - id: ID! - description: String - attribute: String - operator: PromotionRuleOperatorValues - values: [PromotionRuleValue!]! -} - -type PromotionRuleValue { - id: ID! - value: String -} - -type Campaign { - id: ID! - name: String - description: String - campaign_identifier: String - starts_at: DateTime - ends_at: DateTime - budget: CampaignBudget - promotions: [Promotion] -} - -type CampaignBudget { - id: ID! - type: CampaignBudgetTypeValues - limit: Int - used: Int - currency_code: String -} - -type ApplicationMethod { - id: ID! - type: ApplicationMethodTypeValues - target_type: ApplicationMethodTargetTypeValues - allocation: ApplicationMethodAllocationValues - value: Float - currency_code: String - max_quantity: Int - buy_rules_min_quantity: Int - apply_to_quantity: Int - promotion: Promotion - target_rules: [PromotionRule] - buy_rules: [PromotionRule] -} - -` diff --git a/packages/modules/promotion/src/services/promotion-module.ts b/packages/modules/promotion/src/services/promotion-module.ts index 12688def65..5666dd48a0 100644 --- a/packages/modules/promotion/src/services/promotion-module.ts +++ b/packages/modules/promotion/src/services/promotion-module.ts @@ -7,7 +7,6 @@ import { FindConfig, InferEntityType, InternalModuleDeclaration, - ModuleJoinerConfig, ModulesSdkTypes, PromotionDTO, PromotionTypes, @@ -62,7 +61,6 @@ import { validateApplicationMethodAttributes, validatePromotionRuleAttributes, } from "@utils" -import { joinerConfig } from "../joiner-config" import { CreatePromotionRuleValueDTO } from "../types/promotion-rule-value" import { buildPromotionRuleQueryFilterFromContext } from "../utils/compute-actions/build-promotion-rule-query-filter-from-context" @@ -147,10 +145,6 @@ export default class PromotionModuleService this.campaignBudgetUsageService_ = campaignBudgetUsageService } - __joinerConfig(): ModuleJoinerConfig { - return joinerConfig - } - @InjectManager() async listActivePromotions( filters?: FilterablePromotionProps,