Skip to content

Commit

Permalink
fix(crud-gen): dto transform (#31)
Browse files Browse the repository at this point in the history
We need to transform the plain data and not just do the `new`
  • Loading branch information
Yehonal authored Jan 8, 2024
1 parent 1c720a8 commit 217eeec
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions crud-gen/src/api-rest/crud-gen-rest.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ObjectMapperType } from '@nestjs-yalc/utils/object-mapper.helper.js';
import { buildSimpleMapperInterceptor } from '@nestjs-yalc/utils/simple-mapper.interceptor.js';
import { ClassType } from '@nestjs-yalc/types/globals.d.js';
import { Observable } from 'rxjs';
import { plainToInstance } from 'class-transformer';

export function crudGenRestPaginationInterceptorWorker<T>(
startRow?: number,
Expand Down Expand Up @@ -101,7 +102,7 @@ export function buildPaginatedResultDto<T>(
class NewPaginatedResultDto extends PaginatedResultDto<T> {
constructor(data: T[], pageData: PageData) {
super(
data.map((item) => new dto(item)),
data.map((item) => plainToInstance<T, any>(dto, item)),
pageData,
);
}
Expand Down Expand Up @@ -153,7 +154,7 @@ export function buildDTOInterceptor<T>(
intercept(_context: ExecutionContext, next: CallHandler): Observable<any> {
return next.handle().pipe(
map((data) => {
return new dto(data);
return plainToInstance<T, any>(dto, data);
}),
);
}
Expand Down

0 comments on commit 217eeec

Please sign in to comment.