chore(medusa,types): [4] Add request types to API routes (#8561)
This commit is contained in:
1 parent
578e5182dd
commit
078c2df773
27 files changed
+143
-19
No files matched your search
@@ -1,4 +1,3 @@
|
|||||||
export interface AdminFulfillmentProvider {
|
import { BaseFulfillmentProvider } from "../common";
|
||||||
id: string
|
|
||||||
is_enabled: boolean
|
export interface AdminFulfillmentProvider extends BaseFulfillmentProvider {}
|
||||||
}
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export interface BaseFulfillmentProvider {
|
||||||
|
id: string
|
||||||
|
is_enabled: boolean
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import {
|
||||||
|
BaseRegion,
|
||||||
|
BaseRegionCountry,
|
||||||
|
} from "../common"
|
||||||
|
|
||||||
|
export interface StoreRegion extends BaseRegion {}
|
||||||
|
export interface StoreRegionCountry extends BaseRegionCountry {}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export * from "./entities"
|
||||||
|
export * from "./queries"
|
||||||
|
export * from "./responses"
|
||||||
+1
-5
@@ -1,11 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
BaseRegion,
|
|
||||||
BaseRegionCountry,
|
|
||||||
BaseRegionCountryFilters,
|
BaseRegionCountryFilters,
|
||||||
BaseRegionFilters,
|
BaseRegionFilters,
|
||||||
} from "./common"
|
} from "../common"
|
||||||
|
|
||||||
export interface StoreRegion extends BaseRegion {}
|
|
||||||
export interface StoreRegionCountry extends BaseRegionCountry {}
|
|
||||||
export interface StoreRegionFilters extends BaseRegionFilters {}
|
export interface StoreRegionFilters extends BaseRegionFilters {}
|
||||||
export interface StoreRegionCountryFilters extends BaseRegionCountryFilters {}
|
export interface StoreRegionCountryFilters extends BaseRegionCountryFilters {}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { PaginatedResponse } from "../../common";
|
||||||
|
import { StoreRegion } from "./entities";
|
||||||
|
|
||||||
|
export type StoreRegionResponse = {
|
||||||
|
region: StoreRegion
|
||||||
|
}
|
||||||
|
|
||||||
|
export type StoreRegionListResponse = PaginatedResponse<{ regions: StoreRegion[] }>
|
||||||
@@ -1 +1,2 @@
|
|||||||
export * from "./admin"
|
export * from "./admin"
|
||||||
|
export * from "./store"
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import { BaseReturnReason } from "../common";
|
||||||
|
|
||||||
|
export interface StoreReturnReason extends BaseReturnReason {}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from "./entities"
|
||||||
|
export * from "./responses"
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { PaginatedResponse } from "../../common";
|
||||||
|
import { StoreReturnReason } from "./entities";
|
||||||
|
|
||||||
|
export interface StoreReturnReasonResponse {
|
||||||
|
return_reason: StoreReturnReason
|
||||||
|
}
|
||||||
|
|
||||||
|
export type StoreReturnReasonListResponse = PaginatedResponse<{
|
||||||
|
return_reasons: StoreReturnReason[]
|
||||||
|
}>
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
export interface BaseReturnItem {
|
||||||
|
id: string
|
||||||
|
quantity: number
|
||||||
|
received_quantity: number
|
||||||
|
reason_id?: string
|
||||||
|
note?: string
|
||||||
|
item_id: string
|
||||||
|
return_id: string
|
||||||
|
metadata?: Record<string, unknown>
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BaseReturn {
|
||||||
|
id: string
|
||||||
|
order_id: string
|
||||||
|
status?: string
|
||||||
|
exchange_id?: string
|
||||||
|
location_id?: string
|
||||||
|
claim_id?: string
|
||||||
|
order_version: number
|
||||||
|
display_id: number
|
||||||
|
no_notification?: boolean
|
||||||
|
refund_amount?: number
|
||||||
|
items: BaseReturnItem[]
|
||||||
|
}
|
||||||
@@ -1 +1,2 @@
|
|||||||
export * from "./admin"
|
export * from "./admin"
|
||||||
|
export * from "./store"
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import { BaseReturn } from "../common";
|
||||||
|
|
||||||
|
export interface StoreReturn extends BaseReturn {}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from "./entities"
|
||||||
|
export * from "./responses"
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { StoreReturn } from "./entities";
|
||||||
|
|
||||||
|
export interface StoreReturnResponse {
|
||||||
|
return: StoreReturn
|
||||||
|
}
|
||||||
@@ -1 +1,2 @@
|
|||||||
export * from "./admin"
|
export * from "./admin"
|
||||||
|
export * from "./store"
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { ShippingOptionPriceType } from "../../../fulfillment"
|
||||||
|
import { BaseFulfillmentProvider } from "../../fulfillment-provider/common"
|
||||||
|
|
||||||
|
export interface StoreShippingOptionType {
|
||||||
|
id: string
|
||||||
|
label: string
|
||||||
|
description: string
|
||||||
|
code: string
|
||||||
|
shipping_option_id: string
|
||||||
|
created_at: string
|
||||||
|
updated_at: string
|
||||||
|
deleted_at: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StoreShippingOption {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
price_type: ShippingOptionPriceType
|
||||||
|
service_zone_id: string
|
||||||
|
provider_id: string
|
||||||
|
provider: BaseFulfillmentProvider
|
||||||
|
shipping_option_type_id: string | null
|
||||||
|
type: StoreShippingOptionType
|
||||||
|
shipping_profile_id: string
|
||||||
|
amount: number
|
||||||
|
is_tax_inclusive: boolean
|
||||||
|
data: Record<string, unknown> | null
|
||||||
|
metadata: Record<string, unknown> | null
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from "./entities"
|
||||||
|
export * from "./responses"
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { StoreShippingOption } from ".";
|
||||||
|
|
||||||
|
export interface StoreShippingOptionListResponse {
|
||||||
|
shipping_options: StoreShippingOption[]
|
||||||
|
}
|
||||||
@@ -7,10 +7,11 @@ import {
|
|||||||
wrapProductsWithTaxPrices,
|
wrapProductsWithTaxPrices,
|
||||||
} from "../helpers"
|
} from "../helpers"
|
||||||
import { StoreGetProductParamsType } from "../validators"
|
import { StoreGetProductParamsType } from "../validators"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: RequestWithContext<StoreGetProductParamsType>,
|
req: RequestWithContext<StoreGetProductParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreProductResponse>
|
||||||
) => {
|
) => {
|
||||||
const withInventoryQuantity = req.remoteQueryConfig.fields.some((field) =>
|
const withInventoryQuantity = req.remoteQueryConfig.fields.some((field) =>
|
||||||
field.includes("variants.inventory_quantity")
|
field.includes("variants.inventory_quantity")
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ import { MedusaResponse } from "../../../types/routing"
|
|||||||
import { wrapVariantsWithInventoryQuantity } from "../../utils/middlewares"
|
import { wrapVariantsWithInventoryQuantity } from "../../utils/middlewares"
|
||||||
import { StoreGetProductsParamsType } from "./validators"
|
import { StoreGetProductsParamsType } from "./validators"
|
||||||
import { RequestWithContext, wrapProductsWithTaxPrices } from "./helpers"
|
import { RequestWithContext, wrapProductsWithTaxPrices } from "./helpers"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: RequestWithContext<StoreGetProductsParamsType>,
|
req: RequestWithContext<StoreGetProductsParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreProductListResponse>
|
||||||
) => {
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
const context: object = {}
|
const context: object = {}
|
||||||
|
|||||||
@@ -4,8 +4,12 @@ import {
|
|||||||
remoteQueryObjectFromString,
|
remoteQueryObjectFromString,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
|
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
export const GET = async (
|
||||||
|
req: MedusaRequest,
|
||||||
|
res: MedusaResponse<HttpTypes.StoreRegionResponse>
|
||||||
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
const queryObject = remoteQueryObjectFromString({
|
const queryObject = remoteQueryObjectFromString({
|
||||||
entryPoint: "region",
|
entryPoint: "region",
|
||||||
|
|||||||
@@ -3,8 +3,12 @@ import {
|
|||||||
remoteQueryObjectFromString,
|
remoteQueryObjectFromString,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { MedusaRequest, MedusaResponse } from "../../../types/routing"
|
import { MedusaRequest, MedusaResponse } from "../../../types/routing"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
export const GET = async (
|
||||||
|
req: MedusaRequest,
|
||||||
|
res: MedusaResponse<HttpTypes.StoreRegionListResponse>
|
||||||
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
|
|
||||||
const queryObject = remoteQueryObjectFromString({
|
const queryObject = remoteQueryObjectFromString({
|
||||||
|
|||||||
@@ -4,10 +4,11 @@ import {
|
|||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
|
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
|
||||||
import { StoreReturnReasonParamsType } from "../validators"
|
import { StoreReturnReasonParamsType } from "../validators"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: MedusaRequest<StoreReturnReasonParamsType>,
|
req: MedusaRequest<StoreReturnReasonParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreReturnReasonResponse>
|
||||||
) => {
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,12 @@ import {
|
|||||||
remoteQueryObjectFromString,
|
remoteQueryObjectFromString,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { MedusaRequest, MedusaResponse } from "../../../types/routing"
|
import { MedusaRequest, MedusaResponse } from "../../../types/routing"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
export const GET = async (
|
||||||
|
req: MedusaRequest,
|
||||||
|
res: MedusaResponse<HttpTypes.StoreReturnReasonListResponse>
|
||||||
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
|
|
||||||
const queryObject = remoteQueryObjectFromString({
|
const queryObject = remoteQueryObjectFromString({
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { createAndCompleteReturnOrderWorkflow } from "@medusajs/core-flows"
|
import { createAndCompleteReturnOrderWorkflow } from "@medusajs/core-flows"
|
||||||
import { MedusaRequest, MedusaResponse } from "../../../types/routing"
|
import { MedusaRequest, MedusaResponse } from "../../../types/routing"
|
||||||
import { StorePostReturnsReqSchemaType } from "./validators"
|
import { StorePostReturnsReqSchemaType } from "./validators"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: MedusaRequest<StorePostReturnsReqSchemaType>,
|
req: MedusaRequest<StorePostReturnsReqSchemaType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreReturnResponse>
|
||||||
) => {
|
) => {
|
||||||
const input = req.validatedBody as StorePostReturnsReqSchemaType
|
const input = req.validatedBody as StorePostReturnsReqSchemaType
|
||||||
|
|
||||||
@@ -13,5 +14,5 @@ export const POST = async (
|
|||||||
input,
|
input,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(200).json({ return: result })
|
res.status(200).json({ return: result as HttpTypes.StoreReturn })
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
import { listShippingOptionsForCartWorkflow } from "@medusajs/core-flows"
|
import { listShippingOptionsForCartWorkflow } from "@medusajs/core-flows"
|
||||||
import { ICartModuleService } from "@medusajs/types"
|
import { HttpTypes, ICartModuleService } from "@medusajs/types"
|
||||||
import { MedusaError, ModuleRegistrationName } from "@medusajs/utils"
|
import { MedusaError, ModuleRegistrationName } from "@medusajs/utils"
|
||||||
import { MedusaRequest, MedusaResponse } from "../../../types/routing"
|
import { MedusaRequest, MedusaResponse } from "../../../types/routing"
|
||||||
|
|
||||||
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
export const GET = async (
|
||||||
|
req: MedusaRequest,
|
||||||
|
res: MedusaResponse<HttpTypes.StoreShippingOptionListResponse>
|
||||||
|
) => {
|
||||||
const { cart_id } = req.filterableFields as { cart_id: string }
|
const { cart_id } = req.filterableFields as { cart_id: string }
|
||||||
if (!cart_id) {
|
if (!cart_id) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
|
|||||||
Reference in new issue
Block a user