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

[MERGE] dev-be to prod-be #265

Merged
merged 3 commits into from
Dec 2, 2024
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
12 changes: 11 additions & 1 deletion backend/chatServer/src/chat/chat.error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ChatException extends WsException {
this.statusCode = statusCode;
}

getError(): object {
getError() {
return {
statusCode: this.statusCode,
msg: this.message,
Expand Down Expand Up @@ -38,6 +38,11 @@ const CHATTING_SOCKET_ERROR = {
message: '유효하지 않는 유저입니다.'
},

UNAUTHORIZED: {
statusCode: HttpStatus.UNAUTHORIZED,
message: '해당 명령에 대한 권한이 없습니다.'
},

QUESTION_EMPTY: {
statusCode: HttpStatus.BAD_REQUEST,
message: '유효하지 않은 질문입니다.'
Expand All @@ -46,6 +51,11 @@ const CHATTING_SOCKET_ERROR = {
BAN_USER: {
statusCode: HttpStatus.FORBIDDEN,
message: '호스트에 의해 밴 당한 유저입니다.'
},

MSG_TOO_LONG:{
statusCode: HttpStatus.NOT_ACCEPTABLE,
message: '메세지의 내용이 없거나, 길이가 150자를 초과했습니다.'
}


Expand Down
6 changes: 4 additions & 2 deletions backend/chatServer/src/chat/chat.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export class MessageGuard implements CanActivate {
canActivate(context: ExecutionContext): boolean {
const payload = context.switchToWs().getData();
const { msg } = payload;
return !!msg && msg.length <= 150;
if(!!msg && msg.length <= 150) return true;
throw new ChatException(CHATTING_SOCKET_ERROR.MSG_TOO_LONG);
}
}

Expand All @@ -22,7 +23,8 @@ export class HostGuard implements CanActivate {
const { roomId, userId } = payload;
const hostId = await this.roomService.getHostOfRoom(roomId);
console.log('hostGuard:', hostId, userId);
return hostId === userId;
if (hostId === userId) return true;
throw new ChatException(CHATTING_SOCKET_ERROR.UNAUTHORIZED, roomId);
}
}

Expand Down
Loading