Chore/rm main entity concept (#7709)
**What** Update the `MedusaService` class, factory and types to remove the concept of main modules. The idea being that all method will be explicitly named and suffixes to represent the object you are trying to manipulate. This pr also includes various fixes in different modules Co-authored-by: Stevche Radevski <4820812+sradevski@users.noreply.github.com> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
533 files changed
+6469
-9769
No files matched your search
@@ -48,7 +48,7 @@ export async function createDefaultPromotion(
|
||||
): Promise<PromotionDTO> {
|
||||
const { application_method = {}, campaign = {}, ...promotion } = data
|
||||
|
||||
return await service.create({
|
||||
return await service.createPromotions({
|
||||
code: "PROMOTION_TEST",
|
||||
type: "standard",
|
||||
campaign_id: "campaign-id-1",
|
||||
|
||||
+3
-6
@@ -1,18 +1,15 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { IPromotionModuleService } from "@medusajs/types"
|
||||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { CampaignBudgetType } from "../../../../../../core/utils/src/promotion/index"
|
||||
import { createCampaigns } from "../../../__fixtures__/campaigns"
|
||||
import { createPromotions } from "../../../__fixtures__/promotion"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
moduleIntegrationTestRunner({
|
||||
moduleIntegrationTestRunner<IPromotionModuleService>({
|
||||
moduleName: Modules.PROMOTION,
|
||||
testSuite: ({
|
||||
MikroOrmWrapper,
|
||||
service,
|
||||
}: SuiteOptions<IPromotionModuleService>) => {
|
||||
testSuite: ({ MikroOrmWrapper, service }) => {
|
||||
describe("Promotion Module Service: Campaigns", () => {
|
||||
describe("listAndCountCampaigns", () => {
|
||||
beforeEach(async () => {
|
||||
|
||||
+50
-37
@@ -40,7 +40,7 @@ moduleIntegrationTestRunner({
|
||||
it("should create a basic promotion successfully", async () => {
|
||||
const createdPromotion = await createDefaultPromotion(service, {})
|
||||
|
||||
const [promotion] = await service.list({
|
||||
const [promotion] = await service.listPromotions({
|
||||
id: [createdPromotion.id],
|
||||
})
|
||||
|
||||
@@ -113,7 +113,7 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
})
|
||||
|
||||
const [promotion] = await service.list(
|
||||
const [promotion] = await service.listPromotions(
|
||||
{ id: [createdPromotion.id] },
|
||||
{ relations: ["campaign.budget"] }
|
||||
)
|
||||
@@ -146,7 +146,7 @@ moduleIntegrationTestRunner({
|
||||
code: "PROMOTION_TEST",
|
||||
})
|
||||
|
||||
const [promotion] = await service.list(
|
||||
const [promotion] = await service.listPromotions(
|
||||
{ id: [createdPromotion.id] },
|
||||
{ relations: ["campaign.budget"] }
|
||||
)
|
||||
@@ -225,7 +225,7 @@ moduleIntegrationTestRunner({
|
||||
],
|
||||
})
|
||||
|
||||
const [promotion] = await service.list(
|
||||
const [promotion] = await service.listPromotions(
|
||||
{ id: [createdPromotion.id] },
|
||||
{ relations: ["rules", "rules.values"] }
|
||||
)
|
||||
@@ -264,7 +264,7 @@ moduleIntegrationTestRunner({
|
||||
],
|
||||
})
|
||||
|
||||
const [promotion] = await service.list(
|
||||
const [promotion] = await service.listPromotions(
|
||||
{ id: [createdPromotion.id] },
|
||||
{ relations: ["rules", "rules.values"] }
|
||||
)
|
||||
@@ -358,7 +358,7 @@ moduleIntegrationTestRunner({
|
||||
} as any,
|
||||
})
|
||||
|
||||
const [promotion] = await service.list({
|
||||
const [promotion] = await service.listPromotions({
|
||||
id: [createdPromotion.id],
|
||||
})
|
||||
|
||||
@@ -512,7 +512,7 @@ moduleIntegrationTestRunner({
|
||||
describe("update", () => {
|
||||
it("should throw an error when required params are not passed", async () => {
|
||||
const error = await service
|
||||
.update([
|
||||
.updatePromotions([
|
||||
{
|
||||
type: PromotionType.STANDARD,
|
||||
} as any,
|
||||
@@ -525,7 +525,7 @@ moduleIntegrationTestRunner({
|
||||
it("should update the attributes of a promotion successfully", async () => {
|
||||
await createDefaultPromotions(service)
|
||||
|
||||
const [updatedPromotion] = await service.update([
|
||||
const [updatedPromotion] = await service.updatePromotions([
|
||||
{
|
||||
id: "promotion-id-1",
|
||||
is_automatic: true,
|
||||
@@ -549,7 +549,7 @@ moduleIntegrationTestRunner({
|
||||
} as any)
|
||||
const applicationMethod = createdPromotion.application_method
|
||||
|
||||
const [updatedPromotion] = await service.update([
|
||||
const [updatedPromotion] = await service.updatePromotions([
|
||||
{
|
||||
id: createdPromotion.id,
|
||||
application_method: {
|
||||
@@ -574,7 +574,7 @@ moduleIntegrationTestRunner({
|
||||
} as any)
|
||||
const applicationMethod = createdPromotion.application_method
|
||||
|
||||
const [updatedPromotion] = await service.update([
|
||||
const [updatedPromotion] = await service.updatePromotions([
|
||||
{
|
||||
id: createdPromotion.id,
|
||||
application_method: {
|
||||
@@ -608,7 +608,7 @@ moduleIntegrationTestRunner({
|
||||
const applicationMethod = createdPromotion.application_method
|
||||
|
||||
let error = await service
|
||||
.update([
|
||||
.updatePromotions([
|
||||
{
|
||||
id: createdPromotion.id,
|
||||
application_method: {
|
||||
@@ -624,7 +624,7 @@ moduleIntegrationTestRunner({
|
||||
)
|
||||
|
||||
error = await service
|
||||
.update([
|
||||
.updatePromotions([
|
||||
{
|
||||
id: createdPromotion.id,
|
||||
application_method: {
|
||||
@@ -640,7 +640,7 @@ moduleIntegrationTestRunner({
|
||||
)
|
||||
|
||||
error = await service
|
||||
.update([
|
||||
.updatePromotions([
|
||||
{
|
||||
id: createdPromotion.id,
|
||||
application_method: {
|
||||
@@ -661,7 +661,7 @@ moduleIntegrationTestRunner({
|
||||
campaign_id: "campaign-id-1",
|
||||
})
|
||||
|
||||
const [updatedPromotion] = await service.update([
|
||||
const [updatedPromotion] = await service.updatePromotions([
|
||||
{
|
||||
id: createdPromotion.id,
|
||||
campaign_id: "campaign-id-2",
|
||||
@@ -686,7 +686,7 @@ moduleIntegrationTestRunner({
|
||||
const id = "promotion-id-1"
|
||||
|
||||
it("should return promotion for the given id", async () => {
|
||||
const promotion = await service.retrieve(id)
|
||||
const promotion = await service.retrievePromotion(id)
|
||||
|
||||
expect(promotion).toEqual(
|
||||
expect.objectContaining({
|
||||
@@ -699,7 +699,7 @@ moduleIntegrationTestRunner({
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.retrieve("does-not-exist")
|
||||
await service.retrievePromotion("does-not-exist")
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
@@ -713,7 +713,7 @@ moduleIntegrationTestRunner({
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.retrieve(undefined as unknown as string)
|
||||
await service.retrievePromotion(undefined as unknown as string)
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
@@ -722,7 +722,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should return promotion based on config select param", async () => {
|
||||
const promotion = await service.retrieve(id, {
|
||||
const promotion = await service.retrievePromotion(id, {
|
||||
select: ["id"],
|
||||
})
|
||||
|
||||
@@ -757,7 +757,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should return all promotions and count", async () => {
|
||||
const [promotions, count] = await service.listAndCount()
|
||||
const [promotions, count] = await service.listAndCountPromotions()
|
||||
|
||||
expect(count).toEqual(2)
|
||||
expect(promotions).toEqual([
|
||||
@@ -789,7 +789,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should return all promotions based on config select and relations param", async () => {
|
||||
const [promotions, count] = await service.listAndCount(
|
||||
const [promotions, count] = await service.listAndCountPromotions(
|
||||
{
|
||||
id: ["promotion-id-1"],
|
||||
},
|
||||
@@ -820,9 +820,9 @@ moduleIntegrationTestRunner({
|
||||
type: "standard",
|
||||
})
|
||||
|
||||
await service.delete([createdPromotion.id])
|
||||
await service.deletePromotions([createdPromotion.id])
|
||||
|
||||
const promotions = await service.list(
|
||||
const promotions = await service.listPromotions(
|
||||
{
|
||||
id: [createdPromotion.id],
|
||||
},
|
||||
@@ -840,9 +840,9 @@ moduleIntegrationTestRunner({
|
||||
type: "standard",
|
||||
})
|
||||
|
||||
await service.softDelete([createdPromotion.id])
|
||||
await service.softDeletePromotions([createdPromotion.id])
|
||||
|
||||
const promotions = await service.list({
|
||||
const promotions = await service.listPromotions({
|
||||
id: [createdPromotion.id],
|
||||
})
|
||||
|
||||
@@ -857,14 +857,18 @@ moduleIntegrationTestRunner({
|
||||
type: "standard",
|
||||
})
|
||||
|
||||
await service.softDelete([createdPromotion.id])
|
||||
await service.softDeletePromotions([createdPromotion.id])
|
||||
|
||||
let promotions = await service.list({ id: [createdPromotion.id] })
|
||||
let promotions = await service.listPromotions({
|
||||
id: [createdPromotion.id],
|
||||
})
|
||||
|
||||
expect(promotions).toHaveLength(0)
|
||||
await service.restore([createdPromotion.id])
|
||||
await service.restorePromotions([createdPromotion.id])
|
||||
|
||||
promotions = await service.list({ id: [createdPromotion.id] })
|
||||
promotions = await service.listPromotions({
|
||||
id: [createdPromotion.id],
|
||||
})
|
||||
expect(promotions).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
@@ -1127,9 +1131,12 @@ moduleIntegrationTestRunner({
|
||||
|
||||
await service.removePromotionRules(promotion.id, ruleIds)
|
||||
|
||||
const updatedPromotion = await service.retrieve(promotion.id, {
|
||||
relations: ["rules", "rules.values"],
|
||||
})
|
||||
const updatedPromotion = await service.retrievePromotion(
|
||||
promotion.id,
|
||||
{
|
||||
relations: ["rules", "rules.values"],
|
||||
}
|
||||
)
|
||||
|
||||
expect(updatedPromotion).toEqual(
|
||||
expect.objectContaining({
|
||||
@@ -1193,9 +1200,12 @@ moduleIntegrationTestRunner({
|
||||
|
||||
await service.removePromotionTargetRules(promotion.id, ruleIds)
|
||||
|
||||
const updatedPromotion = await service.retrieve(promotion.id, {
|
||||
relations: ["application_method.target_rules.values"],
|
||||
})
|
||||
const updatedPromotion = await service.retrievePromotion(
|
||||
promotion.id,
|
||||
{
|
||||
relations: ["application_method.target_rules.values"],
|
||||
}
|
||||
)
|
||||
|
||||
expect(updatedPromotion).toEqual(
|
||||
expect.objectContaining({
|
||||
@@ -1271,9 +1281,12 @@ moduleIntegrationTestRunner({
|
||||
|
||||
await service.removePromotionBuyRules(promotion.id, ruleIds)
|
||||
|
||||
const updatedPromotion = await service.retrieve(promotion.id, {
|
||||
relations: ["application_method.buy_rules.values"],
|
||||
})
|
||||
const updatedPromotion = await service.retrievePromotion(
|
||||
promotion.id,
|
||||
{
|
||||
relations: ["application_method.buy_rules.values"],
|
||||
}
|
||||
)
|
||||
|
||||
expect(updatedPromotion).toEqual(
|
||||
expect.objectContaining({
|
||||
|
||||
@@ -8,10 +8,7 @@
|
||||
"dist"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
},
|
||||
"bin": {
|
||||
"medusa-promotion-seed": "dist/scripts/bin/run-seed.js"
|
||||
"node": ">=20"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import { moduleDefinition } from "./module-definition"
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { PromotionModuleService } from "@services"
|
||||
|
||||
const moduleDefinition: ModuleExports = {
|
||||
service: PromotionModuleService,
|
||||
}
|
||||
export default moduleDefinition
|
||||
@@ -1,40 +1,19 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||
import { generateLinkableKeysMap } from "@medusajs/utils"
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
} from "@medusajs/utils"
|
||||
import { Campaign, Promotion, PromotionRule } from "@models"
|
||||
|
||||
export const LinkableKeys = {
|
||||
promotion_id: Promotion.name,
|
||||
campaign_id: Campaign.name,
|
||||
promotion_rule_id: PromotionRule.name,
|
||||
}
|
||||
export const joinerConfig = defineJoinerConfig(Modules.PROMOTION, {
|
||||
entityQueryingConfig: [Promotion, Campaign, PromotionRule],
|
||||
linkableKeys: {
|
||||
promotion_id: Promotion.name,
|
||||
campaign_id: Campaign.name,
|
||||
promotion_rule_id: PromotionRule.name,
|
||||
},
|
||||
})
|
||||
|
||||
export const entityNameToLinkableKeysMap = generateLinkableKeysMap(LinkableKeys)
|
||||
|
||||
export const joinerConfig: ModuleJoinerConfig = {
|
||||
serviceName: Modules.PROMOTION,
|
||||
primaryKeys: ["id"],
|
||||
linkableKeys: LinkableKeys,
|
||||
alias: [
|
||||
{
|
||||
name: ["promotion", "promotions"],
|
||||
args: {
|
||||
entity: Promotion.name,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["campaign", "campaigns"],
|
||||
args: {
|
||||
entity: Campaign.name,
|
||||
methodSuffix: "Campaigns",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["promotion_rule", "promotion_rules"],
|
||||
args: {
|
||||
entity: PromotionRule.name,
|
||||
methodSuffix: "PromotionRules",
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -1,8 +0,0 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { PromotionModuleService } from "@services"
|
||||
|
||||
const service = PromotionModuleService
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
service,
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export { MikroOrmBaseRepository as BaseRepository } from "@medusajs/utils"
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
MathBN,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
MedusaService,
|
||||
ModulesSdkUtils,
|
||||
PromotionType,
|
||||
transformPropertiesToBigNumber,
|
||||
@@ -66,41 +67,34 @@ type InjectedDependencies = {
|
||||
campaignBudgetService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
}
|
||||
|
||||
const generateMethodForModels = {
|
||||
ApplicationMethod,
|
||||
Campaign,
|
||||
CampaignBudget,
|
||||
PromotionRule,
|
||||
PromotionRuleValue,
|
||||
}
|
||||
|
||||
export default class PromotionModuleService<
|
||||
TApplicationMethod extends ApplicationMethod = ApplicationMethod,
|
||||
TPromotion extends Promotion = Promotion,
|
||||
TPromotionRule extends PromotionRule = PromotionRule,
|
||||
TPromotionRuleValue extends PromotionRuleValue = PromotionRuleValue,
|
||||
TCampaign extends Campaign = Campaign,
|
||||
TCampaignBudget extends CampaignBudget = CampaignBudget
|
||||
>
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
PromotionTypes.PromotionDTO,
|
||||
export default class PromotionModuleService
|
||||
extends MedusaService<{
|
||||
Promotion: { dto: PromotionTypes.PromotionDTO }
|
||||
ApplicationMethod: { dto: PromotionTypes.ApplicationMethodDTO }
|
||||
Campaign: { dto: PromotionTypes.CampaignDTO }
|
||||
CampaignBudget: { dto: PromotionTypes.CampaignBudgetDTO }
|
||||
PromotionRule: { dto: PromotionTypes.PromotionRuleDTO }
|
||||
PromotionRuleValue: { dto: PromotionTypes.PromotionRuleValueDTO }
|
||||
}>(
|
||||
{
|
||||
ApplicationMethod: { dto: PromotionTypes.ApplicationMethodDTO }
|
||||
Campaign: { dto: PromotionTypes.CampaignDTO }
|
||||
CampaignBudget: { dto: PromotionTypes.CampaignBudgetDTO }
|
||||
PromotionRule: { dto: PromotionTypes.PromotionRuleDTO }
|
||||
PromotionRuleValue: { dto: PromotionTypes.PromotionRuleValueDTO }
|
||||
}
|
||||
>(Promotion, generateMethodForModels, entityNameToLinkableKeysMap)
|
||||
Promotion,
|
||||
ApplicationMethod,
|
||||
Campaign,
|
||||
CampaignBudget,
|
||||
PromotionRule,
|
||||
PromotionRuleValue,
|
||||
},
|
||||
entityNameToLinkableKeysMap
|
||||
)
|
||||
implements PromotionTypes.IPromotionModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected promotionService_: ModulesSdkTypes.IMedusaInternalService<TPromotion>
|
||||
protected applicationMethodService_: ModulesSdkTypes.IMedusaInternalService<TApplicationMethod>
|
||||
protected promotionRuleService_: ModulesSdkTypes.IMedusaInternalService<TPromotionRule>
|
||||
protected promotionRuleValueService_: ModulesSdkTypes.IMedusaInternalService<TPromotionRuleValue>
|
||||
protected campaignService_: ModulesSdkTypes.IMedusaInternalService<TCampaign>
|
||||
protected campaignBudgetService_: ModulesSdkTypes.IMedusaInternalService<TCampaignBudget>
|
||||
protected promotionService_: ModulesSdkTypes.IMedusaInternalService<Promotion>
|
||||
protected applicationMethodService_: ModulesSdkTypes.IMedusaInternalService<ApplicationMethod>
|
||||
protected promotionRuleService_: ModulesSdkTypes.IMedusaInternalService<PromotionRule>
|
||||
protected promotionRuleValueService_: ModulesSdkTypes.IMedusaInternalService<PromotionRuleValue>
|
||||
protected campaignService_: ModulesSdkTypes.IMedusaInternalService<Campaign>
|
||||
protected campaignBudgetService_: ModulesSdkTypes.IMedusaInternalService<CampaignBudget>
|
||||
|
||||
constructor(
|
||||
{
|
||||
@@ -145,7 +139,7 @@ export default class PromotionModuleService<
|
||||
>()
|
||||
const promotionCodeUsageMap = new Map<string, boolean>()
|
||||
|
||||
const existingPromotions = await this.list(
|
||||
const existingPromotions = await this.listPromotions(
|
||||
{ code: promotionCodes },
|
||||
{ relations: ["application_method", "campaign", "campaign.budget"] },
|
||||
sharedContext
|
||||
@@ -256,7 +250,7 @@ export default class PromotionModuleService<
|
||||
const methodIdPromoValueMap = new Map<string, number>()
|
||||
const automaticPromotions = preventAutoPromotions
|
||||
? []
|
||||
: await this.list(
|
||||
: await this.listPromotions(
|
||||
{ is_automatic: true },
|
||||
{ select: ["code"], take: null },
|
||||
sharedContext
|
||||
@@ -296,7 +290,7 @@ export default class PromotionModuleService<
|
||||
})
|
||||
})
|
||||
|
||||
const promotions = await this.list(
|
||||
const promotions = await this.listPromotions(
|
||||
{
|
||||
code: [
|
||||
...promotionCodesToApply,
|
||||
@@ -432,27 +426,28 @@ export default class PromotionModuleService<
|
||||
return computedActions
|
||||
}
|
||||
|
||||
async create(
|
||||
// @ts-expect-error
|
||||
async createPromotions(
|
||||
data: PromotionTypes.CreatePromotionDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<PromotionTypes.PromotionDTO>
|
||||
|
||||
async create(
|
||||
async createPromotions(
|
||||
data: PromotionTypes.CreatePromotionDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<PromotionTypes.PromotionDTO[]>
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async create(
|
||||
async createPromotions(
|
||||
data:
|
||||
| PromotionTypes.CreatePromotionDTO
|
||||
| PromotionTypes.CreatePromotionDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<PromotionTypes.PromotionDTO | PromotionTypes.PromotionDTO[]> {
|
||||
const input = Array.isArray(data) ? data : [data]
|
||||
const createdPromotions = await this.create_(input, sharedContext)
|
||||
const createdPromotions = await this.createPromotions_(input, sharedContext)
|
||||
|
||||
const promotions = await this.list(
|
||||
const promotions = await this.listPromotions(
|
||||
{ id: createdPromotions.map((p) => p!.id) },
|
||||
{
|
||||
relations: [
|
||||
@@ -475,7 +470,7 @@ export default class PromotionModuleService<
|
||||
}
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
protected async create_(
|
||||
protected async createPromotions_(
|
||||
data: PromotionTypes.CreatePromotionDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
) {
|
||||
@@ -699,27 +694,28 @@ export default class PromotionModuleService<
|
||||
return createdPromotions
|
||||
}
|
||||
|
||||
async update(
|
||||
// @ts-expect-error
|
||||
async updatePromotions(
|
||||
data: PromotionTypes.UpdatePromotionDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<PromotionTypes.PromotionDTO>
|
||||
|
||||
async update(
|
||||
async updatePromotions(
|
||||
data: PromotionTypes.UpdatePromotionDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<PromotionTypes.PromotionDTO[]>
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async update(
|
||||
async updatePromotions(
|
||||
data:
|
||||
| PromotionTypes.UpdatePromotionDTO
|
||||
| PromotionTypes.UpdatePromotionDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<PromotionTypes.PromotionDTO | PromotionTypes.PromotionDTO[]> {
|
||||
const input = Array.isArray(data) ? data : [data]
|
||||
const updatedPromotions = await this.update_(input, sharedContext)
|
||||
const updatedPromotions = await this.updatePromotions_(input, sharedContext)
|
||||
|
||||
const promotions = await this.list(
|
||||
const promotions = await this.listPromotions(
|
||||
{ id: updatedPromotions.map((p) => p!.id) },
|
||||
{
|
||||
relations: [
|
||||
@@ -740,7 +736,7 @@ export default class PromotionModuleService<
|
||||
}
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
protected async update_(
|
||||
protected async updatePromotions_(
|
||||
data: PromotionTypes.UpdatePromotionDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
) {
|
||||
@@ -1014,8 +1010,8 @@ export default class PromotionModuleService<
|
||||
relationName: "promotions" | "method_target_rules" | "method_buy_rules",
|
||||
relation: Promotion | ApplicationMethod,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TPromotionRule[]> {
|
||||
const createdPromotionRules: TPromotionRule[] = []
|
||||
): Promise<PromotionRule[]> {
|
||||
const createdPromotionRules: PromotionRule[] = []
|
||||
const promotion =
|
||||
relation instanceof ApplicationMethod ? relation.promotion : relation
|
||||
|
||||
|
||||
Reference in new issue
Block a user