Skip to content

Commit

Permalink
Merge pull request #266 from boostcampwm2023/BE-chatList-#264
Browse files Browse the repository at this point in the history
[BE/#264] 채팅 내역 응답 API
  • Loading branch information
koomin1227 authored Dec 3, 2023
2 parents 45f743e + 0f193e5 commit c6eb04c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
1 change: 1 addition & 0 deletions BE/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,5 @@ lerna-debug.log*

/envs
/logs
firebase.json

4 changes: 2 additions & 2 deletions BE/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import * as path from 'path';

@Module({
imports: [
ServeStaticModule.forRoot({
/*ServeStaticModule.forRoot({
rootPath: path.resolve(__dirname, '../static'),
}),
}),*/
ConfigModule.forRoot({
isGlobal: true,
envFilePath: `${process.cwd()}/envs/${process.env.NODE_ENV}.env`,
Expand Down
3 changes: 1 addition & 2 deletions BE/src/chat/chat.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { Controller, Get, Post, Body, Param, UseGuards } from '@nestjs/common';
import { ChatService } from './chat.service';
import { AuthGuard } from '../utils/auth.guard';
Expand All @@ -21,7 +20,7 @@ export class ChatController {

@Get('room/:id')
@UseGuards(AuthGuard)
async roomDetail(@Param() id: number, @UserHash() userId: string) {
async roomDetail(@Param('id') id: number, @UserHash() userId: string) {
return await this.chatService.findRoomById(id, userId);
}

Expand Down
18 changes: 9 additions & 9 deletions BE/src/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ export class ChatService {
relations: ['chats'],
});

this.checkAuth(room, userId);

return {
post_id: room.post_id,
chat_log: room.chats,
};
}

checkAuth(room: ChatRoomEntity, userId: string) {
if (!room) {
throw new HttpException('존재하지 않는 채팅방입니다.', 404);
} else if (room.writer !== userId && room.user !== userId) {
throw new HttpException('권한이 없습니다.', 403);
}

return {
room_id: room.id,
post_id: room.post_id,
writer: room.writer,
user: room.user,
update_date: room.update_date,
chatLog: room.chats,
};
}
}

0 comments on commit c6eb04c

Please sign in to comment.