fix(medusa): change the request type of removing products from price list (#8964)
* fix(medusa): change the request type of removing products from price list * fix build error
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { batchPriceListPricesWorkflow } from "@medusajs/core-flows"
|
||||
import { HttpTypes, LinkMethodRequest } from "@medusajs/types"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
@@ -8,17 +8,11 @@ import {
|
||||
import { fetchPriceList, fetchPriceListPriceIdsForProduct } from "../../helpers"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<LinkMethodRequest>,
|
||||
req: AuthenticatedMedusaRequest<HttpTypes.AdminLinkPriceListProducts>,
|
||||
res: MedusaResponse<HttpTypes.AdminPriceListResponse>
|
||||
) => {
|
||||
const id = req.params.id
|
||||
const { add, remove = [] } = req.validatedBody
|
||||
if (add?.length) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
"Adding products directly to a price list is not supported, please use the /admin/price-lists/:id/prices/batch endpoint instead"
|
||||
)
|
||||
}
|
||||
const { remove = [] } = req.validatedBody
|
||||
|
||||
if (!remove.length) {
|
||||
throw new MedusaError(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { MiddlewareRoute } from "@medusajs/framework"
|
||||
import { validateAndTransformBody } from "../../utils/validate-body"
|
||||
import { validateAndTransformQuery } from "../../utils/validate-query"
|
||||
import { createBatchBody, createLinkBody } from "../../utils/validators"
|
||||
import { createBatchBody } from "../../utils/validators"
|
||||
import * as QueryConfig from "./query-config"
|
||||
import {
|
||||
AdminCreatePriceList,
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
AdminGetPriceListParams,
|
||||
AdminGetPriceListPricesParams,
|
||||
AdminGetPriceListsParams,
|
||||
AdminRemoveProductsPriceList,
|
||||
AdminUpdatePriceList,
|
||||
AdminUpdatePriceListPrice,
|
||||
} from "./validators"
|
||||
@@ -60,7 +61,7 @@ export const adminPriceListsRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
method: ["POST"],
|
||||
matcher: "/admin/price-lists/:id/products",
|
||||
middlewares: [
|
||||
validateAndTransformBody(createLinkBody()),
|
||||
validateAndTransformBody(AdminRemoveProductsPriceList),
|
||||
validateAndTransformQuery(
|
||||
AdminGetPriceListParams,
|
||||
QueryConfig.listPriceListQueryConfig
|
||||
|
||||
@@ -76,3 +76,11 @@ export const AdminUpdatePriceList = z.object({
|
||||
})
|
||||
|
||||
export type AdminUpdatePriceListType = z.infer<typeof AdminUpdatePriceList>
|
||||
|
||||
export const AdminRemoveProductsPriceList = z.object({
|
||||
remove: z.array(z.string()).optional(),
|
||||
})
|
||||
|
||||
export type AdminRemoveProductsPriceListType = z.infer<
|
||||
typeof AdminRemoveProductsPriceList
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user