chore(medusa,types): [7] Add request types to API routes (#8564)
Add request types as type arguments in API routes. This also includes adding / rearranging types under the `types` package. PR 7/n
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
import { BaseExchange } from "../common";
|
||||
|
||||
export interface AdminExchange extends BaseExchange {}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./entities"
|
||||
export * from "./responses"
|
||||
@@ -0,0 +1,31 @@
|
||||
import { OrderDTO } from "../../../order";
|
||||
import { PaginatedResponse } from "../../common";
|
||||
import { AdminReturn } from "../../return";
|
||||
import { AdminExchange } from "./entities";
|
||||
|
||||
export interface AdminExchangeResponse {
|
||||
exchange: AdminExchange
|
||||
}
|
||||
|
||||
export type AdminExchangeListResponse = PaginatedResponse<{
|
||||
exchanges: AdminExchange
|
||||
}>
|
||||
|
||||
export interface AdminExchangeOrderResponse {
|
||||
order: OrderDTO
|
||||
exchange: AdminExchange
|
||||
}
|
||||
|
||||
export interface AdminExchangePreviewResponse {
|
||||
order_preview: OrderDTO
|
||||
exchange: AdminExchange
|
||||
}
|
||||
|
||||
export interface AdminExchangeRequestResponse extends AdminExchangePreviewResponse {
|
||||
return: AdminReturn
|
||||
}
|
||||
|
||||
export interface AdminExchangeReturnResponse {
|
||||
order_preview: OrderDTO
|
||||
return: AdminReturn
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { BaseOrder } from "../order/common";
|
||||
import { AdminBaseReturnItem, AdminReturn } from "../return";
|
||||
|
||||
export interface BaseExchangeItem {
|
||||
id: string
|
||||
exchange_id: string
|
||||
order_id: string
|
||||
item_id: string
|
||||
quantity: number
|
||||
metadata?: Record<string, unknown>
|
||||
created_at: string | null
|
||||
updated_at: string | null
|
||||
}
|
||||
|
||||
export interface BaseExchange extends Omit<BaseOrder, "status" | "version" | "items"> {
|
||||
order_id: string
|
||||
return_items: AdminBaseReturnItem[]
|
||||
additional_items: BaseExchangeItem[]
|
||||
no_notification?: boolean
|
||||
difference_due?: number
|
||||
return?: AdminReturn
|
||||
return_id?: string
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./admin"
|
||||
@@ -6,6 +6,7 @@ export * from "./collection"
|
||||
export * from "./common"
|
||||
export * from "./currency"
|
||||
export * from "./customer"
|
||||
export * from "./exchange"
|
||||
export * from "./file"
|
||||
export * from "./fulfillment"
|
||||
export * from "./fulfillment-provider"
|
||||
|
||||
@@ -11,4 +11,12 @@ export type AdminOrderListResponse = PaginatedResponse<{
|
||||
|
||||
export interface AdminOrderPreviewResponse {
|
||||
order: AdminOrderPreview
|
||||
}
|
||||
}
|
||||
|
||||
export interface AdminDraftOrderResponse {
|
||||
draft_order: AdminOrder
|
||||
}
|
||||
|
||||
export type AdminDraftOrderListResponse = PaginatedResponse<{
|
||||
draft_orders: AdminOrder
|
||||
}>
|
||||
@@ -2,8 +2,12 @@ import { MedusaError } from "@medusajs/utils"
|
||||
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
|
||||
import { refetchOrder } from "../helpers"
|
||||
import { defaultAdminOrderFields } from "../query-config"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
export const GET = async (
|
||||
req: MedusaRequest,
|
||||
res: MedusaResponse<HttpTypes.AdminDraftOrderResponse>
|
||||
) => {
|
||||
const draftOrder = await refetchOrder(
|
||||
req.params.id,
|
||||
req.scope,
|
||||
|
||||
@@ -11,9 +11,12 @@ import {
|
||||
} from "../../../types/routing"
|
||||
import { AdminCreateDraftOrderType } from "./validators"
|
||||
import { refetchOrder } from "./helpers"
|
||||
import { AdditionalData, CreateOrderDTO } from "@medusajs/types"
|
||||
import { AdditionalData, CreateOrderDTO, HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
export const GET = async (
|
||||
req: MedusaRequest,
|
||||
res: MedusaResponse<HttpTypes.AdminDraftOrderListResponse>
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
@@ -40,7 +43,7 @@ export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminCreateDraftOrderType & AdditionalData>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminDraftOrderResponse>
|
||||
) => {
|
||||
const input = req.validatedBody
|
||||
const workflowInput = {
|
||||
|
||||
@@ -4,10 +4,11 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { AdminPostCancelExchangeReqSchemaType } from "../../validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostCancelExchangeReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminExchangeResponse>
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
@@ -19,5 +20,5 @@ export const POST = async (
|
||||
},
|
||||
})
|
||||
|
||||
res.status(200).json({ exchange: result })
|
||||
res.status(200).json({ exchange: result as HttpTypes.AdminExchange })
|
||||
}
|
||||
|
||||
@@ -12,10 +12,11 @@ import {
|
||||
} from "../../../../../../../types/routing"
|
||||
import { defaultAdminDetailsReturnFields } from "../../../../../returns/query-config"
|
||||
import { AdminPostExchangesRequestItemsReturnActionReqSchemaType } from "../../../../validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostExchangesRequestItemsReturnActionReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminExchangeReturnResponse>
|
||||
) => {
|
||||
const { id, action_id } = req.params
|
||||
|
||||
@@ -62,7 +63,7 @@ export const POST = async (
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminExchangeReturnResponse>
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
|
||||
@@ -10,10 +10,11 @@ import {
|
||||
} from "../../../../../../types/routing"
|
||||
import { defaultAdminDetailsReturnFields } from "../../../../returns/query-config"
|
||||
import { AdminPostExchangesReturnRequestItemsReqSchemaType } from "../../../validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostExchangesReturnRequestItemsReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminExchangeReturnResponse>
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
|
||||
+3
-2
@@ -12,10 +12,11 @@ import {
|
||||
} from "../../../../../../../types/routing"
|
||||
import { defaultAdminDetailsReturnFields } from "../../../../../returns/query-config"
|
||||
import { AdminPostExchangesShippingActionReqSchemaType } from "../../../../validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostExchangesShippingActionReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminExchangePreviewResponse>
|
||||
) => {
|
||||
const { id, action_id } = req.params
|
||||
|
||||
@@ -64,7 +65,7 @@ export const POST = async (
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminExchangeReturnResponse>
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
|
||||
@@ -10,10 +10,11 @@ import {
|
||||
} from "../../../../../../types/routing"
|
||||
import { defaultAdminDetailsReturnFields } from "../../../../returns/query-config"
|
||||
import { AdminPostReturnsShippingReqSchemaType } from "../../../../returns/validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostReturnsShippingReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminExchangeReturnResponse>
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
|
||||
@@ -11,10 +11,11 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../../../types/routing"
|
||||
import { AdminPostExhangesItemsActionReqSchemaType } from "../../../../validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostExhangesItemsActionReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminExchangePreviewResponse>
|
||||
) => {
|
||||
const { id, action_id } = req.params
|
||||
|
||||
@@ -49,7 +50,7 @@ export const POST = async (
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminExchangePreviewResponse>
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
|
||||
@@ -9,10 +9,11 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../../types/routing"
|
||||
import { AdminPostExchangesAddItemsReqSchemaType } from "../../../validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostExchangesAddItemsReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminExchangePreviewResponse>
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
|
||||
+3
-2
@@ -11,10 +11,11 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../../../types/routing"
|
||||
import { AdminPostExchangesShippingActionReqSchemaType } from "../../../../validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostExchangesShippingActionReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminExchangePreviewResponse>
|
||||
) => {
|
||||
const { id, action_id } = req.params
|
||||
|
||||
@@ -49,7 +50,7 @@ export const POST = async (
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminExchangePreviewResponse>
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
|
||||
@@ -8,10 +8,11 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../../types/routing"
|
||||
import { AdminPostExchangesShippingReqSchemaType } from "../../../validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostExchangesShippingReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminExchangePreviewResponse>
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
|
||||
@@ -11,10 +11,11 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { defaultAdminDetailsReturnFields } from "../../../returns/query-config"
|
||||
import { DeleteResponse, HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminExchangeRequestResponse>
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
@@ -62,7 +63,7 @@ export const POST = async (
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<DeleteResponse<"exchange">>
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
|
||||
@@ -10,10 +10,11 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../types/routing"
|
||||
import { AdminPostOrderExchangesReqSchemaType } from "./validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminExchangeListResponse>
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
@@ -40,7 +41,7 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostOrderExchangesReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminExchangeOrderResponse>
|
||||
) => {
|
||||
const input = req.validatedBody as AdminPostOrderExchangesReqSchemaType
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
Reference in New Issue
Block a user