Skip to content

Commit

Permalink
✨ write api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
KMUlee committed Apr 25, 2024
1 parent e5c4cca commit 8297a97
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/profile/dto/profile.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
12 changes: 9 additions & 3 deletions src/profile/profile.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -35,13 +41,13 @@ export class ProfileController {
async getProfile(
@Param('id') id: number,
@GetUser() user: Payload,
): Promise<{ profile: GetProfileDto | null }> {
): Promise<GetProfileDto | null> {
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')
Expand Down
2 changes: 1 addition & 1 deletion src/profile/profile.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class ProfileService {
likedByUsers.push(likedProfile);
});
const profileData: GetProfileDto = {
...profile,
profile,
likedProjects,
likedByUsers,
};
Expand Down

0 comments on commit 8297a97

Please sign in to comment.