@@ -4,20 +4,19 @@ import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/en
44import AbstractUseCase from '../../../common/abstract-use.case.js' ;
55import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js' ;
66import { BaseType } from '../../../common/data-injection.tokens.js' ;
7- import { Messages } from '../../../exceptions/text/messages.js' ;
8- import { slackPostMessage } from '../../../helpers/index.js' ;
9- import { AccessLevelEnum } from '../../../enums/index.js' ;
107import { generateCedarPolicyForGroup } from '../../../entities/cedar-authorization/cedar-policy-generator.js' ;
11- import { CreatedConnectionDTO } from '../../../entities/connection/application/dto/created-connection.dto.js' ;
128import { ConnectionEntity } from '../../../entities/connection/connection.entity.js' ;
139import { readSslCertificate } from '../../../entities/connection/ssl-certificate/read-certificate.js' ;
14- import { buildCreatedConnectionDs } from '../../../entities/connection/utils/build-created-connection.ds.js' ;
10+ import { AccessLevelEnum } from '../../../enums/index.js' ;
11+ import { Messages } from '../../../exceptions/text/messages.js' ;
12+ import { slackPostMessage } from '../../../helpers/index.js' ;
13+ import { CreatedConnectionResponse } from '../data-structures/common-responce.ds.js' ;
1514import { CreateConnectionForHostedDbDto } from '../data-structures/create-connecttion-for-selfhosted-db.dto.js' ;
1615import { ICreateConnectionForHostedDb } from './saas-use-cases.interface.js' ;
1716
1817@Injectable ( { scope : Scope . REQUEST } )
1918export class CreateConnectionForHostedDbUseCase
20- extends AbstractUseCase < CreateConnectionForHostedDbDto , CreatedConnectionDTO >
19+ extends AbstractUseCase < CreateConnectionForHostedDbDto , CreatedConnectionResponse >
2120 implements ICreateConnectionForHostedDb
2221{
2322 constructor (
@@ -27,17 +26,15 @@ export class CreateConnectionForHostedDbUseCase
2726 super ( ) ;
2827 }
2928
30- protected async implementation ( inputData : CreateConnectionForHostedDbDto ) : Promise < CreatedConnectionDTO > {
29+ protected async implementation ( inputData : CreateConnectionForHostedDbDto ) : Promise < CreatedConnectionResponse > {
3130 const { companyId, userId, databaseName, hostname, port, username, password } = inputData ;
3231
3332 const connectionAuthor = await this . _dbContext . userRepository . findOneUserById ( userId ) ;
3433 if ( ! connectionAuthor ) {
3534 throw new InternalServerErrorException ( Messages . USER_NOT_FOUND ) ;
3635 }
3736
38- await slackPostMessage (
39- Messages . USER_TRY_CREATE_CONNECTION ( connectionAuthor . email , ConnectionTypesEnum . postgres ) ,
40- ) ;
37+ await slackPostMessage ( Messages . USER_TRY_CREATE_CONNECTION ( connectionAuthor . email , ConnectionTypesEnum . postgres ) ) ;
4138
4239 const cert = await readSslCertificate ( ) ;
4340
@@ -85,21 +82,18 @@ export class CreateConnectionForHostedDbUseCase
8582 savedConnection ,
8683 connectionAuthor ,
8784 ) ;
88- createdAdminGroup . cedarPolicy = generateCedarPolicyForGroup (
89- savedConnection . id ,
90- true ,
91- {
92- connection : { connectionId : savedConnection . id , accessLevel : AccessLevelEnum . edit } ,
93- group : { groupId : createdAdminGroup . id , accessLevel : AccessLevelEnum . edit } ,
94- tables : [ ] ,
95- } ,
96- ) ;
85+ createdAdminGroup . cedarPolicy = generateCedarPolicyForGroup ( savedConnection . id , true , {
86+ connection : { connectionId : savedConnection . id , accessLevel : AccessLevelEnum . edit } ,
87+ group : { groupId : createdAdminGroup . id , accessLevel : AccessLevelEnum . edit } ,
88+ tables : [ ] ,
89+ } ) ;
9790 await this . _dbContext . groupRepository . saveNewOrUpdatedGroup ( createdAdminGroup ) ;
9891 delete createdAdminGroup . connection ;
9992 await this . _dbContext . userRepository . saveUserEntity ( connectionAuthor ) ;
10093 savedConnection . groups = [ createdAdminGroup ] ;
10194
102- const foundCompany = await this . _dbContext . companyInfoRepository . findCompanyInfoByCompanyIdWithoutConnections ( companyId ) ;
95+ const foundCompany =
96+ await this . _dbContext . companyInfoRepository . findCompanyInfoByCompanyIdWithoutConnections ( companyId ) ;
10397 if ( foundCompany ) {
10498 const connectionToUpdate = await this . _dbContext . connectionRepository . findOne ( {
10599 where : { id : savedConnection . id } ,
@@ -108,11 +102,8 @@ export class CreateConnectionForHostedDbUseCase
108102 await this . _dbContext . connectionRepository . saveUpdatedConnection ( connectionToUpdate ) ;
109103 }
110104
111- await slackPostMessage (
112- Messages . USER_CREATED_CONNECTION ( connectionAuthor . email , ConnectionTypesEnum . postgres ) ,
113- ) ;
105+ await slackPostMessage ( Messages . USER_CREATED_CONNECTION ( connectionAuthor . email , ConnectionTypesEnum . postgres ) ) ;
114106
115- const connectionRO = buildCreatedConnectionDs ( savedConnection , null , null ) ;
116- return connectionRO ;
107+ return { connectionId : savedConnection . id } ;
117108 }
118109}
0 commit comments