feat: add backend-mock app
This commit is contained in:
27
apps/backend-mock/src/core/pipe/params.pipe.ts
Normal file
27
apps/backend-mock/src/core/pipe/params.pipe.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
HttpStatus,
|
||||
ValidationPipe,
|
||||
type ValidationPipeOptions,
|
||||
} from '@nestjs/common';
|
||||
|
||||
class ParamsValidationPipe extends ValidationPipe {
|
||||
constructor(options: ValidationPipeOptions = {}) {
|
||||
super({
|
||||
errorHttpStatusCode: HttpStatus.BAD_REQUEST,
|
||||
exceptionFactory: (errors) => {
|
||||
const message = Object.values(errors[0].constraints)[0];
|
||||
return new BadRequestException({
|
||||
message,
|
||||
status: HttpStatus.BAD_REQUEST,
|
||||
});
|
||||
},
|
||||
forbidNonWhitelisted: true,
|
||||
transform: true,
|
||||
whitelist: true,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export { ParamsValidationPipe };
|
Reference in New Issue
Block a user