-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added decline order change workflow (#8041)
- Loading branch information
Showing
5 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
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
45 changes: 45 additions & 0 deletions
45
packages/core/core-flows/src/order/steps/decline-order-change.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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { | ||
DeclineOrderChangeDTO, | ||
IOrderModuleService, | ||
UpdateOrderChangeDTO, | ||
} from "@medusajs/types" | ||
import { | ||
getSelectsAndRelationsFromObjectArray, | ||
ModuleRegistrationName, | ||
} from "@medusajs/utils" | ||
import { createStep, StepResponse } from "@medusajs/workflows-sdk" | ||
|
||
export const declineOrderChangeStepId = "decline-order-change" | ||
export const declineOrderChangeStep = createStep( | ||
declineOrderChangeStepId, | ||
async (data: DeclineOrderChangeDTO, { container }) => { | ||
const service = container.resolve<IOrderModuleService>( | ||
ModuleRegistrationName.ORDER | ||
) | ||
|
||
const { selects, relations } = getSelectsAndRelationsFromObjectArray( | ||
[data], | ||
{ objectFields: ["metadata"] } | ||
) | ||
|
||
const dataBeforeUpdate = await service.retrieveOrderChange(data.id, { | ||
select: [...selects, "declined_at"], | ||
relations, | ||
}) | ||
|
||
await service.declineOrderChange(data) | ||
|
||
return new StepResponse(void 0, dataBeforeUpdate) | ||
}, | ||
async (rollbackData, { container }) => { | ||
if (!rollbackData) { | ||
return | ||
} | ||
|
||
const service = container.resolve<IOrderModuleService>( | ||
ModuleRegistrationName.ORDER | ||
) | ||
|
||
await service.updateOrderChanges(rollbackData as UpdateOrderChangeDTO) | ||
} | ||
) |
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
11 changes: 11 additions & 0 deletions
11
packages/core/core-flows/src/order/workflows/decline-order-change.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { DeclineOrderChangeDTO } from "@medusajs/types" | ||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk" | ||
import { declineOrderChangeStep } from "../steps" | ||
|
||
export const declineOrderChangeWorkflowId = "decline-order-change" | ||
export const declineOrderChangeWorkflow = createWorkflow( | ||
declineOrderChangeWorkflowId, | ||
(input: WorkflowData<DeclineOrderChangeDTO>): WorkflowData<void> => { | ||
declineOrderChangeStep(input) | ||
} | ||
) |
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