feat: prevent invalid groupId sent

This commit is contained in:
Methapon2001 2024-06-12 13:46:22 +07:00
parent 4c60c81bac
commit f1245316a2

View file

@ -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");
}