From 8297a9704787211a01a7d9c05998e0e927308500 Mon Sep 17 00:00:00 2001 From: SeungWon Date: Thu, 25 Apr 2024 11:28:09 -0700 Subject: [PATCH] :sparkles: write api docs --- src/profile/dto/profile.dto.ts | 8 +++++++- src/profile/profile.controller.ts | 12 +++++++++--- src/profile/profile.service.ts | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/profile/dto/profile.dto.ts b/src/profile/dto/profile.dto.ts index 53c3ef35d8..789c6e9139 100644 --- a/src/profile/dto/profile.dto.ts +++ b/src/profile/dto/profile.dto.ts @@ -32,7 +32,13 @@ export class ProfileDto { readonly githubLink: string; } -export class GetProfileDto extends ProfileDto { +export class GetProfileDto { + @Type(() => ProfileDto) + @ApiProperty({ + type: ProfileDto, + }) + readonly profile: ProfileDto; + @Type(() => ProfileDto) @ApiProperty({ type: [ProfileDto], diff --git a/src/profile/profile.controller.ts b/src/profile/profile.controller.ts index b489f934e0..dd3b95d4e2 100644 --- a/src/profile/profile.controller.ts +++ b/src/profile/profile.controller.ts @@ -12,7 +12,13 @@ import { ProfileService } from './profile.service'; import { JwtAuthGuard } from 'src/user/user.guard'; import { GetUser } from 'src/user/decorators/GetUser.decorator'; import { Payload } from 'src/user/dto/jwt-payload.dto'; -import { ApiBearerAuth, ApiBody, ApiParam, ApiResponse } from '@nestjs/swagger'; +import { + ApiBearerAuth, + ApiBody, + ApiParam, + ApiResponse, + getSchemaPath, +} from '@nestjs/swagger'; import { GetProfileDto, ProfileDto } from './dto/profile.dto'; @Controller('profile') @@ -35,13 +41,13 @@ export class ProfileController { async getProfile( @Param('id') id: number, @GetUser() user: Payload, - ): Promise<{ profile: GetProfileDto | null }> { + ): Promise { if (id !== user.userId) { throw new ForbiddenException( 'You do not have permission to access this profile', ); } - return { profile: await this.profileService.getProfile(id) }; + return await this.profileService.getProfile(id); } @Post('/:id') diff --git a/src/profile/profile.service.ts b/src/profile/profile.service.ts index ce5551decf..e1838d5271 100644 --- a/src/profile/profile.service.ts +++ b/src/profile/profile.service.ts @@ -52,7 +52,7 @@ export class ProfileService { likedByUsers.push(likedProfile); }); const profileData: GetProfileDto = { - ...profile, + profile, likedProjects, likedByUsers, };