feat: prevent invalid groupId sent
This commit is contained in:
parent
4c60c81bac
commit
f1245316a2
1 changed files with 11 additions and 0 deletions
|
|
@ -114,6 +114,17 @@ export class ProductType extends Controller {
|
||||||
@Body() body: ProductTypeUpdate,
|
@Body() body: ProductTypeUpdate,
|
||||||
@Path() typeId: string,
|
@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 } }))) {
|
if (!(await prisma.productType.findUnique({ where: { id: typeId } }))) {
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "Product type cannot be found.", "data_not_found");
|
throw new HttpError(HttpStatus.NOT_FOUND, "Product type cannot be found.", "data_not_found");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue