From f1245316a21e6ee9da228d692aa3b922f1166944 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 12 Jun 2024 13:46:22 +0700 Subject: [PATCH] feat: prevent invalid groupId sent --- src/controllers/product/type-controller.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/controllers/product/type-controller.ts b/src/controllers/product/type-controller.ts index 2395b96..ef859da 100644 --- a/src/controllers/product/type-controller.ts +++ b/src/controllers/product/type-controller.ts @@ -114,6 +114,17 @@ export class ProductType extends Controller { @Body() body: ProductTypeUpdate, @Path() typeId: string, ) { + if ( + body.productGroupId && + !(await prisma.productType.findFirst({ where: { id: body.productGroupId } })) + ) { + throw new HttpError( + HttpStatus.BAD_REQUEST, + "Product group cannot be found.", + "missing_or_invalid_parameter", + ); + } + if (!(await prisma.productType.findUnique({ where: { id: typeId } }))) { throw new HttpError(HttpStatus.NOT_FOUND, "Product type cannot be found.", "data_not_found"); }