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';
|
import { ClassTransformOptions } from './class-transform-options.interface';
|
||||||
|
|
||||||
export interface TransformerPackage {
|
export interface TransformerPackage {
|
||||||
plainToClass<T>(
|
plainToInstance<T>(
|
||||||
cls: Type<T>,
|
cls: Type<T>,
|
||||||
plain: unknown,
|
plain: unknown,
|
||||||
options?: ClassTransformOptions,
|
options?: ClassTransformOptions,
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ export class ValidationPipe implements PipeTransform<any> {
|
|||||||
const isNil = value !== originalValue;
|
const isNil = value !== originalValue;
|
||||||
const isPrimitive = this.isPrimitive(value);
|
const isPrimitive = this.isPrimitive(value);
|
||||||
this.stripProtoKeys(value);
|
this.stripProtoKeys(value);
|
||||||
let entity = classTransformer.plainToClass(
|
let entity = classTransformer.plainToInstance(
|
||||||
metatype,
|
metatype,
|
||||||
value,
|
value,
|
||||||
this.transformOptions,
|
this.transformOptions,
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ export class ClassSerializerInterceptor implements NestInterceptor {
|
|||||||
if (plainOrClass instanceof options.type) {
|
if (plainOrClass instanceof options.type) {
|
||||||
return classTransformer.classToPlain(plainOrClass, options);
|
return classTransformer.classToPlain(plainOrClass, options);
|
||||||
}
|
}
|
||||||
const instance = classTransformer.plainToClass(options.type, plainOrClass);
|
const instance = classTransformer.plainToInstance(options.type, plainOrClass);
|
||||||
return classTransformer.classToPlain(instance, options);
|
return classTransformer.classToPlain(instance, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
PipeTransform,
|
PipeTransform,
|
||||||
Type,
|
Type,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { plainToClass } from 'class-transformer';
|
import { plainToInstance } from 'class-transformer';
|
||||||
import { validate } from 'class-validator';
|
import { validate } from 'class-validator';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -15,7 +15,7 @@ export class ValidationPipe implements PipeTransform<any> {
|
|||||||
if (!metatype || !this.toValidate(metatype)) {
|
if (!metatype || !this.toValidate(metatype)) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
const object = plainToClass(metatype, value);
|
const object = plainToInstance(metatype, value);
|
||||||
const errors = await validate(object);
|
const errors = await validate(object);
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
throw new BadRequestException('Validation failed');
|
throw new BadRequestException('Validation failed');
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
PipeTransform,
|
PipeTransform,
|
||||||
Type,
|
Type,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { plainToClass } from 'class-transformer';
|
import { plainToInstance } from 'class-transformer';
|
||||||
import { validate } from 'class-validator';
|
import { validate } from 'class-validator';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -15,7 +15,7 @@ export class ValidationPipe implements PipeTransform<any> {
|
|||||||
if (!metatype || !this.toValidate(metatype)) {
|
if (!metatype || !this.toValidate(metatype)) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
const object = plainToClass(metatype, value);
|
const object = plainToInstance(metatype, value);
|
||||||
const errors = await validate(object);
|
const errors = await validate(object);
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
throw new BadRequestException('Validation failed');
|
throw new BadRequestException('Validation failed');
|
||||||
|
|||||||
Reference in New Issue
Block a user