Skip to content

Commit

Permalink
Merge pull request #13628 from tomflorentin/master
Browse files Browse the repository at this point in the history
chore(class-transformer): plainToClass is deprectated and replaced with plainToInstance
  • Loading branch information
kamilmysliwiec authored Nov 7, 2024
2 parents 0f38439 + 9b690d9 commit 6ea78d5
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/common/pipes/validation.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/common/serializer/class-serializer.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class ClassSerializerInterceptor implements NestInterceptor {
if (plainOrClass instanceof options.type) {
return classTransformer.classToPlain(plainOrClass, options);
}
const instance = classTransformer.plainToClass(
const instance = classTransformer.plainToInstance(
options.type,
plainOrClass,
options,
Expand Down
4 changes: 2 additions & 2 deletions sample/01-cats-app/src/common/pipes/validation.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions sample/10-fastify/src/common/pipes/validation.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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');
Expand Down

0 comments on commit 6ea78d5

Please sign in to comment.