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 { batchPriceListPricesWorkflow } from "@medusajs/core-flows"
|
||||||
import { HttpTypes, LinkMethodRequest } from "@medusajs/types"
|
import { HttpTypes } from "@medusajs/types"
|
||||||
import { MedusaError } from "@medusajs/utils"
|
import { MedusaError } from "@medusajs/utils"
|
||||||
import {
|
import {
|
||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
@@ -8,17 +8,11 @@ import {
|
|||||||
import { fetchPriceList, fetchPriceListPriceIdsForProduct } from "../../helpers"
|
import { fetchPriceList, fetchPriceListPriceIdsForProduct } from "../../helpers"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<LinkMethodRequest>,
|
req: AuthenticatedMedusaRequest<HttpTypes.AdminLinkPriceListProducts>,
|
||||||
res: MedusaResponse<HttpTypes.AdminPriceListResponse>
|
res: MedusaResponse<HttpTypes.AdminPriceListResponse>
|
||||||
) => {
|
) => {
|
||||||
const id = req.params.id
|
const id = req.params.id
|
||||||
const { add, remove = [] } = req.validatedBody
|
const { 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"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!remove.length) {
|
if (!remove.length) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { MiddlewareRoute } from "@medusajs/framework"
|
import { MiddlewareRoute } from "@medusajs/framework"
|
||||||
import { validateAndTransformBody } from "../../utils/validate-body"
|
import { validateAndTransformBody } from "../../utils/validate-body"
|
||||||
import { validateAndTransformQuery } from "../../utils/validate-query"
|
import { validateAndTransformQuery } from "../../utils/validate-query"
|
||||||
import { createBatchBody, createLinkBody } from "../../utils/validators"
|
import { createBatchBody } from "../../utils/validators"
|
||||||
import * as QueryConfig from "./query-config"
|
import * as QueryConfig from "./query-config"
|
||||||
import {
|
import {
|
||||||
AdminCreatePriceList,
|
AdminCreatePriceList,
|
||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
AdminGetPriceListParams,
|
AdminGetPriceListParams,
|
||||||
AdminGetPriceListPricesParams,
|
AdminGetPriceListPricesParams,
|
||||||
AdminGetPriceListsParams,
|
AdminGetPriceListsParams,
|
||||||
|
AdminRemoveProductsPriceList,
|
||||||
AdminUpdatePriceList,
|
AdminUpdatePriceList,
|
||||||
AdminUpdatePriceListPrice,
|
AdminUpdatePriceListPrice,
|
||||||
} from "./validators"
|
} from "./validators"
|
||||||
@@ -60,7 +61,7 @@ export const adminPriceListsRoutesMiddlewares: MiddlewareRoute[] = [
|
|||||||
method: ["POST"],
|
method: ["POST"],
|
||||||
matcher: "/admin/price-lists/:id/products",
|
matcher: "/admin/price-lists/:id/products",
|
||||||
middlewares: [
|
middlewares: [
|
||||||
validateAndTransformBody(createLinkBody()),
|
validateAndTransformBody(AdminRemoveProductsPriceList),
|
||||||
validateAndTransformQuery(
|
validateAndTransformQuery(
|
||||||
AdminGetPriceListParams,
|
AdminGetPriceListParams,
|
||||||
QueryConfig.listPriceListQueryConfig
|
QueryConfig.listPriceListQueryConfig
|
||||||
|
|||||||
@@ -76,3 +76,11 @@ export const AdminUpdatePriceList = z.object({
|
|||||||
})
|
})
|
||||||
|
|
||||||
export type AdminUpdatePriceListType = z.infer<typeof AdminUpdatePriceList>
|
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