File tree Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 11import { v4 as uuidv4 } from "uuid" ;
22import workspaceModel from "./model" ;
33import userModel from "@apis/user/model" ;
4+ import AuthorizationError from "@errors/authorization-error" ;
5+ import InvalidJoinError from "@errors/invalid-join-error" ;
46
57export const create = async ( name : string ) => {
68 const code = uuidv4 ( ) ;
@@ -11,8 +13,14 @@ export const create = async (name: string) => {
1113} ;
1214
1315export 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 } } ) ;
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments