add app validation
This commit is contained in:
parent
d14eb92656
commit
778248b16f
@ -1,12 +1,22 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
|
|
||||||
|
import { APP_PIPE } from '@nestjs/core';
|
||||||
|
|
||||||
import { database } from './config';
|
import { database } from './config';
|
||||||
|
|
||||||
|
import { DEFAULT_VALIDATION_CONFIG } from './modules/content/constants';
|
||||||
import { ContentModule } from './modules/content/content.module';
|
import { ContentModule } from './modules/content/content.module';
|
||||||
import { CoreModule } from './modules/core/core.module';
|
import { CoreModule } from './modules/core/core.module';
|
||||||
|
import { AppPipe } from './modules/core/providers/app.pipe';
|
||||||
import { DatabaseModule } from './modules/database/database.module';
|
import { DatabaseModule } from './modules/database/database.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [ContentModule, CoreModule.forRoot(), DatabaseModule.forRoot(database)],
|
imports: [ContentModule, CoreModule.forRoot(), DatabaseModule.forRoot(database)],
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: APP_PIPE,
|
||||||
|
useValue: new AppPipe(DEFAULT_VALIDATION_CONFIG),
|
||||||
|
},
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
@ -10,12 +10,10 @@ import {
|
|||||||
Query,
|
Query,
|
||||||
SerializeOptions,
|
SerializeOptions,
|
||||||
UseInterceptors,
|
UseInterceptors,
|
||||||
ValidationPipe,
|
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
|
|
||||||
import { AppInterceptor } from '@/modules/core/providers/app.interceptor';
|
import { AppInterceptor } from '@/modules/core/providers/app.interceptor';
|
||||||
|
|
||||||
import { DEFAULT_VALIDATION_CONFIG } from '../constants';
|
|
||||||
import { CreateCategoryDto, QueryCategoryDto, UpdateCategoryDto } from '../dtos/category.dto';
|
import { CreateCategoryDto, QueryCategoryDto, UpdateCategoryDto } from '../dtos/category.dto';
|
||||||
import { CategoryService } from '../services';
|
import { CategoryService } from '../services';
|
||||||
|
|
||||||
@ -33,7 +31,7 @@ export class CategoryController {
|
|||||||
@Get()
|
@Get()
|
||||||
@SerializeOptions({ groups: ['category-list'] })
|
@SerializeOptions({ groups: ['category-list'] })
|
||||||
async list(
|
async list(
|
||||||
@Query(new ValidationPipe(DEFAULT_VALIDATION_CONFIG))
|
@Query()
|
||||||
options: QueryCategoryDto,
|
options: QueryCategoryDto,
|
||||||
) {
|
) {
|
||||||
return this.service.paginate(options);
|
return this.service.paginate(options);
|
||||||
@ -48,12 +46,7 @@ export class CategoryController {
|
|||||||
@Post()
|
@Post()
|
||||||
@SerializeOptions({ groups: ['category-detail'] })
|
@SerializeOptions({ groups: ['category-detail'] })
|
||||||
async store(
|
async store(
|
||||||
@Body(
|
@Body()
|
||||||
new ValidationPipe({
|
|
||||||
...DEFAULT_VALIDATION_CONFIG,
|
|
||||||
groups: ['create'],
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
data: CreateCategoryDto,
|
data: CreateCategoryDto,
|
||||||
) {
|
) {
|
||||||
return this.service.create(data);
|
return this.service.create(data);
|
||||||
@ -62,12 +55,7 @@ export class CategoryController {
|
|||||||
@Patch()
|
@Patch()
|
||||||
@SerializeOptions({ groups: ['category-detail'] })
|
@SerializeOptions({ groups: ['category-detail'] })
|
||||||
async update(
|
async update(
|
||||||
@Body(
|
@Body()
|
||||||
new ValidationPipe({
|
|
||||||
...DEFAULT_VALIDATION_CONFIG,
|
|
||||||
groups: ['update'],
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
data: UpdateCategoryDto,
|
data: UpdateCategoryDto,
|
||||||
) {
|
) {
|
||||||
return this.service.update(data);
|
return this.service.update(data);
|
||||||
|
@ -9,14 +9,10 @@ import {
|
|||||||
Query,
|
Query,
|
||||||
SerializeOptions,
|
SerializeOptions,
|
||||||
UseInterceptors,
|
UseInterceptors,
|
||||||
ValidationPipe,
|
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
|
|
||||||
import { pick } from 'lodash';
|
|
||||||
|
|
||||||
import { AppInterceptor } from '@/modules/core/providers/app.interceptor';
|
import { AppInterceptor } from '@/modules/core/providers/app.interceptor';
|
||||||
|
|
||||||
import { DEFAULT_VALIDATION_CONFIG } from '../constants';
|
|
||||||
import { CreateCommentDto, QueryCommentDto, QueryCommentTreeDto } from '../dtos/comment.dto';
|
import { CreateCommentDto, QueryCommentDto, QueryCommentTreeDto } from '../dtos/comment.dto';
|
||||||
import { CommentService } from '../services';
|
import { CommentService } from '../services';
|
||||||
|
|
||||||
@ -27,18 +23,14 @@ export class CommentController {
|
|||||||
|
|
||||||
@Get('tree')
|
@Get('tree')
|
||||||
@SerializeOptions({ groups: ['comment-tree'] })
|
@SerializeOptions({ groups: ['comment-tree'] })
|
||||||
async tree(@Query(new ValidationPipe(DEFAULT_VALIDATION_CONFIG)) options: QueryCommentTreeDto) {
|
async tree(@Query() options: QueryCommentTreeDto) {
|
||||||
return this.service.findTrees(options);
|
return this.service.findTrees(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@SerializeOptions({ groups: ['comment-list'] })
|
@SerializeOptions({ groups: ['comment-list'] })
|
||||||
async list(
|
async list(
|
||||||
@Query(
|
@Query()
|
||||||
new ValidationPipe({
|
|
||||||
...pick(DEFAULT_VALIDATION_CONFIG, ['forbidNonWhitelisted', 'whitelist']),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
options: QueryCommentDto,
|
options: QueryCommentDto,
|
||||||
) {
|
) {
|
||||||
return this.service.paginate(options);
|
return this.service.paginate(options);
|
||||||
@ -46,7 +38,7 @@ export class CommentController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@SerializeOptions({ groups: ['comment-detail'] })
|
@SerializeOptions({ groups: ['comment-detail'] })
|
||||||
async store(@Body(new ValidationPipe(DEFAULT_VALIDATION_CONFIG)) data: CreateCommentDto) {
|
async store(@Body() data: CreateCommentDto) {
|
||||||
return this.service.create(data);
|
return this.service.create(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,15 +10,12 @@ import {
|
|||||||
Query,
|
Query,
|
||||||
SerializeOptions,
|
SerializeOptions,
|
||||||
UseInterceptors,
|
UseInterceptors,
|
||||||
ValidationPipe,
|
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
|
|
||||||
import { CreatePostDto, QueryPostDto, UpdatePostDto } from '@/modules/content/dtos/post.dto';
|
import { CreatePostDto, QueryPostDto, UpdatePostDto } from '@/modules/content/dtos/post.dto';
|
||||||
import { PostService } from '@/modules/content/services/post.service';
|
import { PostService } from '@/modules/content/services/post.service';
|
||||||
import { AppInterceptor } from '@/modules/core/providers/app.interceptor';
|
import { AppInterceptor } from '@/modules/core/providers/app.interceptor';
|
||||||
|
|
||||||
import { DEFAULT_VALIDATION_CONFIG } from '../constants';
|
|
||||||
|
|
||||||
@UseInterceptors(AppInterceptor)
|
@UseInterceptors(AppInterceptor)
|
||||||
@Controller('posts')
|
@Controller('posts')
|
||||||
export class PostController {
|
export class PostController {
|
||||||
@ -27,7 +24,7 @@ export class PostController {
|
|||||||
@Get()
|
@Get()
|
||||||
@SerializeOptions({ groups: ['post-list'] })
|
@SerializeOptions({ groups: ['post-list'] })
|
||||||
async list(
|
async list(
|
||||||
@Query(new ValidationPipe(DEFAULT_VALIDATION_CONFIG))
|
@Query()
|
||||||
options: QueryPostDto,
|
options: QueryPostDto,
|
||||||
) {
|
) {
|
||||||
return this.postService.paginate(options);
|
return this.postService.paginate(options);
|
||||||
@ -42,12 +39,7 @@ export class PostController {
|
|||||||
@Post()
|
@Post()
|
||||||
@SerializeOptions({ groups: ['post-detail'] })
|
@SerializeOptions({ groups: ['post-detail'] })
|
||||||
async store(
|
async store(
|
||||||
@Body(
|
@Body()
|
||||||
new ValidationPipe({
|
|
||||||
...DEFAULT_VALIDATION_CONFIG,
|
|
||||||
groups: ['create'],
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
data: CreatePostDto,
|
data: CreatePostDto,
|
||||||
) {
|
) {
|
||||||
return this.postService.create(data);
|
return this.postService.create(data);
|
||||||
@ -56,12 +48,7 @@ export class PostController {
|
|||||||
@Patch()
|
@Patch()
|
||||||
@SerializeOptions({ groups: ['post-detail'] })
|
@SerializeOptions({ groups: ['post-detail'] })
|
||||||
async update(
|
async update(
|
||||||
@Body(
|
@Body()
|
||||||
new ValidationPipe({
|
|
||||||
...DEFAULT_VALIDATION_CONFIG,
|
|
||||||
groups: ['update'],
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
data: UpdatePostDto,
|
data: UpdatePostDto,
|
||||||
) {
|
) {
|
||||||
return this.postService.update(data);
|
return this.postService.update(data);
|
||||||
|
@ -10,12 +10,10 @@ import {
|
|||||||
Query,
|
Query,
|
||||||
SerializeOptions,
|
SerializeOptions,
|
||||||
UseInterceptors,
|
UseInterceptors,
|
||||||
ValidationPipe,
|
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
|
|
||||||
import { AppInterceptor } from '@/modules/core/providers/app.interceptor';
|
import { AppInterceptor } from '@/modules/core/providers/app.interceptor';
|
||||||
|
|
||||||
import { DEFAULT_VALIDATION_CONFIG } from '../constants';
|
|
||||||
import { CreateTagDto, QueryTagDto, UpdateTagDto } from '../dtos/tag.dto';
|
import { CreateTagDto, QueryTagDto, UpdateTagDto } from '../dtos/tag.dto';
|
||||||
import { TagService } from '../services';
|
import { TagService } from '../services';
|
||||||
|
|
||||||
@ -27,7 +25,7 @@ export class TagController {
|
|||||||
@Get()
|
@Get()
|
||||||
@SerializeOptions({})
|
@SerializeOptions({})
|
||||||
async list(
|
async list(
|
||||||
@Query(new ValidationPipe(DEFAULT_VALIDATION_CONFIG))
|
@Query()
|
||||||
options: QueryTagDto,
|
options: QueryTagDto,
|
||||||
) {
|
) {
|
||||||
return this.service.paginate(options);
|
return this.service.paginate(options);
|
||||||
@ -42,7 +40,7 @@ export class TagController {
|
|||||||
@Post()
|
@Post()
|
||||||
@SerializeOptions({})
|
@SerializeOptions({})
|
||||||
async store(
|
async store(
|
||||||
@Body(new ValidationPipe({ ...DEFAULT_VALIDATION_CONFIG, groups: ['create'] }))
|
@Body()
|
||||||
data: CreateTagDto,
|
data: CreateTagDto,
|
||||||
) {
|
) {
|
||||||
return this.service.create(data);
|
return this.service.create(data);
|
||||||
@ -51,7 +49,7 @@ export class TagController {
|
|||||||
@Patch()
|
@Patch()
|
||||||
@SerializeOptions({})
|
@SerializeOptions({})
|
||||||
async update(
|
async update(
|
||||||
@Body(new ValidationPipe({ ...DEFAULT_VALIDATION_CONFIG, groups: ['update'] }))
|
@Body()
|
||||||
date: UpdateTagDto,
|
date: UpdateTagDto,
|
||||||
) {
|
) {
|
||||||
return this.service.update(date);
|
return this.service.update(date);
|
||||||
|
@ -12,8 +12,10 @@ import {
|
|||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
import { toNumber } from 'lodash';
|
import { toNumber } from 'lodash';
|
||||||
|
|
||||||
|
import { DtoValidation } from '@/modules/core/decorator/dto.validation.decorator';
|
||||||
import { PaginateOptions } from '@/modules/database/types';
|
import { PaginateOptions } from '@/modules/database/types';
|
||||||
|
|
||||||
|
@DtoValidation({ type: 'query' })
|
||||||
export class QueryCategoryDto implements PaginateOptions {
|
export class QueryCategoryDto implements PaginateOptions {
|
||||||
@Transform(({ value }) => toNumber(value))
|
@Transform(({ value }) => toNumber(value))
|
||||||
@Min(1, { message: 'The current page must be greater than 1.' })
|
@Min(1, { message: 'The current page must be greater than 1.' })
|
||||||
@ -28,6 +30,7 @@ export class QueryCategoryDto implements PaginateOptions {
|
|||||||
limit = 10;
|
limit = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DtoValidation({ groups: ['create'] })
|
||||||
export class CreateCategoryDto {
|
export class CreateCategoryDto {
|
||||||
@MaxLength(25, {
|
@MaxLength(25, {
|
||||||
always: true,
|
always: true,
|
||||||
@ -53,6 +56,7 @@ export class CreateCategoryDto {
|
|||||||
customOrder?: number = 0;
|
customOrder?: number = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DtoValidation({ groups: ['update'] })
|
||||||
export class UpdateCategoryDto extends PartialType(CreateCategoryDto) {
|
export class UpdateCategoryDto extends PartialType(CreateCategoryDto) {
|
||||||
@IsUUID(undefined, { message: 'The ID format is incorrect', groups: ['update'] })
|
@IsUUID(undefined, { message: 'The ID format is incorrect', groups: ['update'] })
|
||||||
@IsDefined({ groups: ['update'], message: 'The ID must be specified' })
|
@IsDefined({ groups: ['update'], message: 'The ID must be specified' })
|
||||||
|
@ -12,8 +12,10 @@ import {
|
|||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
import { toNumber } from 'lodash';
|
import { toNumber } from 'lodash';
|
||||||
|
|
||||||
|
import { DtoValidation } from '@/modules/core/decorator/dto.validation.decorator';
|
||||||
import { PaginateOptions } from '@/modules/database/types';
|
import { PaginateOptions } from '@/modules/database/types';
|
||||||
|
|
||||||
|
@DtoValidation({ type: 'query' })
|
||||||
export class QueryCommentDto implements PaginateOptions {
|
export class QueryCommentDto implements PaginateOptions {
|
||||||
@Transform(({ value }) => toNumber(value))
|
@Transform(({ value }) => toNumber(value))
|
||||||
@Min(1, { message: 'The current page must be greater than 1.' })
|
@Min(1, { message: 'The current page must be greater than 1.' })
|
||||||
@ -32,8 +34,10 @@ export class QueryCommentDto implements PaginateOptions {
|
|||||||
post?: string;
|
post?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DtoValidation({ type: 'query' })
|
||||||
export class QueryCommentTreeDto extends PickType(QueryCommentDto, ['post']) {}
|
export class QueryCommentTreeDto extends PickType(QueryCommentDto, ['post']) {}
|
||||||
|
|
||||||
|
@DtoValidation()
|
||||||
export class CreateCommentDto {
|
export class CreateCommentDto {
|
||||||
@MaxLength(1000, { message: '' })
|
@MaxLength(1000, { message: '' })
|
||||||
@IsNotEmpty({ message: '' })
|
@IsNotEmpty({ message: '' })
|
||||||
|
@ -17,9 +17,11 @@ import {
|
|||||||
import { isNil, toNumber } from 'lodash';
|
import { isNil, toNumber } from 'lodash';
|
||||||
|
|
||||||
import { PostOrder } from '@/modules/content/constants';
|
import { PostOrder } from '@/modules/content/constants';
|
||||||
|
import { DtoValidation } from '@/modules/core/decorator/dto.validation.decorator';
|
||||||
import { toBoolean } from '@/modules/core/helpers';
|
import { toBoolean } from '@/modules/core/helpers';
|
||||||
import { PaginateOptions } from '@/modules/database/types';
|
import { PaginateOptions } from '@/modules/database/types';
|
||||||
|
|
||||||
|
@DtoValidation({ type: 'query' })
|
||||||
export class QueryPostDto implements PaginateOptions {
|
export class QueryPostDto implements PaginateOptions {
|
||||||
@Transform(({ value }) => toBoolean(value))
|
@Transform(({ value }) => toBoolean(value))
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@ -53,6 +55,7 @@ export class QueryPostDto implements PaginateOptions {
|
|||||||
tag?: string;
|
tag?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DtoValidation({ groups: ['create'] })
|
||||||
export class CreatePostDto {
|
export class CreatePostDto {
|
||||||
@MaxLength(255, {
|
@MaxLength(255, {
|
||||||
always: true,
|
always: true,
|
||||||
@ -109,6 +112,7 @@ export class CreatePostDto {
|
|||||||
tags?: string[];
|
tags?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DtoValidation({ groups: ['update'] })
|
||||||
export class UpdatePostDto extends PartialType(CreatePostDto) {
|
export class UpdatePostDto extends PartialType(CreatePostDto) {
|
||||||
@IsUUID(undefined, {
|
@IsUUID(undefined, {
|
||||||
groups: ['update'],
|
groups: ['update'],
|
||||||
|
@ -11,8 +11,10 @@ import {
|
|||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
import { toNumber } from 'lodash';
|
import { toNumber } from 'lodash';
|
||||||
|
|
||||||
|
import { DtoValidation } from '@/modules/core/decorator/dto.validation.decorator';
|
||||||
import { PaginateOptions } from '@/modules/database/types';
|
import { PaginateOptions } from '@/modules/database/types';
|
||||||
|
|
||||||
|
@DtoValidation({ type: 'query' })
|
||||||
export class QueryTagDto implements PaginateOptions {
|
export class QueryTagDto implements PaginateOptions {
|
||||||
@Transform(({ value }) => toNumber(value))
|
@Transform(({ value }) => toNumber(value))
|
||||||
@Min(1, { message: 'The current page must be greater than 1.' })
|
@Min(1, { message: 'The current page must be greater than 1.' })
|
||||||
@ -27,6 +29,7 @@ export class QueryTagDto implements PaginateOptions {
|
|||||||
limit = 10;
|
limit = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DtoValidation({ groups: ['create'] })
|
||||||
export class CreateTagDto {
|
export class CreateTagDto {
|
||||||
@MaxLength(255, {
|
@MaxLength(255, {
|
||||||
always: true,
|
always: true,
|
||||||
@ -44,6 +47,7 @@ export class CreateTagDto {
|
|||||||
desc?: string;
|
desc?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DtoValidation({ groups: ['update'] })
|
||||||
export class UpdateTagDto extends PartialType(CreateTagDto) {
|
export class UpdateTagDto extends PartialType(CreateTagDto) {
|
||||||
@IsUUID(undefined, { message: 'The ID format is incorrect', groups: ['update'] })
|
@IsUUID(undefined, { message: 'The ID format is incorrect', groups: ['update'] })
|
||||||
@IsDefined({ groups: ['update'], message: 'The ID must be specified' })
|
@IsDefined({ groups: ['update'], message: 'The ID must be specified' })
|
||||||
|
1
src/modules/core/contants.ts
Normal file
1
src/modules/core/contants.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export const DTO_VALIDATION_OPTIONS = 'dto_validation_options';
|
11
src/modules/core/decorator/dto.validation.decorator.ts
Normal file
11
src/modules/core/decorator/dto.validation.decorator.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { Paramtype, SetMetadata } from '@nestjs/common';
|
||||||
|
import { ClassTransformOptions } from 'class-transformer';
|
||||||
|
import { ValidationOptions } from 'class-validator';
|
||||||
|
|
||||||
|
import { DTO_VALIDATION_OPTIONS } from '../contants';
|
||||||
|
|
||||||
|
export const DtoValidation = (
|
||||||
|
options?: ValidationOptions & { transformOptions?: ClassTransformOptions } & {
|
||||||
|
type?: Paramtype;
|
||||||
|
},
|
||||||
|
) => SetMetadata(DTO_VALIDATION_OPTIONS, options ?? {});
|
59
src/modules/core/providers/app.pipe.ts
Normal file
59
src/modules/core/providers/app.pipe.ts
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import { ArgumentMetadata, BadRequestException, Paramtype, ValidationPipe } from '@nestjs/common';
|
||||||
|
|
||||||
|
import { isObject, omit } from 'lodash';
|
||||||
|
|
||||||
|
import { DTO_VALIDATION_OPTIONS } from '../contants';
|
||||||
|
import { deepMerge } from '../helpers';
|
||||||
|
|
||||||
|
export class AppPipe extends ValidationPipe {
|
||||||
|
async transform(value: any, metadata: ArgumentMetadata): Promise<any> {
|
||||||
|
const { metatype, type } = metadata;
|
||||||
|
const dto = metatype as any;
|
||||||
|
const options = Reflect.getMetadata(DTO_VALIDATION_OPTIONS, dto) || {};
|
||||||
|
const originOptions = { ...this.validatorOptions };
|
||||||
|
const originTransform = { ...this.transformOptions };
|
||||||
|
const { transformOptions, type: optionsType, ...customOptions } = options;
|
||||||
|
const requestBody: Paramtype = optionsType ?? 'body';
|
||||||
|
if (requestBody !== type) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
if (transformOptions) {
|
||||||
|
this.transformOptions = deepMerge(
|
||||||
|
this.transformOptions,
|
||||||
|
transformOptions ?? {},
|
||||||
|
'replace',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.validatorOptions = deepMerge(this.validatorOptions, customOptions ?? {}, 'replace');
|
||||||
|
const toValidate = isObject(value)
|
||||||
|
? Object.fromEntries(
|
||||||
|
Object.entries(value as RecordAny).map(([key, val]) => {
|
||||||
|
if (isObject(val) && 'mimetype' in val) {
|
||||||
|
return [key, omit(val, ['fields'])];
|
||||||
|
}
|
||||||
|
return [key, val];
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
: value;
|
||||||
|
console.log(value);
|
||||||
|
console.log(toValidate);
|
||||||
|
try {
|
||||||
|
let result = await super.transform(toValidate, metadata);
|
||||||
|
if (typeof result.transform === 'function') {
|
||||||
|
result = await result.transform(result);
|
||||||
|
const { transform, ...data } = result;
|
||||||
|
result = data;
|
||||||
|
}
|
||||||
|
this.validatorOptions = originOptions;
|
||||||
|
this.transformOptions = originTransform;
|
||||||
|
return result;
|
||||||
|
} catch (error: any) {
|
||||||
|
this.validatorOptions = originOptions;
|
||||||
|
this.transformOptions = originTransform;
|
||||||
|
if ('response' in error) {
|
||||||
|
throw new BadRequestException(error.response);
|
||||||
|
}
|
||||||
|
throw new BadRequestException(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user