chore(medusa,types): [4] Add request types to API routes (#8561)
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
export interface AdminFulfillmentProvider {
|
||||
id: string
|
||||
is_enabled: boolean
|
||||
}
|
||||
import { BaseFulfillmentProvider } from "../common";
|
||||
|
||||
export interface AdminFulfillmentProvider extends BaseFulfillmentProvider {}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export interface BaseFulfillmentProvider {
|
||||
id: string
|
||||
is_enabled: boolean
|
||||
}
|
||||
7
packages/core/types/src/http/region/store/entities.ts
Normal file
7
packages/core/types/src/http/region/store/entities.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import {
|
||||
BaseRegion,
|
||||
BaseRegionCountry,
|
||||
} from "../common"
|
||||
|
||||
export interface StoreRegion extends BaseRegion {}
|
||||
export interface StoreRegionCountry extends BaseRegionCountry {}
|
||||
3
packages/core/types/src/http/region/store/index.ts
Normal file
3
packages/core/types/src/http/region/store/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./entities"
|
||||
export * from "./queries"
|
||||
export * from "./responses"
|
||||
@@ -1,11 +1,7 @@
|
||||
import {
|
||||
BaseRegion,
|
||||
BaseRegionCountry,
|
||||
BaseRegionCountryFilters,
|
||||
BaseRegionFilters,
|
||||
} from "./common"
|
||||
} from "../common"
|
||||
|
||||
export interface StoreRegion extends BaseRegion {}
|
||||
export interface StoreRegionCountry extends BaseRegionCountry {}
|
||||
export interface StoreRegionFilters extends BaseRegionFilters {}
|
||||
export interface StoreRegionCountryFilters extends BaseRegionCountryFilters {}
|
||||
8
packages/core/types/src/http/region/store/responses.ts
Normal file
8
packages/core/types/src/http/region/store/responses.ts
Normal file
@@ -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 "./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[]
|
||||
}>
|
||||
24
packages/core/types/src/http/return/common.ts
Normal file
24
packages/core/types/src/http/return/common.ts
Normal file
@@ -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 "./store"
|
||||
3
packages/core/types/src/http/return/store/entities.ts
Normal file
3
packages/core/types/src/http/return/store/entities.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { BaseReturn } from "../common";
|
||||
|
||||
export interface StoreReturn extends BaseReturn {}
|
||||
2
packages/core/types/src/http/return/store/index.ts
Normal file
2
packages/core/types/src/http/return/store/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./entities"
|
||||
export * from "./responses"
|
||||
5
packages/core/types/src/http/return/store/responses.ts
Normal file
5
packages/core/types/src/http/return/store/responses.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { StoreReturn } from "./entities";
|
||||
|
||||
export interface StoreReturnResponse {
|
||||
return: StoreReturn
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
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,
|
||||
} from "../helpers"
|
||||
import { StoreGetProductParamsType } from "../validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
req: RequestWithContext<StoreGetProductParamsType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.StoreProductResponse>
|
||||
) => {
|
||||
const withInventoryQuantity = req.remoteQueryConfig.fields.some((field) =>
|
||||
field.includes("variants.inventory_quantity")
|
||||
|
||||
@@ -7,10 +7,11 @@ import { MedusaResponse } from "../../../types/routing"
|
||||
import { wrapVariantsWithInventoryQuantity } from "../../utils/middlewares"
|
||||
import { StoreGetProductsParamsType } from "./validators"
|
||||
import { RequestWithContext, wrapProductsWithTaxPrices } from "./helpers"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
req: RequestWithContext<StoreGetProductsParamsType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.StoreProductListResponse>
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
const context: object = {}
|
||||
|
||||
@@ -4,8 +4,12 @@ import {
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
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 queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "region",
|
||||
|
||||
@@ -3,8 +3,12 @@ import {
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
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 queryObject = remoteQueryObjectFromString({
|
||||
|
||||
@@ -4,10 +4,11 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
|
||||
import { StoreReturnReasonParamsType } from "../validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
req: MedusaRequest<StoreReturnReasonParamsType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.StoreReturnReasonResponse>
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
|
||||
@@ -3,8 +3,12 @@ import {
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
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 queryObject = remoteQueryObjectFromString({
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { createAndCompleteReturnOrderWorkflow } from "@medusajs/core-flows"
|
||||
import { MedusaRequest, MedusaResponse } from "../../../types/routing"
|
||||
import { StorePostReturnsReqSchemaType } from "./validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: MedusaRequest<StorePostReturnsReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.StoreReturnResponse>
|
||||
) => {
|
||||
const input = req.validatedBody as StorePostReturnsReqSchemaType
|
||||
|
||||
@@ -13,5 +14,5 @@ export const POST = async (
|
||||
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 { ICartModuleService } from "@medusajs/types"
|
||||
import { HttpTypes, ICartModuleService } from "@medusajs/types"
|
||||
import { MedusaError, ModuleRegistrationName } from "@medusajs/utils"
|
||||
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 }
|
||||
if (!cart_id) {
|
||||
throw new MedusaError(
|
||||
|
||||
Reference in New Issue
Block a user