-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add hooks to campaigns (#8450)
- Loading branch information
1 parent
f415e66
commit 8fb0797
Showing
12 changed files
with
164 additions
and
61 deletions.
There are no files selected for viewing
17 changes: 13 additions & 4 deletions
17
packages/core/core-flows/src/promotion/workflows/create-campaigns.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
import { CampaignDTO, CreateCampaignDTO } from "@medusajs/types" | ||
import { AdditionalData, CreateCampaignDTO } from "@medusajs/types" | ||
import { | ||
WorkflowData, | ||
WorkflowResponse, | ||
createHook, | ||
createWorkflow, | ||
} from "@medusajs/workflows-sdk" | ||
import { createCampaignsStep } from "../steps" | ||
|
||
type WorkflowInput = { campaignsData: CreateCampaignDTO[] } | ||
type WorkflowInput = { campaignsData: CreateCampaignDTO[] } & AdditionalData | ||
|
||
export const createCampaignsWorkflowId = "create-campaigns" | ||
export const createCampaignsWorkflow = createWorkflow( | ||
createCampaignsWorkflowId, | ||
(input: WorkflowData<WorkflowInput>): WorkflowResponse<CampaignDTO[]> => { | ||
return new WorkflowResponse(createCampaignsStep(input.campaignsData)) | ||
(input: WorkflowData<WorkflowInput>) => { | ||
const createdCampaigns = createCampaignsStep(input.campaignsData) | ||
const campaignsCreated = createHook("campaignsCreated", { | ||
campaigns: createdCampaigns, | ||
additional_data: input.additional_data, | ||
}) | ||
|
||
return new WorkflowResponse(createdCampaigns, { | ||
hooks: [campaignsCreated], | ||
}) | ||
} | ||
) |
17 changes: 13 additions & 4 deletions
17
packages/core/core-flows/src/promotion/workflows/create-promotions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
import { CreatePromotionDTO, PromotionDTO } from "@medusajs/types" | ||
import { AdditionalData, CreatePromotionDTO } from "@medusajs/types" | ||
import { | ||
WorkflowData, | ||
WorkflowResponse, | ||
createHook, | ||
createWorkflow, | ||
} from "@medusajs/workflows-sdk" | ||
import { createPromotionsStep } from "../steps" | ||
|
||
type WorkflowInput = { promotionsData: CreatePromotionDTO[] } | ||
type WorkflowInput = { promotionsData: CreatePromotionDTO[] } & AdditionalData | ||
|
||
export const createPromotionsWorkflowId = "create-promotions" | ||
export const createPromotionsWorkflow = createWorkflow( | ||
createPromotionsWorkflowId, | ||
(input: WorkflowData<WorkflowInput>): WorkflowResponse<PromotionDTO[]> => { | ||
return new WorkflowResponse(createPromotionsStep(input.promotionsData)) | ||
(input: WorkflowData<WorkflowInput>) => { | ||
const createdPromotions = createPromotionsStep(input.promotionsData) | ||
const promotionsCreated = createHook("promotionsCreated", { | ||
promotions: createdPromotions, | ||
additional_data: input.additional_data, | ||
}) | ||
|
||
return new WorkflowResponse(createdPromotions, { | ||
hooks: [promotionsCreated], | ||
}) | ||
} | ||
) |
13 changes: 10 additions & 3 deletions
13
packages/core/core-flows/src/promotion/workflows/delete-campaigns.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import { createWorkflow, WorkflowData } from "@medusajs/workflows-sdk" | ||
import { createHook, createWorkflow, WorkflowData, WorkflowResponse } from "@medusajs/workflows-sdk" | ||
import { deleteCampaignsStep } from "../steps" | ||
|
||
type WorkflowInput = { ids: string[] } | ||
|
||
export const deleteCampaignsWorkflowId = "delete-campaigns" | ||
export const deleteCampaignsWorkflow = createWorkflow( | ||
deleteCampaignsWorkflowId, | ||
(input: WorkflowData<WorkflowInput>): WorkflowData<void> => { | ||
return deleteCampaignsStep(input.ids) | ||
(input: WorkflowData<WorkflowInput>) => { | ||
const deletedCampaigns = deleteCampaignsStep(input.ids) | ||
const campaignsDeleted = createHook("campaignsDeleted", { | ||
ids: input.ids | ||
}) | ||
|
||
return new WorkflowResponse(deletedCampaigns, { | ||
hooks: [campaignsDeleted] | ||
}) | ||
} | ||
) |
13 changes: 10 additions & 3 deletions
13
packages/core/core-flows/src/promotion/workflows/delete-promotions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import { createWorkflow, WorkflowData } from "@medusajs/workflows-sdk" | ||
import { createHook, createWorkflow, WorkflowData, WorkflowResponse } from "@medusajs/workflows-sdk" | ||
import { deletePromotionsStep } from "../steps" | ||
|
||
type WorkflowInput = { ids: string[] } | ||
|
||
export const deletePromotionsWorkflowId = "delete-promotions" | ||
export const deletePromotionsWorkflow = createWorkflow( | ||
deletePromotionsWorkflowId, | ||
(input: WorkflowData<WorkflowInput>): WorkflowData<void> => { | ||
return deletePromotionsStep(input.ids) | ||
(input: WorkflowData<WorkflowInput>) => { | ||
const deletedPromotions = deletePromotionsStep(input.ids) | ||
const promotionsDeleted = createHook("promotionsDeleted", { | ||
ids: input.ids | ||
}) | ||
|
||
return new WorkflowResponse(deletedPromotions, { | ||
hooks: [promotionsDeleted] | ||
}) | ||
} | ||
) |
17 changes: 13 additions & 4 deletions
17
packages/core/core-flows/src/promotion/workflows/update-campaigns.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
import { CampaignDTO, UpdateCampaignDTO } from "@medusajs/types" | ||
import { AdditionalData, UpdateCampaignDTO } from "@medusajs/types" | ||
import { | ||
WorkflowData, | ||
WorkflowResponse, | ||
createHook, | ||
createWorkflow, | ||
} from "@medusajs/workflows-sdk" | ||
import { updateCampaignsStep } from "../steps" | ||
|
||
type WorkflowInput = { campaignsData: UpdateCampaignDTO[] } | ||
type WorkflowInput = { campaignsData: UpdateCampaignDTO[] } & AdditionalData | ||
|
||
export const updateCampaignsWorkflowId = "update-campaigns" | ||
export const updateCampaignsWorkflow = createWorkflow( | ||
updateCampaignsWorkflowId, | ||
(input: WorkflowData<WorkflowInput>): WorkflowResponse<CampaignDTO[]> => { | ||
return new WorkflowResponse(updateCampaignsStep(input.campaignsData)) | ||
(input: WorkflowData<WorkflowInput>) => { | ||
const updatedCampaigns = updateCampaignsStep(input.campaignsData) | ||
const campaignsUpdated = createHook("campaignsUpdated", { | ||
campaigns: updatedCampaigns, | ||
additional_data: input.additional_data, | ||
}) | ||
|
||
return new WorkflowResponse(updatedCampaigns, { | ||
hooks: [campaignsUpdated], | ||
}) | ||
} | ||
) |
20 changes: 16 additions & 4 deletions
20
packages/core/core-flows/src/promotion/workflows/update-promotions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,29 @@ | ||
import { PromotionDTO, UpdatePromotionDTO } from "@medusajs/types" | ||
import { | ||
AdditionalData, | ||
UpdatePromotionDTO, | ||
} from "@medusajs/types" | ||
import { | ||
WorkflowData, | ||
WorkflowResponse, | ||
createHook, | ||
createWorkflow, | ||
} from "@medusajs/workflows-sdk" | ||
import { updatePromotionsStep } from "../steps" | ||
|
||
type WorkflowInput = { promotionsData: UpdatePromotionDTO[] } | ||
type WorkflowInput = { promotionsData: UpdatePromotionDTO[] } & AdditionalData | ||
|
||
export const updatePromotionsWorkflowId = "update-promotions" | ||
export const updatePromotionsWorkflow = createWorkflow( | ||
updatePromotionsWorkflowId, | ||
(input: WorkflowData<WorkflowInput>): WorkflowResponse<PromotionDTO[]> => { | ||
return new WorkflowResponse(updatePromotionsStep(input.promotionsData)) | ||
(input: WorkflowData<WorkflowInput>) => { | ||
const updatedPromotions = updatePromotionsStep(input.promotionsData) | ||
const promotionsUpdated = createHook("promotionsUpdated", { | ||
promotions: updatedPromotions, | ||
additional_data: input.additional_data, | ||
}) | ||
|
||
return new WorkflowResponse(updatedPromotions, { | ||
hooks: [promotionsUpdated], | ||
}) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.