chore(medusa,types): [10] Add request types to API routes (#8567)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { DeleteResponse, PaginatedResponse } from "../../common"
|
||||
import { AdminPrice } from "../../pricing"
|
||||
import { AdminPriceList } from "./entities"
|
||||
|
||||
export interface AdminPriceListResponse {
|
||||
@@ -12,3 +13,13 @@ export interface AdminPriceListListResponse
|
||||
|
||||
export interface AdminPriceListDeleteResponse
|
||||
extends DeleteResponse<"price_list"> {}
|
||||
|
||||
export interface AdminPriceListBatchResponse {
|
||||
created: AdminPrice[]
|
||||
updated: AdminPrice[]
|
||||
deleted: {
|
||||
ids: string[]
|
||||
object: "price"
|
||||
deleted: boolean
|
||||
}
|
||||
}
|
||||
@@ -29,3 +29,11 @@ export interface AdminProduct
|
||||
tags?: AdminProductTag[] | null
|
||||
}
|
||||
export type AdminProductStatus = ProductStatus
|
||||
export interface AdminProductVariantInventoryLink {
|
||||
productService: {
|
||||
variant_id: string
|
||||
}
|
||||
inventoryService: {
|
||||
inventory_item_id: string
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
AdminProduct,
|
||||
AdminProductOption,
|
||||
AdminProductVariant,
|
||||
AdminProductVariantInventoryLink,
|
||||
} from "./entitites"
|
||||
import { AdminInventoryItem } from "../../inventory"
|
||||
|
||||
@@ -59,3 +60,18 @@ export type AdminProductOptionListResponse = PaginatedResponse<{
|
||||
|
||||
export interface AdminProductOptionDeleteResponse
|
||||
extends DeleteResponse<"product_option", AdminProduct> {}
|
||||
|
||||
export type AdminProductVariantInventoryResponse = AdminProductVariantInventoryLink | AdminProductVariantInventoryLink[]
|
||||
|
||||
export interface AdminProductVariantInventoryBatchResponse {
|
||||
created: AdminProductVariantInventoryResponse
|
||||
updated: AdminProductVariantInventoryResponse
|
||||
deleted: AdminProductVariantInventoryResponse
|
||||
}
|
||||
|
||||
export interface AdminProductVariantInventoryLinkDeleteResponse {
|
||||
id: AdminProductVariantInventoryLink
|
||||
object: "variant-inventory-item-link"
|
||||
deleted: boolean
|
||||
parent: AdminProductVariant
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
} from "../../../../../../types/routing"
|
||||
import { listPrices } from "../../../queries"
|
||||
import { adminPriceListPriceRemoteQueryFields } from "../../../query-config"
|
||||
import { BatchMethodRequest } from "@medusajs/types"
|
||||
import { BatchMethodRequest, HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
AdminCreatePriceListPriceType,
|
||||
AdminUpdatePriceListPriceType,
|
||||
@@ -19,7 +19,7 @@ export const POST = async (
|
||||
AdminUpdatePriceListPriceType
|
||||
>
|
||||
>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminPriceListBatchResponse>
|
||||
) => {
|
||||
const id = req.params.id
|
||||
const {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { batchPriceListPricesWorkflow } from "@medusajs/core-flows"
|
||||
import { LinkMethodRequest } from "@medusajs/types"
|
||||
import { HttpTypes, LinkMethodRequest } from "@medusajs/types"
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
@@ -9,7 +9,7 @@ import { fetchPriceList, fetchPriceListPriceIdsForProduct } from "../../helpers"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<LinkMethodRequest>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminPriceListResponse>
|
||||
) => {
|
||||
const id = req.params.id
|
||||
const { add, remove = [] } = req.validatedBody
|
||||
|
||||
@@ -8,10 +8,11 @@ import {
|
||||
} from "../../../../types/routing"
|
||||
import { fetchPriceList } from "../helpers"
|
||||
import { AdminUpdatePriceListType } from "../validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminPriceListResponse>
|
||||
) => {
|
||||
const price_list = await fetchPriceList(
|
||||
req.params.id,
|
||||
@@ -24,7 +25,7 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminUpdatePriceListType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminPriceListResponse>
|
||||
) => {
|
||||
const id = req.params.id
|
||||
const workflow = updatePriceListsWorkflow(req.scope)
|
||||
@@ -44,7 +45,7 @@ export const POST = async (
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminPriceListDeleteResponse>
|
||||
) => {
|
||||
const id = req.params.id
|
||||
const workflow = deletePriceListsWorkflow(req.scope)
|
||||
|
||||
@@ -9,10 +9,11 @@ import {
|
||||
} from "../../../types/routing"
|
||||
import { fetchPriceList, transformPriceList } from "./helpers"
|
||||
import { AdminCreatePriceListType } from "./validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminPriceListListResponse>
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
@@ -37,7 +38,7 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminCreatePriceListType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminPriceListResponse>
|
||||
) => {
|
||||
const workflow = createPriceListsWorkflow(req.scope)
|
||||
const { result } = await workflow.run({
|
||||
|
||||
@@ -12,7 +12,7 @@ import { refetchEntity } from "../../../utils/refetch-entity"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminPricePreferenceResponse>
|
||||
) => {
|
||||
const price_preference = await refetchEntity(
|
||||
"price_preference",
|
||||
@@ -26,7 +26,7 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<HttpTypes.AdminUpdatePricePreference>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminPricePreferenceResponse>
|
||||
) => {
|
||||
const id = req.params.id
|
||||
const workflow = updatePricePreferencesWorkflow(req.scope)
|
||||
@@ -47,7 +47,7 @@ export const POST = async (
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminPricePreferenceDeleteResponse>
|
||||
) => {
|
||||
const id = req.params.id
|
||||
const workflow = deletePricePreferencesWorkflow(req.scope)
|
||||
|
||||
@@ -8,7 +8,7 @@ import { createPricePreferencesWorkflow } from "@medusajs/core-flows"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminPricePreferenceListResponse>
|
||||
) => {
|
||||
const { rows: price_preferences, metadata } = await refetchEntities(
|
||||
"price_preference",
|
||||
@@ -27,7 +27,7 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<HttpTypes.AdminCreatePricePreference>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminPricePreferenceResponse>
|
||||
) => {
|
||||
const workflow = createPricePreferencesWorkflow(req.scope)
|
||||
const { result } = await workflow.run({
|
||||
|
||||
@@ -2,7 +2,7 @@ import {
|
||||
deleteProductCategoriesWorkflow,
|
||||
updateProductCategoriesWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { AdminProductCategoryResponse } from "@medusajs/types"
|
||||
import { AdminProductCategoryResponse, HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
@@ -57,7 +57,7 @@ export const POST = async (
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminProductCategoryDeleteResponse>
|
||||
) => {
|
||||
const id = req.params.id
|
||||
|
||||
|
||||
@@ -12,10 +12,11 @@ import {
|
||||
AdminUpdateProductTagType,
|
||||
} from "../validators"
|
||||
import { refetchEntity } from "../../../utils/refetch-entity"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest<AdminGetProductTagParamsType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminProductTagResponse>
|
||||
) => {
|
||||
const productTag = await refetchEntity(
|
||||
"product_tag",
|
||||
@@ -29,7 +30,7 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminUpdateProductTagType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminProductTagResponse>
|
||||
) => {
|
||||
const { result } = await updateProductTagsWorkflow(req.scope).run({
|
||||
input: {
|
||||
@@ -50,7 +51,7 @@ export const POST = async (
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminProductTagDeleteResponse>
|
||||
) => {
|
||||
const id = req.params.id
|
||||
|
||||
|
||||
@@ -9,10 +9,11 @@ import {
|
||||
AdminGetProductTagsParamsType,
|
||||
} from "./validators"
|
||||
import { refetchEntities, refetchEntity } from "../../utils/refetch-entity"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest<AdminGetProductTagsParamsType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminProductTagListResponse>
|
||||
) => {
|
||||
const { rows: product_tags, metadata } = await refetchEntities(
|
||||
"product_tag",
|
||||
@@ -32,7 +33,7 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminCreateProductTagType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminProductTagResponse>
|
||||
) => {
|
||||
const input = [req.validatedBody]
|
||||
|
||||
|
||||
@@ -12,10 +12,11 @@ import {
|
||||
AdminGetProductTypeParamsType,
|
||||
AdminUpdateProductTypeType,
|
||||
} from "../validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest<AdminGetProductTypeParamsType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminProductTypeResponse>
|
||||
) => {
|
||||
const productType = await refetchProductType(
|
||||
req.params.id,
|
||||
@@ -28,7 +29,7 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminUpdateProductTypeType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminProductTypeResponse>
|
||||
) => {
|
||||
const { result } = await updateProductTypesWorkflow(req.scope).run({
|
||||
input: {
|
||||
@@ -48,7 +49,7 @@ export const POST = async (
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminProductTypeDeleteResponse>
|
||||
) => {
|
||||
const id = req.params.id
|
||||
|
||||
|
||||
@@ -13,10 +13,11 @@ import {
|
||||
AdminCreateProductTypeType,
|
||||
AdminGetProductTypesParamsType,
|
||||
} from "./validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest<AdminGetProductTypesParamsType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminProductTypeListResponse>
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
@@ -40,7 +41,7 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminCreateProductTypeType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminProductTypeResponse>
|
||||
) => {
|
||||
const input = [req.validatedBody]
|
||||
|
||||
|
||||
@@ -6,10 +6,11 @@ import {
|
||||
} from "../../../../../../../../types/routing"
|
||||
import { refetchVariant } from "../../../../../helpers"
|
||||
import { AdminUpdateVariantInventoryItemType } from "../../../../../validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminUpdateVariantInventoryItemType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminProductVariantResponse>
|
||||
) => {
|
||||
const variantId = req.params.variant_id
|
||||
const inventoryItemId = req.params.inventory_item_id
|
||||
@@ -35,7 +36,7 @@ export const POST = async (
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminProductVariantInventoryLinkDeleteResponse>
|
||||
) => {
|
||||
const variantId = req.params.variant_id
|
||||
const inventoryItemId = req.params.inventory_item_id
|
||||
@@ -58,7 +59,7 @@ export const DELETE = async (
|
||||
)
|
||||
|
||||
res.status(200).json({
|
||||
id: deleted,
|
||||
id: deleted as unknown as HttpTypes.AdminProductVariantInventoryLink,
|
||||
object: "variant-inventory-item-link",
|
||||
deleted: true,
|
||||
parent,
|
||||
|
||||
@@ -6,10 +6,11 @@ import {
|
||||
} from "../../../../../../../types/routing"
|
||||
import { refetchVariant } from "../../../../helpers"
|
||||
import { AdminCreateVariantInventoryItemType } from "../../../../validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminCreateVariantInventoryItemType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminProductVariantResponse>
|
||||
) => {
|
||||
const variantId = req.params.variant_id
|
||||
|
||||
|
||||
@@ -5,10 +5,11 @@ import {
|
||||
} from "../../../../../../../types/routing"
|
||||
import { buildBatchVariantInventoryData } from "../../../../helpers"
|
||||
import { AdminBatchVariantInventoryItemsType } from "../../../../validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminBatchVariantInventoryItemsType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminProductVariantInventoryBatchResponse>
|
||||
) => {
|
||||
const { create = [], update = [], delete: toDelete = [] } = req.validatedBody
|
||||
|
||||
@@ -24,5 +25,5 @@ export const POST = async (
|
||||
created: result.created,
|
||||
updated: result.updated,
|
||||
deleted: result.deleted,
|
||||
})
|
||||
} as unknown as HttpTypes.AdminProductVariantInventoryBatchResponse)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user