chore(medusa,types): [1] Add request types to API routes (#8558)
Add request types as type arguments in API routes. This also includes adding / rearranging types under the `types` package. PR 1/n
This commit is contained in:
1 parent
dd4147314f
commit
24985cf89d
19 files changed
+86
-30
No files matched your search
@@ -0,0 +1,11 @@
|
|||||||
|
import {
|
||||||
|
BaseCart,
|
||||||
|
BaseCartAddress,
|
||||||
|
BaseCartLineItem,
|
||||||
|
BaseCartShippingMethod,
|
||||||
|
} from "../common"
|
||||||
|
|
||||||
|
export interface StoreCart extends BaseCart {}
|
||||||
|
export interface StoreCartLineItem extends BaseCartLineItem {}
|
||||||
|
export interface StoreCartAddress extends BaseCartAddress {}
|
||||||
|
export interface StoreCartShippingMethod extends BaseCartShippingMethod {}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export * from "./entities"
|
||||||
|
export * from "./payloads"
|
||||||
|
export * from "./responses"
|
||||||
+1
-11
@@ -1,14 +1,4 @@
|
|||||||
import {
|
import { StoreCartAddress, StoreCartLineItem } from "./entities"
|
||||||
BaseCart,
|
|
||||||
BaseCartAddress,
|
|
||||||
BaseCartLineItem,
|
|
||||||
BaseCartShippingMethod,
|
|
||||||
} from "./common"
|
|
||||||
|
|
||||||
export interface StoreCart extends BaseCart {}
|
|
||||||
export interface StoreCartLineItem extends BaseCartLineItem {}
|
|
||||||
export interface StoreCartAddress extends BaseCartAddress {}
|
|
||||||
export interface StoreCartShippingMethod extends BaseCartShippingMethod {}
|
|
||||||
|
|
||||||
export interface StoreCreateCart {
|
export interface StoreCreateCart {
|
||||||
region_id?: string
|
region_id?: string
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { StoreOrder } from "../../order"
|
||||||
|
import { StoreCart } from "./entities"
|
||||||
|
|
||||||
|
export interface StoreCartResponse {
|
||||||
|
cart: StoreCart
|
||||||
|
}
|
||||||
|
|
||||||
|
export type StoreCompleteCartResponse = {
|
||||||
|
type: "cart"
|
||||||
|
cart: StoreCart
|
||||||
|
error: {
|
||||||
|
message: string
|
||||||
|
name: string
|
||||||
|
type: string
|
||||||
|
}
|
||||||
|
} | {
|
||||||
|
type: "order"
|
||||||
|
order: StoreOrder
|
||||||
|
}
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
import { BaseCollection, BaseCollectionListParams } from "./common"
|
|
||||||
|
|
||||||
export interface StoreCollection extends BaseCollection {}
|
|
||||||
export interface StoreCollectionFilters extends BaseCollectionListParams {}
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import { BaseCollection, BaseCollectionListParams } from "../common"
|
||||||
|
|
||||||
|
export interface StoreCollection extends BaseCollection {}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export * from "./entities"
|
||||||
|
export * from "./queries"
|
||||||
|
export * from "./responses"
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import { BaseCollectionListParams } from "../common";
|
||||||
|
|
||||||
|
export interface StoreCollectionFilters extends BaseCollectionListParams {}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { StoreCollection } from "."
|
||||||
|
import { PaginatedResponse } from "../../common"
|
||||||
|
|
||||||
|
export interface StoreCollectionResponse {
|
||||||
|
collection: StoreCollection
|
||||||
|
}
|
||||||
|
|
||||||
|
export type StoreCollectionListResponse = PaginatedResponse<{
|
||||||
|
collections: StoreCollection[]
|
||||||
|
}>
|
||||||
@@ -6,10 +6,11 @@ import { refetchOrder } from "../../../orders/helpers"
|
|||||||
import { refetchCart } from "../../helpers"
|
import { refetchCart } from "../../helpers"
|
||||||
import { defaultStoreCartFields } from "../../query-config"
|
import { defaultStoreCartFields } from "../../query-config"
|
||||||
import { StoreCompleteCartType } from "../../validators"
|
import { StoreCompleteCartType } from "../../validators"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: MedusaRequest<StoreCompleteCartType>,
|
req: MedusaRequest<StoreCompleteCartType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreCompleteCartResponse>
|
||||||
) => {
|
) => {
|
||||||
const cart_id = req.params.id
|
const cart_id = req.params.id
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import {
|
|||||||
deleteLineItemsWorkflow,
|
deleteLineItemsWorkflow,
|
||||||
updateLineItemInCartWorkflow,
|
updateLineItemInCartWorkflow,
|
||||||
} from "@medusajs/core-flows"
|
} from "@medusajs/core-flows"
|
||||||
import { DeleteResponse } from "@medusajs/types"
|
import { DeleteResponse, HttpTypes } from "@medusajs/types"
|
||||||
import { MedusaError } from "@medusajs/utils"
|
import { MedusaError } from "@medusajs/utils"
|
||||||
import { MedusaRequest, MedusaResponse } from "../../../../../../types/routing"
|
import { MedusaRequest, MedusaResponse } from "../../../../../../types/routing"
|
||||||
import { prepareListQuery } from "../../../../../../utils/get-query-config"
|
import { prepareListQuery } from "../../../../../../utils/get-query-config"
|
||||||
@@ -11,7 +11,7 @@ import { StoreUpdateCartLineItemType } from "../../../validators"
|
|||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: MedusaRequest<StoreUpdateCartLineItemType>,
|
req: MedusaRequest<StoreUpdateCartLineItemType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreCartResponse>
|
||||||
) => {
|
) => {
|
||||||
const cart = await refetchCart(
|
const cart = await refetchCart(
|
||||||
req.params.id,
|
req.params.id,
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ import { addToCartWorkflow } from "@medusajs/core-flows"
|
|||||||
import { MedusaRequest, MedusaResponse } from "../../../../../types/routing"
|
import { MedusaRequest, MedusaResponse } from "../../../../../types/routing"
|
||||||
import { refetchCart } from "../../helpers"
|
import { refetchCart } from "../../helpers"
|
||||||
import { StoreAddCartLineItemType } from "../../validators"
|
import { StoreAddCartLineItemType } from "../../validators"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: MedusaRequest<StoreAddCartLineItemType>,
|
req: MedusaRequest<StoreAddCartLineItemType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreCartResponse>
|
||||||
) => {
|
) => {
|
||||||
const cart = await refetchCart(
|
const cart = await refetchCart(
|
||||||
req.params.id,
|
req.params.id,
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ import {
|
|||||||
StoreAddCartPromotionsType,
|
StoreAddCartPromotionsType,
|
||||||
StoreRemoveCartPromotionsType,
|
StoreRemoveCartPromotionsType,
|
||||||
} from "../../validators"
|
} from "../../validators"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: MedusaRequest<StoreAddCartPromotionsType>,
|
req: MedusaRequest<StoreAddCartPromotionsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreCartResponse>
|
||||||
) => {
|
) => {
|
||||||
const workflow = updateCartPromotionsWorkflow(req.scope)
|
const workflow = updateCartPromotionsWorkflow(req.scope)
|
||||||
const payload = req.validatedBody
|
const payload = req.validatedBody
|
||||||
@@ -33,7 +34,9 @@ export const POST = async (
|
|||||||
|
|
||||||
export const DELETE = async (
|
export const DELETE = async (
|
||||||
req: MedusaRequest<StoreRemoveCartPromotionsType>,
|
req: MedusaRequest<StoreRemoveCartPromotionsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<{
|
||||||
|
cart: HttpTypes.StoreCart
|
||||||
|
}>
|
||||||
) => {
|
) => {
|
||||||
const workflow = updateCartPromotionsWorkflow(req.scope)
|
const workflow = updateCartPromotionsWorkflow(req.scope)
|
||||||
const payload = req.validatedBody
|
const payload = req.validatedBody
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
import { updateCartWorkflow } from "@medusajs/core-flows"
|
import { updateCartWorkflow } from "@medusajs/core-flows"
|
||||||
import { AdditionalData, UpdateCartDataDTO } from "@medusajs/types"
|
import { AdditionalData, HttpTypes, UpdateCartDataDTO } from "@medusajs/types"
|
||||||
|
|
||||||
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
|
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
|
||||||
import { refetchCart } from "../helpers"
|
import { refetchCart } from "../helpers"
|
||||||
|
|
||||||
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
export const GET = async (
|
||||||
|
req: MedusaRequest,
|
||||||
|
res: MedusaResponse<HttpTypes.StoreCartResponse>
|
||||||
|
) => {
|
||||||
const cart = await refetchCart(
|
const cart = await refetchCart(
|
||||||
req.params.id,
|
req.params.id,
|
||||||
req.scope,
|
req.scope,
|
||||||
@@ -16,7 +19,9 @@ export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
|||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: MedusaRequest<UpdateCartDataDTO & AdditionalData>,
|
req: MedusaRequest<UpdateCartDataDTO & AdditionalData>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<{
|
||||||
|
cart: HttpTypes.StoreCart
|
||||||
|
}>
|
||||||
) => {
|
) => {
|
||||||
const workflow = updateCartWorkflow(req.scope)
|
const workflow = updateCartWorkflow(req.scope)
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ import { addShippingMethodToWorkflow } from "@medusajs/core-flows"
|
|||||||
import { MedusaRequest, MedusaResponse } from "../../../../../types/routing"
|
import { MedusaRequest, MedusaResponse } from "../../../../../types/routing"
|
||||||
import { refetchCart } from "../../helpers"
|
import { refetchCart } from "../../helpers"
|
||||||
import { StoreAddCartShippingMethodsType } from "../../validators"
|
import { StoreAddCartShippingMethodsType } from "../../validators"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: MedusaRequest<StoreAddCartShippingMethodsType>,
|
req: MedusaRequest<StoreAddCartShippingMethodsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreCartResponse>
|
||||||
) => {
|
) => {
|
||||||
const workflow = addShippingMethodToWorkflow(req.scope)
|
const workflow = addShippingMethodToWorkflow(req.scope)
|
||||||
const payload = req.validatedBody
|
const payload = req.validatedBody
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ import { updateTaxLinesWorkflow } from "@medusajs/core-flows"
|
|||||||
import { MedusaRequest, MedusaResponse } from "../../../../../types/routing"
|
import { MedusaRequest, MedusaResponse } from "../../../../../types/routing"
|
||||||
import { refetchCart } from "../../helpers"
|
import { refetchCart } from "../../helpers"
|
||||||
import { StoreCalculateCartTaxesType } from "../../validators"
|
import { StoreCalculateCartTaxesType } from "../../validators"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: MedusaRequest<StoreCalculateCartTaxesType>,
|
req: MedusaRequest<StoreCalculateCartTaxesType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreCartResponse>
|
||||||
) => {
|
) => {
|
||||||
const workflow = updateTaxLinesWorkflow(req.scope)
|
const workflow = updateTaxLinesWorkflow(req.scope)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { createCartWorkflow } from "@medusajs/core-flows"
|
import { createCartWorkflow } from "@medusajs/core-flows"
|
||||||
import { AdditionalData, CreateCartWorkflowInputDTO } from "@medusajs/types"
|
import {
|
||||||
|
AdditionalData,
|
||||||
|
CreateCartWorkflowInputDTO,
|
||||||
|
HttpTypes,
|
||||||
|
} from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
@@ -8,7 +12,7 @@ import { refetchCart } from "./helpers"
|
|||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<CreateCartWorkflowInputDTO & AdditionalData>,
|
req: AuthenticatedMedusaRequest<CreateCartWorkflowInputDTO & AdditionalData>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreCartResponse>
|
||||||
) => {
|
) => {
|
||||||
const workflowInput = {
|
const workflowInput = {
|
||||||
...req.validatedBody,
|
...req.validatedBody,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
@@ -6,7 +7,7 @@ import { refetchCollection } from "../helpers"
|
|||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreCollectionResponse>
|
||||||
) => {
|
) => {
|
||||||
const collection = await refetchCollection(
|
const collection = await refetchCollection(
|
||||||
req.params.id,
|
req.params.id,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
@@ -10,7 +11,7 @@ import {
|
|||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreCollectionListResponse>
|
||||||
) => {
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user