diff --git a/src/app.controller.spec.ts b/src/app.controller.spec.ts deleted file mode 100644 index ccea57f..0000000 --- a/src/app.controller.spec.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; - -import { AppController } from './app.controller'; -import { AppService } from './app.service'; - -describe('AppController', () => { - let appController: AppController; - - beforeEach(async () => { - const app: TestingModule = await Test.createTestingModule({ - controllers: [AppController], - providers: [AppService], - }).compile(); - - appController = app.get(AppController); - }); - - describe('root', () => { - it('should return "Hello World!"', () => { - expect(appController.getHello()).toBe('Hello World!'); - }); - }); -}); diff --git a/src/app.controller.ts b/src/app.controller.ts deleted file mode 100644 index c0b2a71..0000000 --- a/src/app.controller.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { Controller, Get, InternalServerErrorException } from '@nestjs/common'; -import { ApiBearerAuth } from '@nestjs/swagger'; - -import { AppService } from './app.service'; -import { UseAuthGuard } from './common/decorators/auth-guard.decorator'; -import { CurrentUser } from './common/decorators/user.decorator'; -import { User, UserRole } from './entities'; - -@Controller() -export class AppController { - constructor(private readonly appService: AppService) {} - - @Get() - getHello(): string { - throw new InternalServerErrorException('First issue'); - - return this.appService.getHello(); - } - - @Get('/me') - @UseAuthGuard([UserRole.USER]) - @ApiBearerAuth() - getMe(@CurrentUser() user: User): User { - return user; - } -} diff --git a/src/app.module.ts b/src/app.module.ts index df3e718..1bed527 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -6,8 +6,6 @@ import { MikroOrmModule } from '@mikro-orm/nestjs'; import { LoggerMiddleware } from 'src/core/intercepters/logging.interceptor'; import { InviteLinkModule } from 'src/invite-link/invite-link.module'; -import { AppController } from './app.controller'; -import { AppService } from './app.service'; import { AuthModule } from './auth/auth.module'; import { getNodeEnv, isIgnoreEnvFile } from './common/helper/env.helper'; import { envValidation } from './common/helper/env.validation'; @@ -39,8 +37,8 @@ import { UtilModule } from './util/util.module'; PlaceModule, InviteLinkModule, ], - controllers: [AppController], - providers: [AppService], + controllers: [], + providers: [], }) export class AppModule implements NestModule { configure(consumer: MiddlewareConsumer): void { diff --git a/src/app.service.ts b/src/app.service.ts deleted file mode 100644 index 927d7cc..0000000 --- a/src/app.service.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Injectable } from '@nestjs/common'; - -@Injectable() -export class AppService { - getHello(): string { - return 'Hello World!'; - } -} diff --git a/src/map/map.controller.ts b/src/map/map.controller.ts index e97b9e3..9668f66 100644 --- a/src/map/map.controller.ts +++ b/src/map/map.controller.ts @@ -2,7 +2,6 @@ import { BadRequestException, Body, Controller, - Delete, Get, Param, Patch, @@ -38,7 +37,7 @@ export class MapController { @Post() @ApiOkResponse({ type: MapItemForUserDto }) - @ApiOperation({ summary: '새 지도를 생성합니다' }) + @ApiOperation({ summary: '새 지도를 생성합니다.' }) @ApiBearerAuth() @UseAuthGuard([UserRole.USER]) create(@Body() createMapDto: CreateMapDto, @CurrentUser() user: User) { @@ -53,7 +52,7 @@ export class MapController { } @Get() - @ApiOperation({ summary: '사용자가 속해있는 지도를 가져옵니다' }) + @ApiOperation({ summary: '사용자가 속해있는 지도를 가져옵니다.' }) @ApiOkResponse({ type: [MapItemForUserDto] }) @ApiBearerAuth() @UseAuthGuard([UserRole.USER]) @@ -90,6 +89,10 @@ export class MapController { // } @Post(':id/invite-links') + @ApiOperation({ + summary: '지도의 초대링크를 생성합니다.', + description: '유효기간은 7일로 설정되어 있습니다.', + }) @ApiResponse({ type: InviteLinkResponseDto }) @ApiBearerAuth() @UseMapRoleGuard([UserMapRole.ADMIN]) diff --git a/src/user/dtos/user-response.dto.ts b/src/user/dtos/user-response.dto.ts index a5eaa7e..d066596 100644 --- a/src/user/dtos/user-response.dto.ts +++ b/src/user/dtos/user-response.dto.ts @@ -30,3 +30,14 @@ export class UserResponseDto implements Partial> { @IsNotEmpty() role: UserRoleValueType; } + +export function toUserResponseDto(user: User): UserResponseDto { + const userResponse = new UserResponseDto(); + userResponse.id = user.id; + userResponse.nickname = user.nickname; + userResponse.provider = user.provider; + userResponse.providerId = user.providerId; + userResponse.role = user.role; + + return userResponse; +} diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts index 5fdc9f3..e346ecd 100644 --- a/src/user/user.controller.ts +++ b/src/user/user.controller.ts @@ -7,14 +7,20 @@ import { Patch, Query, } from '@nestjs/common'; -import { ApiBearerAuth, ApiOkResponse, ApiTags } from '@nestjs/swagger'; +import { + ApiBearerAuth, + ApiExcludeEndpoint, + ApiOkResponse, + ApiOperation, + ApiTags, +} from '@nestjs/swagger'; import { UseAuthGuard } from 'src/common/decorators/auth-guard.decorator'; import { CurrentUser } from 'src/common/decorators/user.decorator'; import { User, UserRole } from 'src/entities'; import { UpdateUserRequestDto } from './dtos/update-user.dto'; -import { UserResponseDto } from './dtos/user-response.dto'; +import { UserResponseDto, toUserResponseDto } from './dtos/user-response.dto'; import { UserService } from './user.service'; @ApiTags('users') @@ -22,34 +28,47 @@ import { UserService } from './user.service'; export class UserController { constructor(private readonly userService: UserService) {} - @Get(':id') + @Get('me') + @ApiOperation({ summary: '내 정보를 조회합니다.' }) @UseAuthGuard([UserRole.USER]) @ApiOkResponse({ type: UserResponseDto }) @ApiBearerAuth() - async findOne(@Param('id') id: string) { - const user = await this.userService.findOne({ id: +id }); - return user; + getMe(@CurrentUser() user: User): UserResponseDto { + return toUserResponseDto(user); } - @Patch() + @Patch('me') + @ApiOperation({ summary: '내 정보를 수정합니다.' }) @UseAuthGuard([UserRole.USER]) @ApiOkResponse({ type: UserResponseDto }) @ApiBearerAuth() - async update( + async updateMe( @Body() updateUserDto: UpdateUserRequestDto, @CurrentUser() user: User, - ) { - return await this.userService.update(+user.id, updateUserDto); + ): Promise { + const updatedUser = await this.userService.update(user.id, user); + return toUserResponseDto(updatedUser); + } + + @Get(':id') + @UseAuthGuard([UserRole.USER]) + @ApiOkResponse({ type: UserResponseDto }) + @ApiBearerAuth() + async findOne(@Param('id') id: string): Promise { + const user = await this.userService.findOne({ id: +id }); + return toUserResponseDto(user); } @Delete(':id') @ApiOkResponse({ type: Number }) @ApiBearerAuth() + @ApiExcludeEndpoint() async remove(@Param('id') id: string) { return this.userService.remove(+id); } @Get('check/nickname') + @ApiOperation({ summary: '닉네임 중복체크합니다.' }) @ApiOkResponse({}) async checkDuplicateNickname(@Query('nickname') nickname: string) { return this.userService.checkDuplicateNickname(nickname);