chore(core-flows): reorganize folder structure for promotion workflows (#6243)
workflows folder structure:
```
- src/
- promotion/
- workflows/
- create-promotion.ts
- steps/
- prepare-create-promotion-data.ts
```
RESOLVES CORE-1688
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { CreateCampaignDTO, IPromotionModuleService } from "@medusajs/types"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const createCampaignsStepId = "create-campaigns"
|
||||
export const createCampaignsStep = createStep(
|
||||
createCampaignsStepId,
|
||||
async (data: CreateCampaignDTO[], { container }) => {
|
||||
const promotionModule = container.resolve<IPromotionModuleService>(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
|
||||
const createdCampaigns = await promotionModule.createCampaigns(data)
|
||||
|
||||
return new StepResponse(
|
||||
createdCampaigns,
|
||||
createdCampaigns.map((createdCampaigns) => createdCampaigns.id)
|
||||
)
|
||||
},
|
||||
async (createdCampaignIds, { container }) => {
|
||||
if (!createdCampaignIds?.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const promotionModule = container.resolve<IPromotionModuleService>(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
|
||||
await promotionModule.delete(createdCampaignIds)
|
||||
}
|
||||
)
|
||||
@@ -1,31 +0,0 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { CreatePromotionDTO, IPromotionModuleService } from "@medusajs/types"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const createPromotionsStepId = "create-promotions"
|
||||
export const createPromotionsStep = createStep(
|
||||
createPromotionsStepId,
|
||||
async (data: CreatePromotionDTO[], { container }) => {
|
||||
const promotionModule = container.resolve<IPromotionModuleService>(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
|
||||
const createdPromotions = await promotionModule.create(data)
|
||||
|
||||
return new StepResponse(
|
||||
createdPromotions,
|
||||
createdPromotions.map((createdPromotions) => createdPromotions.id)
|
||||
)
|
||||
},
|
||||
async (createdPromotionIds, { container }) => {
|
||||
if (!createdPromotionIds?.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const promotionModule = container.resolve<IPromotionModuleService>(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
|
||||
await promotionModule.delete(createdPromotionIds)
|
||||
}
|
||||
)
|
||||
@@ -1,28 +0,0 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IPromotionModuleService } from "@medusajs/types"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const deleteCampaignsStepId = "delete-campaigns"
|
||||
export const deleteCampaignsStep = createStep(
|
||||
deleteCampaignsStepId,
|
||||
async (ids: string[], { container }) => {
|
||||
const promotionModule = container.resolve<IPromotionModuleService>(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
|
||||
await promotionModule.softDeleteCampaigns(ids)
|
||||
|
||||
return new StepResponse(void 0, ids)
|
||||
},
|
||||
async (idsToRestore, { container }) => {
|
||||
if (!idsToRestore?.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const promotionModule = container.resolve<IPromotionModuleService>(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
|
||||
await promotionModule.restoreCampaigns(idsToRestore)
|
||||
}
|
||||
)
|
||||
@@ -1,28 +0,0 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IPromotionModuleService } from "@medusajs/types"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const deletePromotionsStepId = "delete-promotions"
|
||||
export const deletePromotionsStep = createStep(
|
||||
deletePromotionsStepId,
|
||||
async (ids: string[], { container }) => {
|
||||
const promotionModule = container.resolve<IPromotionModuleService>(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
|
||||
await promotionModule.softDelete(ids)
|
||||
|
||||
return new StepResponse(void 0, ids)
|
||||
},
|
||||
async (idsToRestore, { container }) => {
|
||||
if (!idsToRestore?.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const promotionModule = container.resolve<IPromotionModuleService>(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
|
||||
await promotionModule.restore(idsToRestore)
|
||||
}
|
||||
)
|
||||
@@ -1,6 +0,0 @@
|
||||
export * from "./create-campaigns"
|
||||
export * from "./create-promotions"
|
||||
export * from "./delete-campaigns"
|
||||
export * from "./delete-promotions"
|
||||
export * from "./update-campaigns"
|
||||
export * from "./update-promotions"
|
||||
@@ -1,37 +0,0 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IPromotionModuleService, UpdateCampaignDTO } from "@medusajs/types"
|
||||
import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const updateCampaignsStepId = "update-campaigns"
|
||||
export const updateCampaignsStep = createStep(
|
||||
updateCampaignsStepId,
|
||||
async (data: UpdateCampaignDTO[], { container }) => {
|
||||
const promotionModule = container.resolve<IPromotionModuleService>(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
|
||||
const { selects, relations } = getSelectsAndRelationsFromObjectArray(data)
|
||||
const dataBeforeUpdate = await promotionModule.listCampaigns(
|
||||
{ id: data.map((d) => d.id) },
|
||||
{ relations, select: selects }
|
||||
)
|
||||
|
||||
const updatedCampaigns = await promotionModule.updateCampaigns(data)
|
||||
|
||||
return new StepResponse(updatedCampaigns, dataBeforeUpdate)
|
||||
},
|
||||
async (dataBeforeUpdate, { container }) => {
|
||||
if (!dataBeforeUpdate) {
|
||||
return
|
||||
}
|
||||
|
||||
const promotionModule = container.resolve<IPromotionModuleService>(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
|
||||
// TODO: This still requires some sanitation of data and transformation of
|
||||
// shapes for manytomany and oneToMany relations. Create a common util.
|
||||
await promotionModule.updateCampaigns(dataBeforeUpdate)
|
||||
}
|
||||
)
|
||||
@@ -1,37 +0,0 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IPromotionModuleService, UpdatePromotionDTO } from "@medusajs/types"
|
||||
import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const updatePromotionsStepId = "update-promotions"
|
||||
export const updatePromotionsStep = createStep(
|
||||
updatePromotionsStepId,
|
||||
async (data: UpdatePromotionDTO[], { container }) => {
|
||||
const promotionModule = container.resolve<IPromotionModuleService>(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
|
||||
const { selects, relations } = getSelectsAndRelationsFromObjectArray(data)
|
||||
const dataBeforeUpdate = await promotionModule.list(
|
||||
{ id: data.map((d) => d.id) },
|
||||
{ relations, select: selects }
|
||||
)
|
||||
|
||||
const updatedPromotions = await promotionModule.update(data)
|
||||
|
||||
return new StepResponse(updatedPromotions, dataBeforeUpdate)
|
||||
},
|
||||
async (dataBeforeUpdate, { container }) => {
|
||||
if (!dataBeforeUpdate) {
|
||||
return
|
||||
}
|
||||
|
||||
const promotionModule = container.resolve<IPromotionModuleService>(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
|
||||
// TODO: This still requires some sanitation of data and transformation of
|
||||
// shapes for manytomany and oneToMany relations. Create a common util.
|
||||
await promotionModule.update(dataBeforeUpdate)
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user