chore(medusa,types): [3] Add request types to API routes (#8560)
* chore(medusa,types): [3] Add request types to API routes * more types
This commit is contained in:
1 parent
e5e8489cc0
commit
578e5182dd
14 files changed
+49
-17
No files matched your search
+1
-4
@@ -1,14 +1,11 @@
|
|||||||
import {
|
import {
|
||||||
BaseOrder,
|
BaseOrder,
|
||||||
BaseOrderAddress,
|
BaseOrderAddress,
|
||||||
BaseOrderFilters,
|
|
||||||
BaseOrderLineItem,
|
BaseOrderLineItem,
|
||||||
BaseOrderShippingMethod,
|
BaseOrderShippingMethod,
|
||||||
} from "./common"
|
} from "../common"
|
||||||
|
|
||||||
export interface StoreOrder extends BaseOrder {}
|
export interface StoreOrder extends BaseOrder {}
|
||||||
export interface StoreOrderLineItem extends BaseOrderLineItem {}
|
export interface StoreOrderLineItem extends BaseOrderLineItem {}
|
||||||
export interface StoreOrderAddress extends BaseOrderAddress {}
|
export interface StoreOrderAddress extends BaseOrderAddress {}
|
||||||
export interface StoreOrderShippingMethod extends BaseOrderShippingMethod {}
|
export interface StoreOrderShippingMethod extends BaseOrderShippingMethod {}
|
||||||
|
|
||||||
export interface StoreOrderFilters extends BaseOrderFilters {}
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export * from "./entities"
|
||||||
|
export * from "./queries"
|
||||||
|
export * from "./responses"
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import { BaseOrderFilters } from "../common";
|
||||||
|
|
||||||
|
export interface StoreOrderFilters extends BaseOrderFilters {}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { PaginatedResponse } from "../../common";
|
||||||
|
import { StoreOrder } from "./entities";
|
||||||
|
|
||||||
|
export interface StoreOrderResponse {
|
||||||
|
order: StoreOrder
|
||||||
|
}
|
||||||
|
|
||||||
|
export type StoreOrderListResponse = PaginatedResponse<{ orders: StoreOrder[] }>
|
||||||
@@ -17,6 +17,7 @@ export type BasePaymentCollectionStatus =
|
|||||||
*/
|
*/
|
||||||
export type BasePaymentSessionStatus =
|
export type BasePaymentSessionStatus =
|
||||||
| "authorized"
|
| "authorized"
|
||||||
|
| "captured"
|
||||||
| "pending"
|
| "pending"
|
||||||
| "requires_more"
|
| "requires_more"
|
||||||
| "error"
|
| "error"
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import {
|
||||||
|
BasePaymentCollection,
|
||||||
|
BasePaymentProvider,
|
||||||
|
BasePaymentSession,
|
||||||
|
} from "../common"
|
||||||
|
|
||||||
|
export interface StorePaymentProvider extends BasePaymentProvider {}
|
||||||
|
export interface StorePaymentCollection extends BasePaymentCollection {}
|
||||||
|
export interface StorePaymentSession extends BasePaymentSession {}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export * from "./entities"
|
||||||
|
export * from "./queries"
|
||||||
|
export * from "./responses"
|
||||||
+1
-8
@@ -1,15 +1,8 @@
|
|||||||
import {
|
import {
|
||||||
BasePaymentCollection,
|
|
||||||
BasePaymentCollectionFilters,
|
BasePaymentCollectionFilters,
|
||||||
BasePaymentProvider,
|
|
||||||
BasePaymentProviderFilters,
|
BasePaymentProviderFilters,
|
||||||
BasePaymentSession,
|
|
||||||
BasePaymentSessionFilters,
|
BasePaymentSessionFilters,
|
||||||
} from "./common"
|
} from "../common"
|
||||||
|
|
||||||
export interface StorePaymentProvider extends BasePaymentProvider {}
|
|
||||||
export interface StorePaymentCollection extends BasePaymentCollection {}
|
|
||||||
export interface StorePaymentSession extends BasePaymentSession {}
|
|
||||||
|
|
||||||
export interface StorePaymentProviderFilters
|
export interface StorePaymentProviderFilters
|
||||||
extends BasePaymentProviderFilters {}
|
extends BasePaymentProviderFilters {}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { PaginatedResponse } from "../../common";
|
||||||
|
import { StorePaymentCollection, StorePaymentProvider } from "./entities";
|
||||||
|
|
||||||
|
export interface StorePaymentCollectionResponse {
|
||||||
|
payment_collection: StorePaymentCollection
|
||||||
|
}
|
||||||
|
|
||||||
|
export type StorePaymentProviderListResponse = PaginatedResponse<{
|
||||||
|
payment_providers: StorePaymentProvider[]
|
||||||
|
}>
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
|
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
|
||||||
import { refetchOrder } from "../helpers"
|
import { refetchOrder } from "../helpers"
|
||||||
import { StoreGetOrdersParamsType } from "../validators"
|
import { StoreGetOrdersParamsType } from "../validators"
|
||||||
@@ -5,7 +6,7 @@ import { StoreGetOrdersParamsType } from "../validators"
|
|||||||
// TODO: Do we want to apply some sort of authentication here? My suggestion is that we do
|
// TODO: Do we want to apply some sort of authentication here? My suggestion is that we do
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: MedusaRequest<StoreGetOrdersParamsType>,
|
req: MedusaRequest<StoreGetOrdersParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreOrderResponse>
|
||||||
) => {
|
) => {
|
||||||
const order = await refetchOrder(
|
const order = await refetchOrder(
|
||||||
req.params.id,
|
req.params.id,
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ import {
|
|||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
} from "../../../types/routing"
|
} from "../../../types/routing"
|
||||||
import { AdminGetOrdersParamsType } from "../../admin/draft-orders/validators"
|
import { AdminGetOrdersParamsType } from "../../admin/draft-orders/validators"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminGetOrdersParamsType>,
|
req: AuthenticatedMedusaRequest<AdminGetOrdersParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreOrderListResponse>
|
||||||
) => {
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ import {
|
|||||||
} from "../../../../../types/routing"
|
} from "../../../../../types/routing"
|
||||||
import { StoreCreatePaymentSessionType } from "../../validators"
|
import { StoreCreatePaymentSessionType } from "../../validators"
|
||||||
import { refetchPaymentCollection } from "../../helpers"
|
import { refetchPaymentCollection } from "../../helpers"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<StoreCreatePaymentSessionType>,
|
req: AuthenticatedMedusaRequest<StoreCreatePaymentSessionType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StorePaymentCollectionResponse>
|
||||||
) => {
|
) => {
|
||||||
const collectionId = req.params.id
|
const collectionId = req.params.id
|
||||||
const { context = {}, data, provider_id } = req.body
|
const { context = {}, data, provider_id } = req.body
|
||||||
|
|||||||
@@ -8,10 +8,11 @@ import {
|
|||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
} from "../../../types/routing"
|
} from "../../../types/routing"
|
||||||
import { StoreCreatePaymentCollectionType } from "./validators"
|
import { StoreCreatePaymentCollectionType } from "./validators"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<StoreCreatePaymentCollectionType>,
|
req: AuthenticatedMedusaRequest<StoreCreatePaymentCollectionType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StorePaymentCollectionResponse>
|
||||||
) => {
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
const { cart_id } = req.body
|
const { cart_id } = req.body
|
||||||
|
|||||||
@@ -8,11 +8,12 @@ import {
|
|||||||
remoteQueryObjectFromString,
|
remoteQueryObjectFromString,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { StoreGetPaymentProvidersParamsType } from "./validators"
|
import { StoreGetPaymentProvidersParamsType } from "./validators"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
// TODO: Add more fields to provider, such as default name and maybe logo.
|
// TODO: Add more fields to provider, such as default name and maybe logo.
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<StoreGetPaymentProvidersParamsType>,
|
req: AuthenticatedMedusaRequest<StoreGetPaymentProvidersParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StorePaymentProviderListResponse>
|
||||||
) => {
|
) => {
|
||||||
if (!req.filterableFields.region_id) {
|
if (!req.filterableFields.region_id) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
|
|||||||
Reference in new issue
Block a user