How do you mange to document api response when using prisma and nestjs?

Viewed 252

Do have an idea about how you can document quickly an api response when using nestjs and prisma.

let's say I have

I have this controller

  @Get('/user-profile')
  @ApiOkResponse({ type: UserProfileResponse })
  getUserProfile(@payLoad() payLoad: JwtPayload): Promise<UserProfileResponse> {
    return this.userService.getUserProfile(payLoad);
  }

This service

  async getUserProfile(payLoad: JwtPayload): Promise<UserProfileResponse> {
    return await this.prisma.user.findUnique({
      where:{id:payLoad.userId},
      include: {
        address : { select: {city:true,}}     

      }
    })

  }

export class UserProfileResponse {
    id: string;
    username: string;
    firstName: string;
    lastName: string;
    address : AddressCity;
}

class AddressCity {
    city: string;
}

I will need to create a DTO to specify the response each time .Whith this example It's not a big deal but when we have deeply nested response object It became realy time consuming.

Do have like an idean to speed up this process ?

0 Answers
Related