chore(medusa): return endpoints (#7823)
This commit is contained in:
@@ -7,7 +7,7 @@ import {
|
||||
updateLinksWorkflowId,
|
||||
} from "@medusajs/core-flows"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
adminHeaders,
|
||||
createAdminUser,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IFulfillmentModuleService } from "@medusajs/types"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
} from "@medusajs/core-flows"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IFulfillmentModuleService } from "@medusajs/types"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
generateCreateFulfillmentData,
|
||||
generateCreateShippingOptionsData,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IFulfillmentModuleService } from "@medusajs/types"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
import {
|
||||
generateCreateFulfillmentData,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { initialize, runMigrations } from "@medusajs/link-modules"
|
||||
import { MedusaModule, ModuleJoinerConfig } from "@medusajs/modules-sdk"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(5000000)
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
Modules,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(500000)
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
Modules,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(500000)
|
||||
|
||||
|
||||
@@ -18,10 +18,10 @@ import {
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
Modules,
|
||||
remoteQueryObjectFromString,
|
||||
RuleOperator,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(500000)
|
||||
|
||||
|
||||
@@ -18,10 +18,10 @@ import {
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
Modules,
|
||||
remoteQueryObjectFromString,
|
||||
RuleOperator,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(500000)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
adminHeaders,
|
||||
createAdminUser,
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
} from "@medusajs/core-flows"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IPaymentModuleService, IRegionModuleService } from "@medusajs/types"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import {
|
||||
} from "@medusajs/core-flows"
|
||||
import { LinkModuleUtils, ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IPaymentModuleService, IRegionModuleService } from "@medusajs/types"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
} from "@medusajs/core-flows"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IProductModuleService } from "@medusajs/types"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
|
||||
+7
-7
@@ -1,4 +1,8 @@
|
||||
import {ModuleRegistrationName} from "@medusajs/modules-sdk"
|
||||
import {
|
||||
batchShippingOptionRulesWorkflow,
|
||||
createShippingOptionsWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
BatchWorkflowInput,
|
||||
CreateShippingOptionRuleDTO,
|
||||
@@ -10,16 +14,12 @@ import {
|
||||
ShippingProfileDTO,
|
||||
UpdateShippingOptionRuleDTO,
|
||||
} from "@medusajs/types"
|
||||
import {medusaIntegrationTestRunner} from "medusa-test-utils/dist"
|
||||
import {
|
||||
batchShippingOptionRulesWorkflow,
|
||||
createShippingOptionsWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
RuleOperator,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
|
||||
+3
-3
@@ -1,3 +1,4 @@
|
||||
import { createShippingOptionsWorkflow } from "@medusajs/core-flows"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
FulfillmentSetDTO,
|
||||
@@ -7,13 +8,12 @@ import {
|
||||
ServiceZoneDTO,
|
||||
ShippingProfileDTO,
|
||||
} from "@medusajs/types"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
import { createShippingOptionsWorkflow } from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
RuleOperator,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
|
||||
+6
-6
@@ -1,3 +1,7 @@
|
||||
import {
|
||||
createShippingOptionsWorkflow,
|
||||
deleteShippingOptionsWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
FulfillmentSetDTO,
|
||||
@@ -7,16 +11,12 @@ import {
|
||||
ServiceZoneDTO,
|
||||
ShippingProfileDTO,
|
||||
} from "@medusajs/types"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
import {
|
||||
createShippingOptionsWorkflow,
|
||||
deleteShippingOptionsWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
RuleOperator,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ import {
|
||||
RuleOperator,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { ITaxModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { ITaxModuleService } from "@medusajs/types"
|
||||
|
||||
import { createAdminUser } from "../../../../helpers/create-admin-user"
|
||||
import {
|
||||
createTaxRateRulesStepId,
|
||||
updateTaxRatesWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { createAdminUser } from "../../../../helpers/create-admin-user"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import { LinkWorkflowInput } from "@medusajs/types/src"
|
||||
import { LinkWorkflowInput } from "@medusajs/types"
|
||||
import { ContainerRegistrationKeys, Modules, promiseAll } from "@medusajs/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const linkSalesChannelsToApiKeyStepId = "link-sales-channels-to-api-key"
|
||||
export const linkSalesChannelsToApiKeyStep = createStep(
|
||||
|
||||
+1
-1
@@ -1,9 +1,9 @@
|
||||
import { LinkWorkflowInput } from "@medusajs/types"
|
||||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
||||
import {
|
||||
linkSalesChannelsToApiKeyStep,
|
||||
validateSalesChannelsExistStep,
|
||||
} from "../steps"
|
||||
import { LinkWorkflowInput } from "@medusajs/types/src"
|
||||
|
||||
export const linkSalesChannelsToApiKeyWorkflowId =
|
||||
"link-sales-channels-to-api-key"
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { LinkWorkflowInput } from "@medusajs/types/src"
|
||||
import { ICustomerModuleService, LinkWorkflowInput } from "@medusajs/types"
|
||||
import { promiseAll } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const linkCustomersToCustomerGroupStepId =
|
||||
"link-customers-to-customer-group"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { LinkWorkflowInput } from "@medusajs/types"
|
||||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
||||
import { linkCustomersToCustomerGroupStep } from "../steps"
|
||||
import { LinkWorkflowInput } from "@medusajs/types/src"
|
||||
|
||||
export const linkCustomersToCustomerGroupWorkflowId =
|
||||
"link-customers-to-customer-group"
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
FulfillmentWorkflow,
|
||||
IFulfillmentModuleService,
|
||||
ShippingOptionDTO,
|
||||
UpsertShippingOptionDTO,
|
||||
} from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
arrayDifference,
|
||||
getSelectsAndRelationsFromObjectArray,
|
||||
} from "@medusajs/utils"
|
||||
import { UpsertShippingOptionDTO } from "@medusajs/types/src"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
type StepInput = Omit<
|
||||
| FulfillmentWorkflow.CreateShippingOptionsWorkflowInput
|
||||
|
||||
@@ -12,8 +12,8 @@ export const createReturnStep = createStep(
|
||||
ModuleRegistrationName.ORDER
|
||||
)
|
||||
|
||||
await service.createReturn(data)
|
||||
return new StepResponse(void 0, data.order_id)
|
||||
const orderReturn = await service.createReturn(data)
|
||||
return new StepResponse(orderReturn, data.order_id)
|
||||
},
|
||||
async (orderId, { container }) => {
|
||||
if (!orderId) {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IOrderModuleService, ReceiveOrderReturnDTO } from "@medusajs/types"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
type ReceiveReturnStepInput = ReceiveOrderReturnDTO
|
||||
|
||||
export const receiveReturnStepId = "receive-return"
|
||||
export const receiveReturnStep = createStep(
|
||||
receiveReturnStepId,
|
||||
async (data: ReceiveReturnStepInput, { container }) => {
|
||||
const service = container.resolve<IOrderModuleService>(
|
||||
ModuleRegistrationName.ORDER
|
||||
)
|
||||
|
||||
if (!data.items?.length) {
|
||||
return new StepResponse(void 0)
|
||||
}
|
||||
|
||||
const received = await service.receiveReturn(data)
|
||||
return new StepResponse(received, data.return_id)
|
||||
},
|
||||
async (orderId, { container }) => {
|
||||
if (!orderId) {
|
||||
return
|
||||
}
|
||||
|
||||
const service = container.resolve<IOrderModuleService>(
|
||||
ModuleRegistrationName.ORDER
|
||||
)
|
||||
|
||||
await service.revertLastVersion(orderId)
|
||||
}
|
||||
)
|
||||
@@ -1,4 +1,4 @@
|
||||
import { OrderDTO, OrderWorkflow } from "@medusajs/types"
|
||||
import { OrderDTO, OrderWorkflow, ReturnDTO } from "@medusajs/types"
|
||||
import { MedusaError, OrderStatus, arrayDifference } from "@medusajs/utils"
|
||||
|
||||
export function throwIfOrderIsCancelled({ order }: { order: OrderDTO }) {
|
||||
@@ -30,3 +30,37 @@ export function throwIfItemsDoesNotExistsInOrder({
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export function throwIfReturnIsCancelled({
|
||||
orderReturn,
|
||||
}: {
|
||||
orderReturn: ReturnDTO
|
||||
}) {
|
||||
if (orderReturn.canceled_at) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
`return with id ${orderReturn.id} has been canceled.`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export function throwIfItemsDoesNotExistsInReturn({
|
||||
orderReturn,
|
||||
inputItems,
|
||||
}: {
|
||||
orderReturn: Pick<ReturnDTO, "id" | "items">
|
||||
inputItems: OrderWorkflow.CreateOrderFulfillmentWorkflowInput["items"]
|
||||
}) {
|
||||
const orderReturnItemIds = orderReturn.items?.map((i) => i.id) ?? []
|
||||
const inputItemIds = inputItems.map((i) => i.id)
|
||||
const diff = arrayDifference(inputItemIds, orderReturnItemIds)
|
||||
|
||||
if (diff.length) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
`Items with ids ${diff.join(", ")} does not exist in Return with id ${
|
||||
orderReturn.id
|
||||
}.`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
BigNumberInput,
|
||||
CreateOrderShippingMethodDTO,
|
||||
FulfillmentWorkflow,
|
||||
OrderDTO,
|
||||
@@ -7,25 +8,26 @@ import {
|
||||
WithCalculatedPrice,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
arrayDifference,
|
||||
ContainerRegistrationKeys,
|
||||
isDefined,
|
||||
MathBN,
|
||||
MedusaError,
|
||||
Modules,
|
||||
arrayDifference,
|
||||
isDefined,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
createStep,
|
||||
createWorkflow,
|
||||
parallelize,
|
||||
transform,
|
||||
WorkflowData,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { createRemoteLinkStep, useRemoteQueryStep } from "../../common"
|
||||
import { createReturnFulfillmentWorkflow } from "../../fulfillment"
|
||||
import { updateOrderTaxLinesStep } from "../steps"
|
||||
import { createReturnStep } from "../steps/create-return"
|
||||
import { receiveReturnStep } from "../steps/receive-return"
|
||||
import {
|
||||
throwIfItemsDoesNotExistsInOrder,
|
||||
throwIfOrderIsCancelled,
|
||||
@@ -139,6 +141,37 @@ function validateCustomRefundAmount({
|
||||
}
|
||||
}
|
||||
|
||||
function prepareReceiveItems({
|
||||
receiveNow,
|
||||
returnId,
|
||||
items,
|
||||
createdBy,
|
||||
}: {
|
||||
receiveNow: boolean
|
||||
returnId: string
|
||||
items: {
|
||||
id: string
|
||||
quantity: BigNumberInput
|
||||
}[]
|
||||
createdBy?: string
|
||||
}) {
|
||||
if (!receiveNow) {
|
||||
return {
|
||||
return_id: returnId,
|
||||
items: [],
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
return_id: returnId,
|
||||
items: (items ?? []).map((i) => ({
|
||||
id: i.id,
|
||||
quantity: i.quantity,
|
||||
})),
|
||||
created_by: createdBy,
|
||||
}
|
||||
}
|
||||
|
||||
function prepareFulfillmentData({
|
||||
order,
|
||||
input,
|
||||
@@ -316,7 +349,7 @@ export const createReturnOrderWorkflow = createWorkflow(
|
||||
}
|
||||
)
|
||||
|
||||
parallelize(
|
||||
const [returnCreated] = parallelize(
|
||||
createReturnStep({
|
||||
order_id: input.order_id,
|
||||
items: input.items,
|
||||
@@ -329,5 +362,16 @@ export const createReturnOrderWorkflow = createWorkflow(
|
||||
}),
|
||||
createRemoteLinkStep(link)
|
||||
)
|
||||
|
||||
const receiveItems = transform(
|
||||
{
|
||||
receiveNow: input.receive_now ?? false,
|
||||
returnId: returnCreated.id,
|
||||
items: order.items!,
|
||||
createdBy: input.created_by!,
|
||||
},
|
||||
prepareReceiveItems
|
||||
)
|
||||
receiveReturnStep(receiveItems)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -7,4 +7,5 @@ export * from "./create-orders"
|
||||
export * from "./create-return"
|
||||
export * from "./create-shipment"
|
||||
export * from "./get-order-detail"
|
||||
export * from "./receive-return"
|
||||
export * from "./update-tax-lines"
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { OrderWorkflow } from "@medusajs/types"
|
||||
import {
|
||||
WorkflowData,
|
||||
createStep,
|
||||
createWorkflow,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
|
||||
import { ReturnDTO } from "@medusajs/types"
|
||||
import { receiveReturnStep } from "../steps/receive-return"
|
||||
import {
|
||||
throwIfItemsDoesNotExistsInReturn,
|
||||
throwIfReturnIsCancelled,
|
||||
} from "../utils/order-validation"
|
||||
|
||||
const validationStep = createStep(
|
||||
"receive-return-order-validation",
|
||||
async function (
|
||||
{
|
||||
orderReturn,
|
||||
input,
|
||||
}: {
|
||||
orderReturn
|
||||
input: OrderWorkflow.ReceiveOrderReturnWorkflowInput
|
||||
},
|
||||
context
|
||||
) {
|
||||
throwIfReturnIsCancelled({ orderReturn })
|
||||
throwIfItemsDoesNotExistsInReturn({ orderReturn, inputItems: input.items })
|
||||
}
|
||||
)
|
||||
|
||||
export const receiveReturnOrderWorkflowId = "receive-return-order"
|
||||
export const receiveReturnOrderWorkflow = createWorkflow(
|
||||
receiveReturnOrderWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.ReceiveOrderReturnWorkflowInput>
|
||||
): WorkflowData<ReturnDTO> {
|
||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||
entry_point: "returns",
|
||||
fields: ["id", "canceled_at", "items.*"],
|
||||
variables: { id: input.return_id },
|
||||
list: false,
|
||||
throw_if_key_not_found: true,
|
||||
})
|
||||
|
||||
validationStep({ orderReturn, input })
|
||||
|
||||
const received = receiveReturnStep(input)
|
||||
|
||||
return received
|
||||
}
|
||||
)
|
||||
@@ -1,5 +1,4 @@
|
||||
import { CreatePriceListPricesWorkflowDTO } from "@medusajs/types"
|
||||
import { PricingTypes } from "@medusajs/types/src"
|
||||
import { CreatePriceListPricesWorkflowDTO, PricingTypes } from "@medusajs/types"
|
||||
import {
|
||||
WorkflowData,
|
||||
createWorkflow,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { UpdatePriceListPricesWorkflowDTO } from "@medusajs/types"
|
||||
import { PricingTypes } from "@medusajs/types/src"
|
||||
import { PricingTypes, UpdatePriceListPricesWorkflowDTO } from "@medusajs/types"
|
||||
import {
|
||||
WorkflowData,
|
||||
createWorkflow,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IProductModuleService } from "@medusajs/types"
|
||||
import { LinkWorkflowInput } from "@medusajs/types/src"
|
||||
import { IProductModuleService, LinkWorkflowInput } from "@medusajs/types"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const batchLinkProductsToCollectionStepId =
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { LinkWorkflowInput } from "@medusajs/types"
|
||||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
||||
import { LinkWorkflowInput } from "@medusajs/types/src"
|
||||
import { batchLinkProductsToCollectionStep } from "../steps/batch-link-products-collection"
|
||||
|
||||
export const batchLinkProductsToCollectionWorkflowId =
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import {
|
||||
BatchWorkflowInput,
|
||||
BatchWorkflowOutput,
|
||||
CreateProductWorkflowInputDTO,
|
||||
ProductTypes,
|
||||
UpdateProductWorkflowInputDTO,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
WorkflowData,
|
||||
createWorkflow,
|
||||
parallelize,
|
||||
transform,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import {
|
||||
ProductTypes,
|
||||
BatchWorkflowInput,
|
||||
CreateProductWorkflowInputDTO,
|
||||
UpdateProductWorkflowInputDTO,
|
||||
} from "@medusajs/types"
|
||||
import { BatchWorkflowOutput } from "@medusajs/types/src"
|
||||
import { createProductsWorkflow } from "./create-products"
|
||||
import { updateProductsWorkflow } from "./update-products"
|
||||
import { deleteProductsWorkflow } from "./delete-products"
|
||||
import { updateProductsWorkflow } from "./update-products"
|
||||
|
||||
export const batchProductsWorkflowId = "batch-products"
|
||||
export const batchProductsWorkflow = createWorkflow(
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
ModulesSdkUtils,
|
||||
toMikroOrmEntities,
|
||||
} from "@medusajs/utils"
|
||||
import { MockEventBusService } from "."
|
||||
import { getDatabaseURL, getMikroOrmWrapper, TestDatabase } from "./database"
|
||||
import { initModules, InitModulesOptions } from "./init-modules"
|
||||
|
||||
import { ContainerRegistrationKeys, ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { MockEventBusService } from "."
|
||||
import { toMikroOrmEntities } from "@medusajs/utils/src"
|
||||
|
||||
export interface SuiteOptions<TService = unknown> {
|
||||
MikroOrmWrapper: TestDatabase
|
||||
medusaApp: any
|
||||
|
||||
@@ -3,3 +3,4 @@ export * from "./cancel-order"
|
||||
export * from "./create-fulfillment"
|
||||
export * from "./create-return-order"
|
||||
export * from "./create-shipment"
|
||||
export * from "./receive-return"
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { BigNumberInput } from "../../totals"
|
||||
|
||||
interface ReceiveReturnItem {
|
||||
id: string
|
||||
quantity: BigNumberInput
|
||||
internal_note?: string | null
|
||||
reason_id?: string | null
|
||||
note?: string | null
|
||||
metadata?: Record<string, any>
|
||||
}
|
||||
|
||||
export interface ReceiveOrderReturnWorkflowInput {
|
||||
return_id: string
|
||||
created_by?: string | null // The id of the authenticated user
|
||||
items: ReceiveReturnItem[]
|
||||
internal_note?: string | null
|
||||
}
|
||||
@@ -8,9 +8,10 @@ import {
|
||||
} from "@medusajs/orchestration"
|
||||
import { Context, LoadedModule, MedusaContainer } from "@medusajs/types"
|
||||
import {
|
||||
isPresent,
|
||||
ContainerRegistrationKeys,
|
||||
MedusaContextType,
|
||||
ModuleRegistrationName,
|
||||
isPresent,
|
||||
} from "@medusajs/utils"
|
||||
import { EOL } from "os"
|
||||
import { ulid } from "ulid"
|
||||
@@ -25,7 +26,6 @@ import {
|
||||
MainExportedWorkflow,
|
||||
WorkflowResult,
|
||||
} from "./type"
|
||||
import { ContainerRegistrationKeys } from "@medusajs/utils/dist"
|
||||
|
||||
function createContextualWorkflowRunner<
|
||||
TData = unknown,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { linkSalesChannelsToApiKeyWorkflow } from "@medusajs/core-flows"
|
||||
import { LinkMethodRequest } from "@medusajs/types"
|
||||
import { ApiKeyType, MedusaError } from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { refetchApiKey } from "../../helpers"
|
||||
import { LinkMethodRequest } from "@medusajs/types/src"
|
||||
import { linkSalesChannelsToApiKeyWorkflow } from "@medusajs/core-flows"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<LinkMethodRequest>,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { batchLinkProductsToCollectionWorkflow } from "@medusajs/core-flows"
|
||||
import { LinkMethodRequest } from "@medusajs/types"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { LinkMethodRequest } from "@medusajs/types/src"
|
||||
import { refetchCollection } from "../../helpers"
|
||||
|
||||
export const POST = async (
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
|
||||
import { LinkMethodRequest } from "@medusajs/types/src"
|
||||
import { LinkMethodRequest } from "@medusajs/types"
|
||||
import { refetchCustomerGroup } from "../../helpers"
|
||||
|
||||
export const POST = async (
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { batchPriceListPricesWorkflow } from "@medusajs/core-flows"
|
||||
import { LinkMethodRequest } from "@medusajs/types"
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { batchPriceListPricesWorkflow } from "@medusajs/core-flows"
|
||||
import { LinkMethodRequest } from "@medusajs/types/src"
|
||||
import { fetchPriceList, fetchPriceListPriceIdsForProduct } from "../../helpers"
|
||||
|
||||
export const POST = async (
|
||||
|
||||
@@ -1,35 +1,20 @@
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { receiveReturnOrderWorkflow } from "@medusajs/core-flows"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { AdminPostReceiveReturnsReqSchemaType } from "../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
req: AuthenticatedMedusaRequest<AdminPostReceiveReturnsReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
const input = req.validatedBody as AdminPostReceiveReturnsReqSchemaType
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "return",
|
||||
variables: {
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
...req.remoteQueryConfig.pagination,
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
const workflow = receiveReturnOrderWorkflow(req.scope)
|
||||
const { result } = await workflow.run({
|
||||
input,
|
||||
})
|
||||
|
||||
const { rows: orders, metadata } = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
orders,
|
||||
count: metadata.count,
|
||||
offset: metadata.skip,
|
||||
limit: metadata.take,
|
||||
})
|
||||
res.status(200).json({ return: result })
|
||||
}
|
||||
|
||||
@@ -19,17 +19,13 @@ export const GET = async (
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
...req.remoteQueryConfig.pagination,
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const { rows: orders, metadata } = await remoteQuery(queryObject)
|
||||
const [orderReturn] = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
orders,
|
||||
count: metadata.count,
|
||||
offset: metadata.skip,
|
||||
limit: metadata.take,
|
||||
return: orderReturn,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {createReturnOrderWorkflow} from "@medusajs/core-flows"
|
||||
import { createReturnOrderWorkflow } from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../types/routing"
|
||||
import {AdminPostReturnsReqSchemaType} from "./validators"
|
||||
import { AdminPostReturnsReqSchemaType } from "./validators"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
@@ -16,7 +16,7 @@ export const GET = async (
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "order",
|
||||
entryPoint: "returns",
|
||||
variables: {
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
@@ -26,10 +26,10 @@ export const GET = async (
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const { rows: orders, metadata } = await remoteQuery(queryObject)
|
||||
const { rows: returns, metadata } = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
orders,
|
||||
returns,
|
||||
count: metadata.count,
|
||||
offset: metadata.skip,
|
||||
limit: metadata.take,
|
||||
|
||||
@@ -53,7 +53,7 @@ export const AdminPostReturnsReqSchema = z.object({
|
||||
order_id: z.string(),
|
||||
items: z.array(ItemSchema),
|
||||
return_shipping: ReturnShippingSchema,
|
||||
note: z.string().nullish(),
|
||||
internal_note: z.string().nullish(),
|
||||
receive_now: z.boolean().optional(),
|
||||
refund_amount: z.number().optional(),
|
||||
location_id: z.string().nullish(),
|
||||
@@ -61,3 +61,12 @@ export const AdminPostReturnsReqSchema = z.object({
|
||||
export type AdminPostReturnsReqSchemaType = z.infer<
|
||||
typeof AdminPostReturnsReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostReceiveReturnsReqSchema = z.object({
|
||||
return_id: z.string(),
|
||||
items: z.array(ItemSchema),
|
||||
internal_note: z.string().nullish(),
|
||||
})
|
||||
export type AdminPostReceiveReturnsReqSchemaType = z.infer<
|
||||
typeof AdminPostReceiveReturnsReqSchema
|
||||
>
|
||||
|
||||
@@ -3,9 +3,9 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
|
||||
import { LinkMethodRequest } from "@medusajs/types/src"
|
||||
import { refetchSalesChannel } from "../../helpers"
|
||||
import { linkProductsToSalesChannelWorkflow } from "@medusajs/core-flows"
|
||||
import { LinkMethodRequest } from "@medusajs/types"
|
||||
import { refetchSalesChannel } from "../../helpers"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<LinkMethodRequest>,
|
||||
|
||||
@@ -3,9 +3,9 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
|
||||
import { LinkMethodRequest } from "@medusajs/types/src"
|
||||
import { refetchStockLocation } from "../../helpers"
|
||||
import { linkSalesChannelsToStockLocationWorkflow } from "@medusajs/core-flows"
|
||||
import { LinkMethodRequest } from "@medusajs/types"
|
||||
import { refetchStockLocation } from "../../helpers"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<LinkMethodRequest>,
|
||||
|
||||
+6
-4
@@ -1,7 +1,3 @@
|
||||
import { FulfillmentEvents, GeoZoneType, Modules } from "@medusajs/utils"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { MockEventBusService } from "medusa-test-utils/dist"
|
||||
import { buildExpectedEventMessageShape } from "../../__fixtures__"
|
||||
import {
|
||||
CreateFulfillmentSetDTO,
|
||||
CreateServiceZoneDTO,
|
||||
@@ -9,6 +5,12 @@ import {
|
||||
ServiceZoneDTO,
|
||||
UpdateFulfillmentSetDTO,
|
||||
} from "@medusajs/types"
|
||||
import { FulfillmentEvents, GeoZoneType, Modules } from "@medusajs/utils"
|
||||
import {
|
||||
MockEventBusService,
|
||||
moduleIntegrationTestRunner,
|
||||
} from "medusa-test-utils"
|
||||
import { buildExpectedEventMessageShape } from "../../__fixtures__"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
|
||||
+4
-4
@@ -1,15 +1,15 @@
|
||||
import { ModulesDefinition } from "@medusajs/modules-sdk"
|
||||
import { FulfillmentSetDTO, IFulfillmentModuleService } from "@medusajs/types"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { FulfillmentProviderService } from "@services"
|
||||
import {
|
||||
SuiteOptions,
|
||||
initModules,
|
||||
moduleIntegrationTestRunner,
|
||||
SuiteOptions,
|
||||
} from "medusa-test-utils/dist"
|
||||
} from "medusa-test-utils"
|
||||
import { resolve } from "path"
|
||||
import { createFullDataStructure } from "../../__fixtures__"
|
||||
import { FulfillmentProviderService } from "@services"
|
||||
import { FulfillmentProviderServiceFixtures } from "../../__fixtures__/providers"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
|
||||
let moduleOptions = {
|
||||
providers: [
|
||||
|
||||
+4
-4
@@ -1,20 +1,20 @@
|
||||
import {
|
||||
CreateShippingOptionDTO,
|
||||
IFulfillmentModuleService,
|
||||
UpdateShippingOptionDTO,
|
||||
} from "@medusajs/types"
|
||||
import { FulfillmentEvents, GeoZoneType, Modules } from "@medusajs/utils"
|
||||
import { FulfillmentProviderService } from "@services"
|
||||
import {
|
||||
MockEventBusService,
|
||||
moduleIntegrationTestRunner,
|
||||
} from "medusa-test-utils"
|
||||
import { resolve } from "path"
|
||||
import {
|
||||
buildExpectedEventMessageShape,
|
||||
generateCreateShippingOptionsData,
|
||||
} from "../../__fixtures__"
|
||||
import { resolve } from "path"
|
||||
import { FulfillmentProviderService } from "@services"
|
||||
import { FulfillmentProviderServiceFixtures } from "../../__fixtures__/providers"
|
||||
import { FulfillmentEvents, GeoZoneType, Modules } from "@medusajs/utils"
|
||||
import { UpdateShippingOptionDTO } from "@medusajs/types/src"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
|
||||
+2
-5
@@ -1,10 +1,7 @@
|
||||
import { INotificationModuleService } from "@medusajs/types"
|
||||
import {
|
||||
moduleIntegrationTestRunner,
|
||||
SuiteOptions,
|
||||
} from "medusa-test-utils/dist"
|
||||
import { resolve } from "path"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
|
||||
import { resolve } from "path"
|
||||
|
||||
let moduleOptions = {
|
||||
providers: [
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
import { IPaymentModuleService } from "@medusajs/types"
|
||||
import { Modules, promiseAll } from "@medusajs/utils"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
createPaymentCollections,
|
||||
createPayments,
|
||||
createPaymentSessions,
|
||||
createPayments,
|
||||
} from "../../../__fixtures__"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
Reference in New Issue
Block a user