Skip to content

Commit f1296c9

Browse files
committed
feat: 워크스페이스 참여 서비스의 예외 상황 처리
InvalidJoinError 커스텀해서 사용
1 parent aef37f1 commit f1296c9

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

server/apis/workspace/controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ router.post(
2323
asyncWrapper(async (req: Request, res: Response, next: NextFunction) => {
2424
const { code } = req.body;
2525

26-
const joinResult = await workspaceService.join(req.user.id, code);
26+
const joinedWorkspace = await workspaceService.join(req.user.id, code);
2727

28-
res.status(OK).send(joinResult);
28+
res.status(OK).send(joinedWorkspace);
2929
})
3030
);
3131

server/apis/workspace/service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { v4 as uuidv4 } from "uuid";
22
import workspaceModel from "./model";
33
import userModel from "@apis/user/model";
4+
import AuthorizationError from "@errors/authorization-error";
5+
import InvalidJoinError from "@errors/invalid-join-error";
46

57
export const create = async (name: string) => {
68
const code = uuidv4();
@@ -11,8 +13,14 @@ export const create = async (name: string) => {
1113
};
1214

1315
export const join = async (userId: number, code: string) => {
16+
if (!userId) throw new AuthorizationError("유저 인증 실패");
17+
18+
if (!code) throw new InvalidJoinError("참여코드를 입력하세요 ^^");
19+
1420
const workspace = await workspaceModel.findOne({ code });
1521

22+
if (!workspace) throw new InvalidJoinError("잘못된 참여코드에요 ^^");
23+
1624
const { id, name } = workspace;
1725

1826
await workspaceModel.updateOne({ id }, { $push: { users: userId } });
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import CustomError from ".";
2+
import { BAD_REQUEST } from "@constants/http-status";
3+
4+
export default class InvalidJoinError extends CustomError {
5+
constructor(message: string = "Unauthorized") {
6+
super(message, BAD_REQUEST);
7+
}
8+
}

0 commit comments

Comments
 (0)