feat(medusa): order changes endpoint (#8728)
What: - `admin/orders/:id/changes` endpoint to get order changes related to the order - added `*_by` attributes missing
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { cancelOrderClaimWorkflow } from "@medusajs/core-flows"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { AdminPostCancelClaimReqSchemaType } from "../../validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostCancelClaimReqSchemaType>,
|
||||
@@ -17,6 +17,7 @@ export const POST = async (
|
||||
input: {
|
||||
...req.validatedBody,
|
||||
claim_id: id,
|
||||
canceled_by: req.auth_context.actor_id,
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
cancelBeginOrderClaimWorkflow,
|
||||
confirmClaimRequestWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
@@ -11,7 +12,6 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { defaultAdminDetailsReturnFields } from "../../../returns/query-config"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
@@ -22,7 +22,10 @@ export const POST = async (
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const { result } = await confirmClaimRequestWorkflow(req.scope).run({
|
||||
input: { claim_id: id },
|
||||
input: {
|
||||
claim_id: id,
|
||||
confirmed_by: req.auth_context.actor_id,
|
||||
},
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { cancelOrderExchangeWorkflow } from "@medusajs/core-flows"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { AdminPostCancelExchangeReqSchemaType } from "../../validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostCancelExchangeReqSchemaType>,
|
||||
@@ -17,6 +17,7 @@ export const POST = async (
|
||||
input: {
|
||||
...req.validatedBody,
|
||||
exchange_id: id,
|
||||
canceled_by: req.auth_context.actor_id,
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
cancelBeginOrderExchangeWorkflow,
|
||||
confirmExchangeRequestWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { DeleteResponse, HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
@@ -11,7 +12,6 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { defaultAdminDetailsReturnFields } from "../../../returns/query-config"
|
||||
import { DeleteResponse, HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
@@ -22,7 +22,10 @@ export const POST = async (
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const { result } = await confirmExchangeRequestWorkflow(req.scope).run({
|
||||
input: { exchange_id: id },
|
||||
input: {
|
||||
exchange_id: id,
|
||||
confirmed_by: req.auth_context.actor_id,
|
||||
},
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
|
||||
@@ -12,7 +12,10 @@ export const POST = async (
|
||||
const { id } = req.params
|
||||
|
||||
const { result } = await confirmOrderEditRequestWorkflow(req.scope).run({
|
||||
input: { order_id: id },
|
||||
input: {
|
||||
order_id: id,
|
||||
confirmed_by: req.auth_context.actor_id,
|
||||
},
|
||||
})
|
||||
|
||||
res.json({
|
||||
|
||||
@@ -12,7 +12,10 @@ export const POST = async (
|
||||
const { id } = req.params
|
||||
|
||||
const { result } = await requestOrderEditRequestWorkflow(req.scope).run({
|
||||
input: { order_id: id },
|
||||
input: {
|
||||
order_id: id,
|
||||
requested_by: req.auth_context.actor_id,
|
||||
},
|
||||
})
|
||||
|
||||
res.json({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { cancelOrderWorkflow } from "@medusajs/core-flows"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
@@ -7,7 +8,6 @@ import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
@@ -19,6 +19,7 @@ export const POST = async (
|
||||
|
||||
const input = {
|
||||
order_id: req.params.id,
|
||||
canceled_by: req.auth_context.actor_id,
|
||||
}
|
||||
|
||||
await cancelOrderWorkflow(req.scope).run({
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse<HttpTypes.AdminOrderChangesResponse>
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "order_change",
|
||||
variables: {
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
order_id: id,
|
||||
},
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const order_changes = await remoteQuery(queryObject)
|
||||
|
||||
res.status(200).json({ order_changes })
|
||||
}
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
import { cancelOrderFulfillmentWorkflow } from "@medusajs/core-flows"
|
||||
import { AdditionalData, HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
@@ -8,7 +9,6 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../../../types/routing"
|
||||
import { AdminOrderCancelFulfillmentType } from "../../../../validators"
|
||||
import { AdditionalData, HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<
|
||||
@@ -24,6 +24,7 @@ export const POST = async (
|
||||
...req.validatedBody,
|
||||
order_id: req.params.id,
|
||||
fulfillment_id: req.params.fulfillment_id,
|
||||
canceled_by: req.auth_context.actor_id,
|
||||
}
|
||||
|
||||
await cancelOrderFulfillmentWorkflow(req.scope).run({
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
AdminGetOrdersOrderParams,
|
||||
AdminGetOrdersParams,
|
||||
AdminOrderCancelFulfillment,
|
||||
AdminOrderChanges,
|
||||
AdminOrderCreateFulfillment,
|
||||
AdminOrderCreateShipment,
|
||||
} from "./validators"
|
||||
@@ -33,6 +34,16 @@ export const adminOrderRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["GET"],
|
||||
matcher: "/admin/orders/:id/changes",
|
||||
middlewares: [
|
||||
validateAndTransformQuery(
|
||||
AdminOrderChanges,
|
||||
QueryConfig.retrieveOrderChangesTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["GET"],
|
||||
matcher: "/admin/orders/:id/preview",
|
||||
|
||||
@@ -53,6 +53,33 @@ export const defaultAdminRetrieveOrderFields = [
|
||||
"*payment_collections.payments.refunds",
|
||||
]
|
||||
|
||||
export const defaultAdminRetrieveOrderChangesFields = [
|
||||
"id",
|
||||
"order_id",
|
||||
"return_id",
|
||||
"claim_id",
|
||||
"exchange_id",
|
||||
"version",
|
||||
"change_type",
|
||||
"*actions",
|
||||
"description",
|
||||
"status",
|
||||
"internal_note",
|
||||
"created_by",
|
||||
"requested_by",
|
||||
"requested_at",
|
||||
"confirmed_by",
|
||||
"confirmed_at",
|
||||
"declined_by",
|
||||
"declined_reason",
|
||||
"metadata",
|
||||
"declined_at",
|
||||
"canceled_by",
|
||||
"canceled_at",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
]
|
||||
|
||||
export const retrieveTransformQueryConfig = {
|
||||
defaultFields: defaultAdminRetrieveOrderFields,
|
||||
isList: false,
|
||||
@@ -63,3 +90,8 @@ export const listTransformQueryConfig = {
|
||||
defaultLimit: 20,
|
||||
isList: true,
|
||||
}
|
||||
|
||||
export const retrieveOrderChangesTransformQueryConfig = {
|
||||
defaultFields: defaultAdminRetrieveOrderChangesFields,
|
||||
isList: false,
|
||||
}
|
||||
|
||||
@@ -91,3 +91,13 @@ export const OrderCancelFulfillment = z.object({
|
||||
export const AdminOrderCancelFulfillment = WithAdditionalData(
|
||||
OrderCancelFulfillment
|
||||
)
|
||||
|
||||
export const AdminOrderChanges = z.object({
|
||||
id: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
status: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
change_type: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
created_at: createOperatorMap().optional(),
|
||||
updated_at: createOperatorMap().optional(),
|
||||
deleted_at: createOperatorMap().optional(),
|
||||
})
|
||||
export type AdminOrderChangesType = z.infer<typeof AdminOrderChanges>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { confirmReturnReceiveWorkflow } from "@medusajs/core-flows"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
@@ -8,7 +9,6 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../../types/routing"
|
||||
import { AdminPostReturnsConfirmRequestReqSchemaType } from "../../../validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostReturnsConfirmRequestReqSchemaType>,
|
||||
@@ -19,7 +19,10 @@ export const POST = async (
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const { result } = await confirmReturnReceiveWorkflow(req.scope).run({
|
||||
input: { return_id: id },
|
||||
input: {
|
||||
return_id: id,
|
||||
confirmed_by: req.auth_context.actor_id,
|
||||
},
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
cancelReturnRequestWorkflow,
|
||||
confirmReturnRequestWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { DeleteResponse, HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
@@ -11,7 +12,6 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { AdminPostReturnsConfirmRequestReqSchemaType } from "../../validators"
|
||||
import { DeleteResponse, HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostReturnsConfirmRequestReqSchemaType>,
|
||||
@@ -22,7 +22,10 @@ export const POST = async (
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const { result } = await confirmReturnRequestWorkflow(req.scope).run({
|
||||
input: { return_id: id },
|
||||
input: {
|
||||
return_id: id,
|
||||
confirmed_by: req.auth_context.actor_id,
|
||||
},
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
|
||||
Reference in New Issue
Block a user