📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
added validation when updating a category
Yevhenii K67072963e0d7
diff --git a/src/marketplace/categories/categories.controller.ts b/src/marketplace/categories/categories.controller.tsindex 7281772e9..29b95a40c 100644--- a/src/marketplace/categories/categories.controller.ts+++ b/src/marketplace/categories/categories.controller.ts@@ -26,9 +26,17 @@ import { GetCategoryParams } from './dtos/get-category-params.dto'import { UpdateCategoryParams } from './dtos/update-category-params.dto'import { UpdateCategory } from './dtos/update-category.dto'import { ISaveCategory } from './interfaces/save-category.interface'+import { BodyValidationPipe } from './pipes/body-validation.pipe'@ApiTags('categories')-@UsePipes(new ValidationPipe({ transform: true, whitelist: true }))+@UsePipes(+ new ValidationPipe({+ forbidNonWhitelisted: true,+ forbidUnknownValues: true,+ transform: true,+ whitelist: true,+ }),+)@Controller('categories')export class CategoriesController {constructor(private readonly categoriesService: CategoriesService) {}@@ -105,7 +113,7 @@ export class CategoriesController {@Patch(':categoryId')async updateCategory(@Param() params: UpdateCategoryParams,- @Body() body: UpdateCategory,+ @Body(new BodyValidationPipe()) body: UpdateCategory,): Promise<UpdateCategory> {const category = await this.categoriesService.findById(params.categoryId)diff --git a/src/marketplace/categories/pipes/body-validation.pipe.ts b/src/marketplace/categories/pipes/body-validation.pipe.tsnew file mode 100644index 000000000..49525325a--- /dev/null+++ b/src/marketplace/categories/pipes/body-validation.pipe.ts@@ -0,0 +1,12 @@+import { BadRequestException, Injectable, PipeTransform } from '@nestjs/common'++@Injectable()+export class BodyValidationPipe implements PipeTransform {+ transform(value: any) {+ if (Object.keys(value).length === 0) {+ throw new BadRequestException('The body cannot be empty.')+ }++ return value+ }+}