-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support class transformer #26
Comments
Are there also some other use cases (except for Date)? Actually, I was thinking about to change the behavior of |
for now i'am only face use case for date. |
@Brakebein in my case I want to exclude the password from the response, e.g: import { Exclude } from 'class-transformer';
export class UserEntity {
id: number;
firstName: string;
lastName: string;
@Exclude()
password: string;
} I found it from NestJs documentation here Why is this necessary? I tried to change this line:
to be like this: return '@ApiHideProperty()\n@Exclude()\n'; assume when I use and I also change this line:
to be like this: const imp = [{ from: '@nestjs/swagger', destruct }];
if (hasApiHideProperty) imp.push({ from: 'class-transformer', destruct: ['Exclude'] })
return imp; it's works for me. import { ApiHideProperty, ApiProperty } from '@nestjs/swagger';
import { Exclude } from 'class-transformer';
export class User {
...
@ApiHideProperty()
@Exclude()
password: string;
} |
Interesting. I wasn't yet aware of this serialization and constructor(partial: Partial<UserEntity>) {
Object.assign(this, partial);
} So, this contructor should also be generated? Or how do you create and return the instance? In my own projects, I created a custom dto so far to exclude, for example, the password. But of course, it is not automatic. export class UserWithoutPasswordDto extends OmitType(UserDto, ['password']) {} |
Can you add class transformer custom annotation, because sometimes i need class transformer to transform input to other class type that i want
example :
input in prisma schema
expectend output
thank you
The text was updated successfully, but these errors were encountered: