Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE/#264] 채팅 내역 응답 API #266

Merged
merged 3 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

권한 확인 좋습니다~!


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,
};
}
}
Loading