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:
Shahed Nasser
2024-08-13 09:36:56 +03:00
committed by GitHub
parent e5e8489cc0
commit 578e5182dd
14 changed files with 49 additions and 17 deletions
@@ -1,14 +1,11 @@
import {
BaseOrder,
BaseOrderAddress,
BaseOrderFilters,
BaseOrderLineItem,
BaseOrderShippingMethod,
} from "./common"
} from "../common"
export interface StoreOrder extends BaseOrder {}
export interface StoreOrderLineItem extends BaseOrderLineItem {}
export interface StoreOrderAddress extends BaseOrderAddress {}
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 =
| "authorized"
| "captured"
| "pending"
| "requires_more"
| "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,15 +1,8 @@
import {
BasePaymentCollection,
BasePaymentCollectionFilters,
BasePaymentProvider,
BasePaymentProviderFilters,
BasePaymentSession,
BasePaymentSessionFilters,
} from "./common"
export interface StorePaymentProvider extends BasePaymentProvider {}
export interface StorePaymentCollection extends BasePaymentCollection {}
export interface StorePaymentSession extends BasePaymentSession {}
} from "../common"
export interface StorePaymentProviderFilters
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 { refetchOrder } from "../helpers"
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
export const GET = async (
req: MedusaRequest<StoreGetOrdersParamsType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.StoreOrderResponse>
) => {
const order = await refetchOrder(
req.params.id,
@@ -7,10 +7,11 @@ import {
MedusaResponse,
} from "../../../types/routing"
import { AdminGetOrdersParamsType } from "../../admin/draft-orders/validators"
import { HttpTypes } from "@medusajs/types"
export const GET = async (
req: AuthenticatedMedusaRequest<AdminGetOrdersParamsType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.StoreOrderListResponse>
) => {
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
@@ -5,10 +5,11 @@ import {
} from "../../../../../types/routing"
import { StoreCreatePaymentSessionType } from "../../validators"
import { refetchPaymentCollection } from "../../helpers"
import { HttpTypes } from "@medusajs/types"
export const POST = async (
req: AuthenticatedMedusaRequest<StoreCreatePaymentSessionType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.StorePaymentCollectionResponse>
) => {
const collectionId = req.params.id
const { context = {}, data, provider_id } = req.body
@@ -8,10 +8,11 @@ import {
MedusaResponse,
} from "../../../types/routing"
import { StoreCreatePaymentCollectionType } from "./validators"
import { HttpTypes } from "@medusajs/types"
export const POST = async (
req: AuthenticatedMedusaRequest<StoreCreatePaymentCollectionType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.StorePaymentCollectionResponse>
) => {
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
const { cart_id } = req.body
@@ -8,11 +8,12 @@ import {
remoteQueryObjectFromString,
} from "@medusajs/utils"
import { StoreGetPaymentProvidersParamsType } from "./validators"
import { HttpTypes } from "@medusajs/types"
// TODO: Add more fields to provider, such as default name and maybe logo.
export const GET = async (
req: AuthenticatedMedusaRequest<StoreGetPaymentProvidersParamsType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.StorePaymentProviderListResponse>
) => {
if (!req.filterableFields.region_id) {
throw new MedusaError(