Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/order claims 2 #8312

Merged
merged 16 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
528 changes: 528 additions & 0 deletions integration-tests/http/__tests__/claims/claims.spec.ts

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions integration-tests/http/__tests__/returns/returns.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ medusaIntegrationTestRunner({
},
currency_code: "usd",
customer_id: "joe",
transactions: [
{
amount: 20,
currency_code: "usd",
},
],
})

shippingProfile = (
Expand Down Expand Up @@ -328,13 +334,15 @@ medusaIntegrationTestRunner({
},
adminHeaders
)

await api.post(
`/admin/returns/${returnId2}/shipping-method`,
{
shipping_option_id: returnShippingOption.id,
},
adminHeaders
)

await api.post(`/admin/returns/${returnId2}/request`, {}, adminHeaders)

const returnId = result.data.return.id
Expand Down
59 changes: 59 additions & 0 deletions packages/core/core-flows/src/order/steps/create-claim-items.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { IOrderModuleService, OrderChangeActionDTO } from "@medusajs/types"
import { ChangeActionType, ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

type CreateOrderClaimItemsInput = {
changes: OrderChangeActionDTO[]
claimId: string
}

export const createOrderClaimItemsStep = createStep(
"create-claim-items",
async (input: CreateOrderClaimItemsInput, { container }) => {
const orderModuleService = container.resolve<IOrderModuleService>(
ModuleRegistrationName.ORDER
)

const claimItems = input.changes.map((item) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Should we put this in a transformer in the workflow?

let additionalFields
if (item.action === ChangeActionType.ITEM_ADD) {
additionalFields = {
is_additional_item: true,
}
} else if (item.action === ChangeActionType.WRITE_OFF_ITEM) {
additionalFields = {
reason: item.details?.reason,
}
}

return {
claim_id: input.claimId,
item_id: item.details?.reference_id! as string,
quantity: item.details?.quantity as number,
note: item.internal_note,
metadata: (item.details?.metadata as Record<string, unknown>) ?? {},
...additionalFields,
}
})

const createdClaimItems = await orderModuleService.createOrderClaimItems(
claimItems
)

return new StepResponse(
createdClaimItems,
createdClaimItems.map((i) => i.id)
)
},
async (ids, { container }) => {
if (!ids) {
return
}

const orderModuleService = container.resolve<IOrderModuleService>(
ModuleRegistrationName.ORDER
)

await orderModuleService.deleteOrderClaimItems(ids)
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const createReturnItemsStep = createStep(
metadata: (item.details?.metadata as Record<string, unknown>) ?? {},
} as CreateOrderReturnItemDTO
})

const createdReturnItems = await orderModuleService.createReturnItems(
returnItems
)
Expand Down
1 change: 1 addition & 0 deletions packages/core/core-flows/src/order/steps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from "./cancel-order-change"
export * from "./cancel-orders"
export * from "./cancel-return"
export * from "./complete-orders"
export * from "./create-claim-items"
export * from "./create-claims"
export * from "./create-complete-return"
export * from "./create-exchanges"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const cancelBeginOrderClaimWorkflow = createWorkflow(
cancelBeginOrderClaimWorkflowId,
function (input: WorkflowInput): WorkflowData<void> {
const orderClaim: OrderClaimDTO = useRemoteQueryStep({
entry_point: "claim",
entry_point: "order_claim",
fields: ["id", "status", "order_id", "return_id", "canceled_at"],
variables: { id: input.claim_id },
list: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const orderClaimAddNewItemWorkflow = createWorkflow(
details: {
reference_id: lineItems[index].id,
quantity: item.quantity,
unit_price: item.unit_price,
unit_price: item.unit_price ?? lineItems[index].unit_price,
metadata: item.metadata,
},
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const orderClaimItemWorkflow = createWorkflow(
reference_id: orderClaim.id,
details: {
reference_id: item.id,
reason: item.reason,
quantity: item.quantity,
},
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export const orderClaimRequestItemReturnWorkflow = createWorkflow(
details: {
reference_id: item.id,
quantity: item.quantity,
reason_id: item.reason_id,
metadata: item.metadata,
},
}))
Expand Down
Loading
Loading