【问题标题】:How to serialize Prisma Object in NestJS?如何在 NestJS 中序列化 Prisma 对象?
【发布时间】:2021-11-08 22:53:38
【问题描述】:

我尝试过使用 Class Transformer,但它没有任何意义,因为 Prisma 不需要 Entity,而且 Prisma Type 不能是 Exclude() 有没有办法从 Prisma 对象中排除密钥,例如createdAt 还是密码?谢谢

【问题讨论】:

    标签: nestjs prisma


    【解决方案1】:

    我是这样做的

    在文件中:user.entity.ts

    import { Role, User as UserPrisma } from '@prisma/client';
    import { Exclude } from 'class-transformer';
    
    export class User implements UserPrisma {
      id: string;
      name: string;
      email: string;
    
      @Exclude()
      password: string;
    
      @Exclude()
      role: Role;
    
      createdAt: Date;
      updatedAt: Date;
    }
    

    【讨论】:

      猜你喜欢
      • 2021-03-31
      • 2019-07-06
      • 2021-12-04
      • 2023-03-03
      • 2021-04-22
      • 2010-10-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多