chore(core-flows,medusa): order claims (#8271)
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import {
|
||||
removeItemClaimActionWorkflow,
|
||||
updateClaimItemWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../../types/routing"
|
||||
import { AdminPostClaimsItemsActionReqSchemaType } from "../../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostClaimsItemsActionReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const { id, action_id } = req.params
|
||||
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const { result } = await updateClaimItemWorkflow(req.scope).run({
|
||||
input: {
|
||||
data: { ...req.validatedBody },
|
||||
claim_id: id,
|
||||
action_id,
|
||||
},
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "claim",
|
||||
variables: {
|
||||
id,
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const [orderClaim] = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
order_preview: result,
|
||||
claim: orderClaim,
|
||||
})
|
||||
}
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const { id, action_id } = req.params
|
||||
|
||||
const { result: orderPreview } = await removeItemClaimActionWorkflow(
|
||||
req.scope
|
||||
).run({
|
||||
input: {
|
||||
claim_id: id,
|
||||
action_id,
|
||||
},
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "claim",
|
||||
variables: {
|
||||
id,
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
const [orderClaim] = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
order_preview: orderPreview,
|
||||
claim: orderClaim,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { orderClaimItemWorkflow } from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { AdminPostClaimItemsReqSchemaType } from "../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostClaimItemsReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const { result } = await orderClaimItemWorkflow(req.scope).run({
|
||||
input: { ...req.validatedBody, claim_id: id },
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "claim",
|
||||
variables: {
|
||||
id,
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const [orderClaim] = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
order_preview: result,
|
||||
claim: orderClaim,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import {
|
||||
removeItemReturnActionWorkflow,
|
||||
updateRequestItemReturnWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../../../types/routing"
|
||||
import { AdminPostReturnsRequestItemsActionReqSchemaType } from "../../../../../returns/validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostReturnsRequestItemsActionReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const { id, action_id } = req.params
|
||||
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const [claim] = await remoteQuery(
|
||||
remoteQueryObjectFromString({
|
||||
entryPoint: "claim",
|
||||
variables: {
|
||||
id,
|
||||
},
|
||||
fields: ["return_id"],
|
||||
}),
|
||||
undefined,
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
}
|
||||
)
|
||||
|
||||
const { result } = await updateRequestItemReturnWorkflow(req.scope).run({
|
||||
input: {
|
||||
data: { ...req.validatedBody },
|
||||
return_id: claim.return_id,
|
||||
action_id,
|
||||
},
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "return",
|
||||
variables: {
|
||||
id,
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const [orderReturn] = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
order_preview: result,
|
||||
return: orderReturn,
|
||||
})
|
||||
}
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const { id, action_id } = req.params
|
||||
|
||||
const { result: orderPreview } = await removeItemReturnActionWorkflow(
|
||||
req.scope
|
||||
).run({
|
||||
input: {
|
||||
return_id: id,
|
||||
action_id,
|
||||
},
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "return",
|
||||
variables: {
|
||||
id,
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
const [orderReturn] = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
order_preview: orderPreview,
|
||||
return: orderReturn,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { orderClaimRequestItemReturnWorkflow } from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../../types/routing"
|
||||
import { AdminPostReturnsRequestItemsReqSchemaType } from "../../../../returns/validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostReturnsRequestItemsReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const [claim] = await remoteQuery(
|
||||
remoteQueryObjectFromString({
|
||||
entryPoint: "claim",
|
||||
variables: {
|
||||
id,
|
||||
},
|
||||
fields: ["return_id"],
|
||||
}),
|
||||
undefined,
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
}
|
||||
)
|
||||
|
||||
const { result } = await orderClaimRequestItemReturnWorkflow(req.scope).run({
|
||||
input: { ...req.validatedBody, return_id: claim.return_id, claim_id: id },
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "return",
|
||||
variables: {
|
||||
id,
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const [orderReturn] = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
order_preview: result,
|
||||
return: orderReturn,
|
||||
})
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
import {
|
||||
removeReturnShippingMethodWorkflow,
|
||||
updateReturnShippingMethodWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../../../types/routing"
|
||||
import { AdminPostClaimsShippingActionReqSchemaType } from "../../../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostClaimsShippingActionReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const { id, action_id } = req.params
|
||||
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const [claim] = await remoteQuery(
|
||||
remoteQueryObjectFromString({
|
||||
entryPoint: "claim",
|
||||
variables: {
|
||||
id,
|
||||
},
|
||||
fields: ["return_id"],
|
||||
}),
|
||||
undefined,
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
}
|
||||
)
|
||||
|
||||
const { result } = await updateReturnShippingMethodWorkflow(req.scope).run({
|
||||
input: {
|
||||
data: { ...req.validatedBody },
|
||||
return_id: claim.return_id,
|
||||
action_id,
|
||||
},
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "claim",
|
||||
variables: {
|
||||
id,
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const [orderClaim] = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
order_preview: result,
|
||||
claim: orderClaim,
|
||||
})
|
||||
}
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const { id, action_id } = req.params
|
||||
|
||||
const [claim] = await remoteQuery(
|
||||
remoteQueryObjectFromString({
|
||||
entryPoint: "claim",
|
||||
variables: {
|
||||
id,
|
||||
},
|
||||
fields: ["return_id"],
|
||||
}),
|
||||
undefined,
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
}
|
||||
)
|
||||
|
||||
const { result: orderPreview } = await removeReturnShippingMethodWorkflow(
|
||||
req.scope
|
||||
).run({
|
||||
input: {
|
||||
return_id: claim.return_id,
|
||||
action_id,
|
||||
},
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "claim",
|
||||
variables: {
|
||||
id,
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
const [orderClaim] = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
order_preview: orderPreview,
|
||||
claim: orderClaim,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { createClaimShippingMethodWorkflow } from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../../types/routing"
|
||||
import { AdminPostReturnsShippingReqSchemaType } from "../../../../returns/validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostReturnsShippingReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const [claim] = await remoteQuery(
|
||||
remoteQueryObjectFromString({
|
||||
entryPoint: "claim",
|
||||
variables: {
|
||||
id,
|
||||
},
|
||||
fields: ["return_id"],
|
||||
}),
|
||||
undefined,
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
}
|
||||
)
|
||||
|
||||
const { result } = await createClaimShippingMethodWorkflow(req.scope).run({
|
||||
input: { ...req.validatedBody, return_id: claim.return_id, claim_id: id },
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "return",
|
||||
variables: {
|
||||
id,
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const [orderClaim] = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
order_preview: result,
|
||||
return: orderClaim,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import {
|
||||
removeItemClaimActionWorkflow,
|
||||
updateClaimAddItemWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../../../types/routing"
|
||||
import { AdminPostClaimsItemsActionReqSchemaType } from "../../../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostClaimsItemsActionReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const { id, action_id } = req.params
|
||||
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const { result } = await updateClaimAddItemWorkflow(req.scope).run({
|
||||
input: {
|
||||
data: { ...req.validatedBody },
|
||||
claim_id: id,
|
||||
action_id,
|
||||
},
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "claim",
|
||||
variables: {
|
||||
id,
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const [orderClaim] = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
order_preview: result,
|
||||
claim: orderClaim,
|
||||
})
|
||||
}
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const { id, action_id } = req.params
|
||||
|
||||
const { result: orderPreview } = await removeItemClaimActionWorkflow(
|
||||
req.scope
|
||||
).run({
|
||||
input: {
|
||||
claim_id: id,
|
||||
action_id,
|
||||
},
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "claim",
|
||||
variables: {
|
||||
id,
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
const [orderClaim] = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
order_preview: orderPreview,
|
||||
claim: orderClaim,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { orderClaimAddNewItemWorkflow } from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../../types/routing"
|
||||
import { AdminPostClaimsAddItemsReqSchemaType } from "../../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostClaimsAddItemsReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const { result } = await orderClaimAddNewItemWorkflow(req.scope).run({
|
||||
input: { ...req.validatedBody, claim_id: id },
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "claim",
|
||||
variables: {
|
||||
id,
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const [orderClaim] = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
order_preview: result,
|
||||
claim: orderClaim,
|
||||
})
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
import {
|
||||
removeClaimShippingMethodWorkflow,
|
||||
updateClaimShippingMethodWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../../../types/routing"
|
||||
import { AdminPostClaimsShippingActionReqSchemaType } from "../../../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostClaimsShippingActionReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const { id, action_id } = req.params
|
||||
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const { result } = await updateClaimShippingMethodWorkflow(req.scope).run({
|
||||
input: {
|
||||
data: { ...req.validatedBody },
|
||||
claim_id: id,
|
||||
action_id,
|
||||
},
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "claim",
|
||||
variables: {
|
||||
id,
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const [orderClaim] = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
order_preview: result,
|
||||
claim: orderClaim,
|
||||
})
|
||||
}
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const { id, action_id } = req.params
|
||||
|
||||
const { result: orderPreview } = await removeClaimShippingMethodWorkflow(
|
||||
req.scope
|
||||
).run({
|
||||
input: {
|
||||
claim_id: id,
|
||||
action_id,
|
||||
},
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "claim",
|
||||
variables: {
|
||||
id,
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
const [orderClaim] = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
order_preview: orderPreview,
|
||||
claim: orderClaim,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { createClaimShippingMethodWorkflow } from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../../types/routing"
|
||||
import { AdminPostClaimsShippingReqSchemaType } from "../../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostClaimsShippingReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const { result } = await createClaimShippingMethodWorkflow(req.scope).run({
|
||||
input: { ...req.validatedBody, claim_id: id },
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "claim",
|
||||
variables: {
|
||||
id,
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const [orderClaim] = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
order_preview: result,
|
||||
claim: orderClaim,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
import { MiddlewareRoute } from "../../../loaders/helpers/routing/types"
|
||||
import { validateAndTransformBody } from "../../utils/validate-body"
|
||||
import { validateAndTransformQuery } from "../../utils/validate-query"
|
||||
import * as QueryConfig from "./query-config"
|
||||
import {
|
||||
AdminGetOrdersOrderParams,
|
||||
AdminGetOrdersParams,
|
||||
AdminPostClaimsAddItemsReqSchema,
|
||||
AdminPostClaimsConfirmRequestReqSchema,
|
||||
AdminPostClaimsRequestItemsActionReqSchema,
|
||||
AdminPostClaimsRequestReturnItemsReqSchema,
|
||||
AdminPostClaimsShippingActionReqSchema,
|
||||
AdminPostClaimsShippingReqSchema,
|
||||
AdminPostOrderClaimsReqSchema,
|
||||
} from "./validators"
|
||||
|
||||
export const adminClaimRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
{
|
||||
method: ["GET"],
|
||||
matcher: "/admin/claims",
|
||||
middlewares: [
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersParams,
|
||||
QueryConfig.listTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["GET"],
|
||||
matcher: "/admin/claims/:id",
|
||||
middlewares: [
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/claims",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminPostOrderClaimsReqSchema),
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/claims/:id/claim-items",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminPostClaimsRequestReturnItemsReqSchema),
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/claims/:id/claim-items/:action_id",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminPostClaimsRequestItemsActionReqSchema),
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["DELETE"],
|
||||
matcher: "/admin/claims/:id/claim-items/:action_id",
|
||||
middlewares: [
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/claims/:id/inbound/items",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminPostClaimsRequestReturnItemsReqSchema),
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/claims/:id/inbound/items/:action_id",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminPostClaimsRequestItemsActionReqSchema),
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["DELETE"],
|
||||
matcher: "/admin/claims/:id/inbound/items/:action_id",
|
||||
middlewares: [
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/claims/:id/inbound/shipping-method",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminPostClaimsShippingReqSchema),
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/claims/:id/inbound/shipping-method/:action_id",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminPostClaimsShippingActionReqSchema),
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["DELETE"],
|
||||
matcher: "/admin/claims/:id/inbound/shipping-method/:action_id",
|
||||
middlewares: [
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/claims/:id/outbound/items",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminPostClaimsAddItemsReqSchema),
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/claims/:id/outbound/items/:action_id",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminPostClaimsRequestItemsActionReqSchema),
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["DELETE"],
|
||||
matcher: "/admin/claims/:id/outbound/items/:action_id",
|
||||
middlewares: [
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/claims/:id/outbound/shipping-method",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminPostClaimsShippingReqSchema),
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/claims/:id/outbound/shipping-method/:action_id",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminPostClaimsShippingActionReqSchema),
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["DELETE"],
|
||||
matcher: "/admin/claims/:id/outbound/shipping-method/:action_id",
|
||||
middlewares: [
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/claims/:id/request",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminPostClaimsConfirmRequestReqSchema),
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["DELETE"],
|
||||
matcher: "/admin/claims/:id/request",
|
||||
middlewares: [],
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,31 @@
|
||||
export const defaultAdminClaimFields = [
|
||||
"id",
|
||||
"type",
|
||||
"order_id",
|
||||
"exchange_id",
|
||||
"claim_id",
|
||||
"display_id",
|
||||
"location_id",
|
||||
"order_version",
|
||||
"status",
|
||||
"refund_amount",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
]
|
||||
|
||||
export const defaultAdminDetailsClaimFields = [
|
||||
...defaultAdminClaimFields,
|
||||
"items.*",
|
||||
"items.reason.*",
|
||||
]
|
||||
|
||||
export const retrieveTransformQueryConfig = {
|
||||
defaultFields: defaultAdminDetailsClaimFields,
|
||||
isList: false,
|
||||
}
|
||||
|
||||
export const listTransformQueryConfig = {
|
||||
defaults: defaultAdminClaimFields,
|
||||
defaultLimit: 20,
|
||||
isList: true,
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import { beginClaimOrderWorkflow } from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
ModuleRegistrationName,
|
||||
promiseAll,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../types/routing"
|
||||
import { AdminPostOrderClaimsReqSchemaType } from "./validators"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "claims",
|
||||
variables: {
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
...req.remoteQueryConfig.pagination,
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const { rows: claims, metadata } = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
claims,
|
||||
count: metadata.count,
|
||||
offset: metadata.skip,
|
||||
limit: metadata.take,
|
||||
})
|
||||
}
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostOrderClaimsReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const input = req.validatedBody as AdminPostOrderClaimsReqSchemaType
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
const orderModuleService = req.scope.resolve(ModuleRegistrationName.ORDER)
|
||||
|
||||
const workflow = beginClaimOrderWorkflow(req.scope)
|
||||
const { result } = await workflow.run({
|
||||
input,
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "claim",
|
||||
variables: {
|
||||
id: result.claim_id,
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const [order, orderClaim] = await promiseAll([
|
||||
orderModuleService.retrieveOrder(result.order_id),
|
||||
remoteQuery(queryObject),
|
||||
])
|
||||
|
||||
res.json({
|
||||
order,
|
||||
claim: orderClaim[0],
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
import { ClaimType } from "@medusajs/utils"
|
||||
import { z } from "zod"
|
||||
import {
|
||||
createFindParams,
|
||||
createOperatorMap,
|
||||
createSelectParams,
|
||||
} from "../../utils/validators"
|
||||
|
||||
export const AdminGetOrdersOrderParams = createSelectParams().merge(
|
||||
z.object({
|
||||
id: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
status: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
created_at: createOperatorMap().optional(),
|
||||
updated_at: createOperatorMap().optional(),
|
||||
deleted_at: createOperatorMap().optional(),
|
||||
})
|
||||
)
|
||||
|
||||
export type AdminGetOrdersOrderParamsType = z.infer<
|
||||
typeof AdminGetOrdersOrderParams
|
||||
>
|
||||
|
||||
/**
|
||||
* Parameters used to filter and configure the pagination of the retrieved order.
|
||||
*/
|
||||
export const AdminGetOrdersParams = createFindParams({
|
||||
limit: 15,
|
||||
offset: 0,
|
||||
}).merge(
|
||||
z.object({
|
||||
id: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
order_id: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
status: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
created_at: createOperatorMap().optional(),
|
||||
updated_at: createOperatorMap().optional(),
|
||||
deleted_at: createOperatorMap().optional(),
|
||||
})
|
||||
)
|
||||
|
||||
export type AdminGetOrdersParamsType = z.infer<typeof AdminGetOrdersParams>
|
||||
|
||||
export const AdminPostOrderClaimsReqSchema = z.object({
|
||||
type: z.nativeEnum(ClaimType),
|
||||
order_id: z.string(),
|
||||
description: z.string().optional(),
|
||||
internal_note: z.string().optional(),
|
||||
metadata: z.record(z.unknown()).nullish(),
|
||||
})
|
||||
export type AdminPostOrderClaimsReqSchemaType = z.infer<
|
||||
typeof AdminPostOrderClaimsReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostOrderExchangesReqSchema = z.object({
|
||||
order_id: z.string(),
|
||||
description: z.string().optional(),
|
||||
internal_note: z.string().optional(),
|
||||
metadata: z.record(z.unknown()).nullish(),
|
||||
})
|
||||
export type AdminPostOrderExchangesReqSchemaType = z.infer<
|
||||
typeof AdminPostOrderExchangesReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostReceiveClaimsReqSchema = z.object({
|
||||
internal_note: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
metadata: z.record(z.unknown()).nullish(),
|
||||
})
|
||||
export type AdminPostReceiveClaimsReqSchemaType = z.infer<
|
||||
typeof AdminPostReceiveClaimsReqSchema
|
||||
>
|
||||
|
||||
const ReceiveItemSchema = z.object({
|
||||
id: z.string(),
|
||||
quantity: z.number().min(1),
|
||||
internal_note: z.string().optional(),
|
||||
})
|
||||
export const AdminPostReceiveClaimItemsReqSchema = z.object({
|
||||
items: z.array(ReceiveItemSchema),
|
||||
})
|
||||
export type AdminPostReceiveClaimItemsReqSchemaType = z.infer<
|
||||
typeof AdminPostReceiveClaimItemsReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostCancelClaimReqSchema = z.object({
|
||||
return_id: z.string(),
|
||||
no_notification: z.boolean().optional(),
|
||||
internal_note: z.string().nullish(),
|
||||
})
|
||||
export type AdminPostCancelClaimReqSchemaType = z.infer<
|
||||
typeof AdminPostCancelClaimReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostClaimsShippingReqSchema = z.object({
|
||||
shipping_option_id: z.string(),
|
||||
custom_price: z.number().optional(),
|
||||
description: z.string().optional(),
|
||||
internal_note: z.string().optional(),
|
||||
metadata: z.record(z.unknown()).optional(),
|
||||
})
|
||||
|
||||
export type AdminPostClaimsShippingReqSchemaType = z.infer<
|
||||
typeof AdminPostClaimsShippingReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostClaimsShippingActionReqSchema = z.object({
|
||||
custom_price: z.number().optional(),
|
||||
internal_note: z.string().nullish().optional(),
|
||||
metadata: z.record(z.unknown()).nullish().optional(),
|
||||
})
|
||||
|
||||
export type AdminPostClaimsShippingActionReqSchemaType = z.infer<
|
||||
typeof AdminPostClaimsShippingActionReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostClaimsAddItemsReqSchema = z.object({
|
||||
items: z.array(
|
||||
z.object({
|
||||
variant_id: z.string(),
|
||||
quantity: z.number(),
|
||||
unit_price: z.number().optional(),
|
||||
internal_note: z.string().optional(),
|
||||
metadata: z.record(z.unknown()).optional(),
|
||||
})
|
||||
),
|
||||
})
|
||||
|
||||
export type AdminPostClaimsAddItemsReqSchemaType = z.infer<
|
||||
typeof AdminPostClaimsAddItemsReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostClaimsRequestReturnItemsReqSchema = z.object({
|
||||
items: z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
quantity: z.number(),
|
||||
description: z.string().optional(),
|
||||
internal_note: z.string().optional(),
|
||||
reason_id: z.string().optional(),
|
||||
metadata: z.record(z.unknown()).optional(),
|
||||
})
|
||||
),
|
||||
})
|
||||
|
||||
export type AdminPostClaimsRequestReturnItemsReqSchemaType = z.infer<
|
||||
typeof AdminPostClaimsRequestReturnItemsReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostClaimItemsReqSchema = z.object({
|
||||
items: z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
quantity: z.number(),
|
||||
description: z.string().optional(),
|
||||
internal_note: z.string().optional(),
|
||||
metadata: z.record(z.unknown()).optional(),
|
||||
})
|
||||
),
|
||||
})
|
||||
|
||||
export type AdminPostClaimItemsReqSchemaType = z.infer<
|
||||
typeof AdminPostClaimItemsReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostClaimsRequestItemsActionReqSchema = z.object({
|
||||
quantity: z.number().optional(),
|
||||
internal_note: z.string().nullish().optional(),
|
||||
reason_id: z.string().nullish().optional(),
|
||||
metadata: z.record(z.unknown()).nullish().optional(),
|
||||
})
|
||||
|
||||
export type AdminPostClaimsRequestItemsActionReqSchemaType = z.infer<
|
||||
typeof AdminPostClaimsRequestItemsActionReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostClaimsItemsActionReqSchema = z.object({
|
||||
quantity: z.number().optional(),
|
||||
internal_note: z.string().nullish().optional(),
|
||||
})
|
||||
|
||||
export type AdminPostClaimsItemsActionReqSchemaType = z.infer<
|
||||
typeof AdminPostClaimsItemsActionReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostClaimsDismissItemsActionReqSchema = z.object({
|
||||
quantity: z.number().optional(),
|
||||
internal_note: z.string().nullish().optional(),
|
||||
})
|
||||
|
||||
export type AdminPostClaimsDismissItemsActionReqSchemaType = z.infer<
|
||||
typeof AdminPostClaimsDismissItemsActionReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostClaimsConfirmRequestReqSchema = z.object({
|
||||
no_notification: z.boolean().optional(),
|
||||
})
|
||||
|
||||
export type AdminPostClaimsConfirmRequestReqSchemaType = z.infer<
|
||||
typeof AdminPostClaimsConfirmRequestReqSchema
|
||||
>
|
||||
@@ -1,4 +1,3 @@
|
||||
import { ClaimType } from "@medusajs/utils"
|
||||
import { z } from "zod"
|
||||
import {
|
||||
createFindParams,
|
||||
@@ -51,17 +50,6 @@ export type AdminPostReturnsReqSchemaType = z.infer<
|
||||
typeof AdminPostReturnsReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostOrderClaimsReqSchema = z.object({
|
||||
type: z.nativeEnum(ClaimType),
|
||||
order_id: z.string(),
|
||||
description: z.string().optional(),
|
||||
internal_note: z.string().optional(),
|
||||
metadata: z.record(z.unknown()).nullish(),
|
||||
})
|
||||
export type AdminPostOrderClaimsReqSchemaType = z.infer<
|
||||
typeof AdminPostOrderClaimsReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostOrderExchangesReqSchema = z.object({
|
||||
order_id: z.string(),
|
||||
description: z.string().optional(),
|
||||
|
||||
Reference in New Issue
Block a user