I am trying to serialize my API response with @Transform() decorator from 'class-transformer' library. I am getting object from db using PrismaService, initialized with
`import { Injectable, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
@Exclude()
export class MyResponse {
@Transform(({ value }) => value.toNumber())
@Expose()
age: number;
}
age field is instance of Decimal from Decimal.js.
Expected behavior: Decimal to converts to number after value.toNumber() in @Transform() decorator callback.
Current behavior: [Nest] 20138 - 04/17/2024, 12:06:08 PM ERROR [ExceptionsHandler] [DecimalError] Invalid argument: undefined
Error: [DecimalError] Invalid argument: undefined
at new i (/Users/mypc/projects/someproject/my-project/node_modules/.pnpm/@prisma+client@5.11.0_prisma@5.11.0/node_modules/@prisma/client/runtime/library.js:23:29389)
Code execution is not even get into Transform decorator callback.
Packages versions: "@prisma/client": "5.11.0", "class-transformer": "0.5.1"
I am trying to serialize my API response with @Transform() decorator from 'class-transformer' library. I am getting object from db using PrismaService, initialized with
`import { Injectable, OnModuleInit } from '@nestjs/common'; import { PrismaClient } from '@prisma/client';
@Injectable() export class PrismaService extends PrismaClient implements OnModuleInit { async onModuleInit() { await this.$connect(); } }`
I have class for API response serialization:
@Exclude() export class MyResponse { @Transform(({ value }) => value.toNumber()) @Expose() age: number; }
age field is instance of Decimal from Decimal.js.
Expected behavior: Decimal to converts to number after value.toNumber() in @Transform() decorator callback.
Current behavior: [Nest] 20138 - 04/17/2024, 12:06:08 PM ERROR [ExceptionsHandler] [DecimalError] Invalid argument: undefined Error: [DecimalError] Invalid argument: undefined at new i (/Users/mypc/projects/someproject/my-project/node_modules/.pnpm/@prisma+client@5.11.0_prisma@5.11.0/node_modules/@prisma/client/runtime/library.js:23:29389) Code execution is not even get into Transform decorator callback.