@@ -28,9 +28,9 @@ export class WorkspaceService {
2828 private readonly roleRepository : RoleRepository ,
2929 ) {
3030 console . log ( '환경 : ' , process . env . NODE_ENV ) ;
31- // if (process.env.NODE_ENV !== 'test') {
32- // this.initializeMainWorkspace();
33- // }
31+ if ( process . env . NODE_ENV !== 'test' ) {
32+ this . initializeMainWorkspace ( ) ;
33+ }
3434 }
3535
3636 async createWorkspace (
@@ -108,12 +108,12 @@ export class WorkspaceService {
108108
109109 // 가장 처음에 모두가 접속할 수 있는 main workspace를 생성한다.
110110 async initializeMainWorkspace ( ) {
111- const findUser = await this . userRepository . findOneBy ( {
111+ let findOwner = await this . userRepository . findOneBy ( {
112112 snowflakeId : MainWorkspace . OWNER_SNOWFLAKEID ,
113113 } ) ;
114114
115115 // 존재하지 않을 때만 생성한다.
116- if ( ! findUser ) {
116+ if ( ! findOwner ) {
117117 // main workspace owner를 생성한다.
118118 const owner = await this . userRepository . save ( {
119119 snowflakeId : MainWorkspace . OWNER_SNOWFLAKEID ,
@@ -122,34 +122,45 @@ export class WorkspaceService {
122122 email : MainWorkspace . OWNER_EMAIL ,
123123 } ) ;
124124
125- // main workspace를 생성한다.
126- await this . workspaceRepository . save ( {
127- snowflakeId : MainWorkspace . WORKSPACE_SNOWFLAKEID ,
128- owner,
129- title : MainWorkspace . WORKSPACE_TITLE ,
130- description : MainWorkspace . WORKSPACE_DESCRIPTION ,
131- visibility : MainWorkspace . WORKSPACE_VISIBILITY ,
132- } ) ;
133- this . logger . log ( 'main workspace를 생성했습니다.' ) ;
125+ findOwner = owner ;
134126 }
135127 this . logger . log ( 'main workspace owner가 존재합니다.' ) ;
136128
137129 // main workspace를 찾는다.
138- const findWorkspace = await this . workspaceRepository . findOneBy ( {
130+ let findWorkspace = await this . workspaceRepository . findOneBy ( {
139131 snowflakeId : MainWorkspace . WORKSPACE_SNOWFLAKEID ,
140132 } ) ;
141133
142134 // owner는 존재하지만 워크스페이스가 없으면 생성한다.
143135 if ( ! findWorkspace ) {
144- await this . workspaceRepository . save ( {
136+ findWorkspace = await this . workspaceRepository . save ( {
145137 snowflakeId : MainWorkspace . WORKSPACE_SNOWFLAKEID ,
146- owner : findUser ,
138+ owner : findOwner ,
147139 title : MainWorkspace . WORKSPACE_TITLE ,
148140 description : MainWorkspace . WORKSPACE_DESCRIPTION ,
149141 visibility : MainWorkspace . WORKSPACE_VISIBILITY ,
150142 } ) ;
151143 this . logger . log ( 'main workspace를 생성했습니다.' ) ;
152144 }
153145 this . logger . log ( 'main workspace가 존재합니다.' ) ;
146+
147+ // owner의 role을 찾는다.
148+ const role = await this . roleRepository . findOne ( {
149+ where : {
150+ workspaceId : findWorkspace . id ,
151+ userId : findOwner . id ,
152+ } ,
153+ } ) ;
154+
155+ // owner의 role이 없으면 생성한다.
156+ if ( ! role ) {
157+ await this . roleRepository . save ( {
158+ workspaceId : findWorkspace . id ,
159+ userId : findOwner . id ,
160+ workspace : findWorkspace ,
161+ user : findOwner ,
162+ role : 'owner' ,
163+ } ) ;
164+ }
154165 }
155166}
0 commit comments