mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
plain to class deprectated
This commit is contained in:
@@ -2,7 +2,7 @@ import { Type } from '../type.interface';
|
||||
import { ClassTransformOptions } from './class-transform-options.interface';
|
||||
|
||||
export interface TransformerPackage {
|
||||
plainToClass<T>(
|
||||
plainToInstance<T>(
|
||||
cls: Type<T>,
|
||||
plain: unknown,
|
||||
options?: ClassTransformOptions,
|
||||
|
||||
@@ -121,7 +121,7 @@ export class ValidationPipe implements PipeTransform<any> {
|
||||
const isNil = value !== originalValue;
|
||||
const isPrimitive = this.isPrimitive(value);
|
||||
this.stripProtoKeys(value);
|
||||
let entity = classTransformer.plainToClass(
|
||||
let entity = classTransformer.plainToInstance(
|
||||
metatype,
|
||||
value,
|
||||
this.transformOptions,
|
||||
|
||||
@@ -94,7 +94,7 @@ export class ClassSerializerInterceptor implements NestInterceptor {
|
||||
if (plainOrClass instanceof options.type) {
|
||||
return classTransformer.classToPlain(plainOrClass, options);
|
||||
}
|
||||
const instance = classTransformer.plainToClass(options.type, plainOrClass);
|
||||
const instance = classTransformer.plainToInstance(options.type, plainOrClass);
|
||||
return classTransformer.classToPlain(instance, options);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
PipeTransform,
|
||||
Type,
|
||||
} from '@nestjs/common';
|
||||
import { plainToClass } from 'class-transformer';
|
||||
import { plainToInstance } from 'class-transformer';
|
||||
import { validate } from 'class-validator';
|
||||
|
||||
@Injectable()
|
||||
@@ -15,7 +15,7 @@ export class ValidationPipe implements PipeTransform<any> {
|
||||
if (!metatype || !this.toValidate(metatype)) {
|
||||
return value;
|
||||
}
|
||||
const object = plainToClass(metatype, value);
|
||||
const object = plainToInstance(metatype, value);
|
||||
const errors = await validate(object);
|
||||
if (errors.length > 0) {
|
||||
throw new BadRequestException('Validation failed');
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
PipeTransform,
|
||||
Type,
|
||||
} from '@nestjs/common';
|
||||
import { plainToClass } from 'class-transformer';
|
||||
import { plainToInstance } from 'class-transformer';
|
||||
import { validate } from 'class-validator';
|
||||
|
||||
@Injectable()
|
||||
@@ -15,7 +15,7 @@ export class ValidationPipe implements PipeTransform<any> {
|
||||
if (!metatype || !this.toValidate(metatype)) {
|
||||
return value;
|
||||
}
|
||||
const object = plainToClass(metatype, value);
|
||||
const object = plainToInstance(metatype, value);
|
||||
const errors = await validate(object);
|
||||
if (errors.length > 0) {
|
||||
throw new BadRequestException('Validation failed');
|
||||
|
||||
Reference in New Issue
Block a user