Clean up product typings (#7663)
There are a lot of issues in the admin after applying the correct typings, but fixing those should be done gradually, it's better to keep it out of this PR
This commit is contained in:
@@ -10,7 +10,6 @@ import { invites } from "./invites"
|
||||
import { payments } from "./payments"
|
||||
import { priceLists } from "./price-lists"
|
||||
import { productTypes } from "./product-types"
|
||||
import { products } from "./products"
|
||||
import { promotions } from "./promotions"
|
||||
import { reservations } from "./reservations"
|
||||
import { salesChannels } from "./sales-channels"
|
||||
@@ -42,7 +41,6 @@ export const client = {
|
||||
reservations: reservations,
|
||||
fulfillments: fulfillments,
|
||||
fulfillmentProviders: fulfillmentProviders,
|
||||
products: products,
|
||||
productTypes: productTypes,
|
||||
priceLists: priceLists,
|
||||
stockLocations: stockLocations,
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
import { ProductTypeListRes, ProductTypeRes } from "../../types/api-responses"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { getRequest } from "./common"
|
||||
|
||||
async function listProductTypes(query?: Record<string, any>) {
|
||||
return getRequest<ProductTypeListRes>(`/admin/product-types`, query)
|
||||
return getRequest<{ product_types: HttpTypes.AdminProductType[] }>(
|
||||
`/admin/product-types`,
|
||||
query
|
||||
)
|
||||
}
|
||||
|
||||
async function retrieveProductType(id: string, query?: Record<string, any>) {
|
||||
return getRequest<ProductTypeRes>(`/admin/product-types/${id}`, query)
|
||||
return getRequest<{ product_type: HttpTypes.AdminProductType }>(
|
||||
`/admin/product-types/${id}`,
|
||||
query
|
||||
)
|
||||
}
|
||||
|
||||
export const productTypes = {
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
import { ProductDeleteRes, ProductListRes } from "../../types/api-responses"
|
||||
import { deleteRequest, getRequest, postRequest } from "./common"
|
||||
|
||||
async function retrieveProduct(id: string, query?: Record<string, any>) {
|
||||
return getRequest<any>(`/admin/products/${id}`, query)
|
||||
}
|
||||
|
||||
async function createProduct(payload: any) {
|
||||
return postRequest<any>(`/admin/products`, payload)
|
||||
}
|
||||
|
||||
async function listProducts(query?: Record<string, any>) {
|
||||
return getRequest<ProductListRes>(`/admin/products`, query)
|
||||
}
|
||||
|
||||
async function updateProduct(id: string, payload: any) {
|
||||
return postRequest<any>(`/admin/products/${id}`, payload)
|
||||
}
|
||||
|
||||
async function deleteProduct(id: string) {
|
||||
return deleteRequest<ProductDeleteRes>(`/admin/products/${id}`)
|
||||
}
|
||||
|
||||
async function retrieveVariant(
|
||||
productId: string,
|
||||
variantId: string,
|
||||
query?: Record<string, any>
|
||||
) {
|
||||
return getRequest<any>(
|
||||
`/admin/products/${productId}/variants/${variantId}`,
|
||||
query
|
||||
)
|
||||
}
|
||||
|
||||
async function listVariants(productId: string, query?: Record<string, any>) {
|
||||
return getRequest<any>(`/admin/products/${productId}/variants`, query)
|
||||
}
|
||||
|
||||
async function createVariant(productId: string, payload: any) {
|
||||
return postRequest<any>(`/admin/products/${productId}/variants`, payload)
|
||||
}
|
||||
|
||||
async function updateVariant(
|
||||
productId: string,
|
||||
variantId: string,
|
||||
payload: any
|
||||
) {
|
||||
return postRequest<any>(
|
||||
`/admin/products/${productId}/variants/${variantId}`,
|
||||
payload
|
||||
)
|
||||
}
|
||||
|
||||
async function updateVariantsBatch(
|
||||
productId: string,
|
||||
payload: { add: any[]; update: any[]; remove: any[] }
|
||||
) {
|
||||
return postRequest<any>(
|
||||
`/admin/products/${productId}/variants/batch`,
|
||||
payload
|
||||
)
|
||||
}
|
||||
|
||||
async function deleteVariant(productId: string, variantId: string) {
|
||||
return deleteRequest<any>(
|
||||
`/admin/products/${productId}/variants/${variantId}`
|
||||
)
|
||||
}
|
||||
|
||||
async function createOption(productId: string, payload: any) {
|
||||
return postRequest<any>(`/admin/products/${productId}/options`, payload)
|
||||
}
|
||||
|
||||
async function updateOption(productId: string, optionId: string, payload: any) {
|
||||
return postRequest<any>(
|
||||
`/admin/products/${productId}/options/${optionId}`,
|
||||
payload
|
||||
)
|
||||
}
|
||||
|
||||
async function deleteOption(productId: string, optionId: string) {
|
||||
return deleteRequest<any>(`/admin/products/${productId}/options/${optionId}`)
|
||||
}
|
||||
|
||||
export const products = {
|
||||
retrieve: retrieveProduct,
|
||||
list: listProducts,
|
||||
create: createProduct,
|
||||
update: updateProduct,
|
||||
delete: deleteProduct,
|
||||
retrieveVariant,
|
||||
listVariants,
|
||||
createVariant,
|
||||
updateVariant,
|
||||
updateVariantsBatch,
|
||||
deleteVariant,
|
||||
createOption,
|
||||
updateOption,
|
||||
deleteOption,
|
||||
}
|
||||
Reference in New Issue
Block a user