@@ -8,13 +8,15 @@ import { UserNotFoundException } from '../exception/user.exception';
88import { Workspace } from './workspace.entity' ;
99import { WorkspaceNotFoundException } from '../exception/workspace.exception' ;
1010import { NotWorkspaceOwnerException } from '../exception/workspace-auth.exception' ;
11+ import { TokenService } from '../auth/token/token.service' ;
1112
1213@Injectable ( )
1314export class WorkspaceService {
1415 constructor (
1516 private readonly workspaceRepository : WorkspaceRepository ,
1617 private readonly userRepository : UserRepository ,
1718 private readonly roleRepository : RoleRepository ,
19+ private readonly tokenService : TokenService ,
1820 ) { }
1921
2022 async createWorkspace (
@@ -57,7 +59,6 @@ export class WorkspaceService {
5759 throw new WorkspaceNotFoundException ( ) ;
5860 }
5961
60- // Role Repository에서 해당 workspace의 owner이 userId인지 확인
6162 // Role Repository에서 해당 workspace의 owner인지 확인
6263 const role = await this . roleRepository . findOneBy ( {
6364 workspaceId : workspace . id ,
@@ -89,4 +90,35 @@ export class WorkspaceService {
8990 role : role . role as 'owner' | 'guest' ,
9091 } ) ) ;
9192 }
93+
94+ async generateInviteUrl (
95+ userId : number ,
96+ workspaceId : string ,
97+ ) : Promise < string > {
98+ // 워크스페이스가 존재하는지 확인
99+ const workspace = await this . workspaceRepository . findOneBy ( {
100+ snowflakeId : workspaceId ,
101+ } ) ;
102+
103+ if ( ! workspace ) {
104+ throw new WorkspaceNotFoundException ( ) ;
105+ }
106+
107+ // Role Repository에서 해당 사용자가 소유자인지 확인
108+ const role = await this . roleRepository . findOneBy ( {
109+ userId,
110+ workspaceId : workspace . id ,
111+ role : 'owner' ,
112+ } ) ;
113+
114+ if ( ! role ) {
115+ throw new NotWorkspaceOwnerException ( ) ;
116+ }
117+
118+ // 게스트용 초대용 토큰 생성
119+ const token = this . tokenService . generateInviteToken ( workspace . id , 'guest' ) ;
120+
121+ // TODO: 하드코딩 -> 바꿔야할듯?
122+ return `https://octodocs.local/api/workspace/join?token=${ token } ` ;
123+ }
92124}
0 commit comments