Skip to content

Commit 9a89927

Browse files
authored
Merge pull request #1703 from rocket-admin/backend_hosted_connection_info
feat: add GetConnectionsInfoByIds use case and corresponding API endpoint
2 parents eb44093 + f0d0f4b commit 9a89927

7 files changed

Lines changed: 163 additions & 0 deletions

File tree

backend/src/common/data-injection.tokens.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export enum UseCaseType {
118118
SAAS_CREATE_CONNECTION_FOR_HOSTED_DB = 'SAAS_CREATE_CONNECTION_FOR_HOSTED_DB',
119119
SAAS_DELETE_CONNECTION_FOR_HOSTED_DB = 'SAAS_DELETE_CONNECTION_FOR_HOSTED_DB',
120120
SAAS_UPDATE_HOSTED_CONNECTION_PASSWORD = 'SAAS_UPDATE_HOSTED_CONNECTION_PASSWORD',
121+
SAAS_GET_CONNECTIONS_INFO_BY_IDS = 'SAAS_GET_CONNECTIONS_INFO_BY_IDS',
121122

122123
INVITE_USER_IN_COMPANY_AND_CONNECTION_GROUP = 'INVITE_USER_IN_COMPANY_AND_CONNECTION_GROUP',
123124
VERIFY_INVITE_USER_IN_COMPANY_AND_CONNECTION_GROUP = 'VERIFY_INVITE_USER_IN_COMPANY_AND_CONNECTION_GROUP',
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js';
3+
4+
export class FoundConnectionInfoRO {
5+
@ApiProperty()
6+
id: string;
7+
8+
@ApiProperty()
9+
title: string;
10+
11+
@ApiProperty({ enum: ConnectionTypesEnum })
12+
type: ConnectionTypesEnum;
13+
14+
@ApiProperty()
15+
host: string;
16+
17+
@ApiProperty()
18+
port: number;
19+
20+
@ApiProperty()
21+
database: string;
22+
23+
@ApiProperty()
24+
schema: string;
25+
26+
@ApiProperty()
27+
sid: string;
28+
29+
@ApiProperty()
30+
ssh: boolean;
31+
32+
@ApiProperty()
33+
ssl: boolean;
34+
35+
@ApiProperty()
36+
createdAt: Date;
37+
38+
@ApiProperty()
39+
updatedAt: Date;
40+
41+
@ApiProperty()
42+
isTestConnection: boolean;
43+
44+
@ApiProperty()
45+
is_frozen: boolean;
46+
47+
@ApiProperty()
48+
masterEncryption: boolean;
49+
50+
@ApiProperty()
51+
azure_encryption: boolean;
52+
53+
@ApiProperty()
54+
authSource: string;
55+
56+
@ApiProperty()
57+
dataCenter: string | null;
58+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { IsArray, IsNotEmpty, IsString } from 'class-validator';
3+
4+
export class GetConnectionsInfoByIdsDS {
5+
@ApiProperty({ type: [String] })
6+
@IsArray()
7+
@IsNotEmpty()
8+
@IsString({ each: true })
9+
connectionIds: Array<string>;
10+
}

backend/src/microservices/saas-microservice/saas.controller.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ import { InTransactionEnum } from '../../enums/in-transaction.enum.js';
2525
import { Messages } from '../../exceptions/text/messages.js';
2626
import { SentryInterceptor } from '../../interceptors/sentry.interceptor.js';
2727
import { CreatedConnectionResponse, SuccessResponse } from './data-structures/common-responce.ds.js';
28+
import { FoundConnectionInfoRO } from './data-structures/found-connection-info.ro.js';
2829
import { CreateConnectionForHostedDbDto } from './data-structures/create-connecttion-for-selfhosted-db.dto.js';
2930
import { DeleteConnectionForHostedDbDto } from './data-structures/delete-connection-for-hosted-db.dto.js';
31+
import { GetConnectionsInfoByIdsDS } from './data-structures/get-connections-info-by-ids.ds.js';
3032
import { RegisterCompanyWebhookDS } from './data-structures/register-company.ds.js';
3133
import { RegisteredCompanyDS } from './data-structures/registered-company.ds.js';
3234
import { SaasRegisterUserWithGithub } from './data-structures/saas-register-user-with-github.js';
@@ -38,6 +40,7 @@ import {
3840
ICreateConnectionForHostedDb,
3941
IDeleteConnectionForHostedDb,
4042
IFreezeConnectionsInCompany,
43+
IGetConnectionsInfoByIds,
4144
IGetUserInfo,
4245
ILoginUserWithGitHub,
4346
ILoginUserWithGoogle,
@@ -95,6 +98,8 @@ export class SaasController {
9598
private readonly deleteConnectionForHostedDbUseCase: IDeleteConnectionForHostedDb,
9699
@Inject(UseCaseType.SAAS_UPDATE_HOSTED_CONNECTION_PASSWORD)
97100
private readonly updateHostedConnectionPasswordUseCase: IUpdateHostedConnectionPassword,
101+
@Inject(UseCaseType.SAAS_GET_CONNECTIONS_INFO_BY_IDS)
102+
private readonly getConnectionsInfoByIdsUseCase: IGetConnectionsInfoByIds,
98103
) {}
99104

100105
@ApiOperation({ summary: 'Company registered webhook' })
@@ -326,4 +331,17 @@ export class SaasController {
326331
): Promise<SuccessResponse> {
327332
return await this.updateHostedConnectionPasswordUseCase.execute(updatePasswordData);
328333
}
334+
335+
@ApiOperation({ summary: 'Get connections info by ids' })
336+
@ApiBody({ type: GetConnectionsInfoByIdsDS })
337+
@ApiResponse({
338+
status: 200,
339+
type: [FoundConnectionInfoRO],
340+
})
341+
@Post('/connections/info')
342+
async getConnectionsInfoByIds(
343+
@Body() connectionsData: GetConnectionsInfoByIdsDS,
344+
): Promise<Array<FoundConnectionInfoRO>> {
345+
return await this.getConnectionsInfoByIdsUseCase.execute(connectionsData);
346+
}
329347
}

backend/src/microservices/saas-microservice/saas.module.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { SaasUsualRegisterUseCase } from './use-cases/saas-usual-register-user.u
2323
import { SuspendUsersUseCase } from './use-cases/suspend-users.use.case.js';
2424
import { SuspendUsersOverLimitUseCase } from './use-cases/suspend-users-over-limit.use.case.js';
2525
import { UnFreezeConnectionsInCompanyUseCase } from './use-cases/unfreeze-connections-in-company-use.case.js';
26+
import { GetConnectionsInfoByIdsUseCase } from './use-cases/get-connections-info-by-ids.use.case.js';
2627
import { UpdateHostedConnectionPasswordUseCase } from './use-cases/update-hosted-connection-password.use.case.js';
2728

2829
@Module({
@@ -100,6 +101,10 @@ import { UpdateHostedConnectionPasswordUseCase } from './use-cases/update-hosted
100101
provide: UseCaseType.SAAS_UPDATE_HOSTED_CONNECTION_PASSWORD,
101102
useClass: UpdateHostedConnectionPasswordUseCase,
102103
},
104+
{
105+
provide: UseCaseType.SAAS_GET_CONNECTIONS_INFO_BY_IDS,
106+
useClass: GetConnectionsInfoByIdsUseCase,
107+
},
103108
SignInAuditService,
104109
],
105110
controllers: [SaasController],
@@ -126,6 +131,7 @@ export class SaasModule {
126131
{ path: 'saas/connection/hosted', method: RequestMethod.POST },
127132
{ path: 'saas/connection/hosted/delete', method: RequestMethod.POST },
128133
{ path: 'saas/connection/hosted/password', method: RequestMethod.POST },
134+
{ path: 'saas/connections/info', method: RequestMethod.POST },
129135
);
130136
}
131137
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
2+
import { In } from 'typeorm';
3+
import AbstractUseCase from '../../../common/abstract-use.case.js';
4+
import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js';
5+
import { BaseType } from '../../../common/data-injection.tokens.js';
6+
import { ConnectionEntity } from '../../../entities/connection/connection.entity.js';
7+
import { Messages } from '../../../exceptions/text/messages.js';
8+
import { FoundConnectionInfoRO } from '../data-structures/found-connection-info.ro.js';
9+
import { GetConnectionsInfoByIdsDS } from '../data-structures/get-connections-info-by-ids.ds.js';
10+
import { IGetConnectionsInfoByIds } from './saas-use-cases.interface.js';
11+
12+
@Injectable()
13+
export class GetConnectionsInfoByIdsUseCase
14+
extends AbstractUseCase<GetConnectionsInfoByIdsDS, Array<FoundConnectionInfoRO>>
15+
implements IGetConnectionsInfoByIds
16+
{
17+
constructor(
18+
@Inject(BaseType.GLOBAL_DB_CONTEXT)
19+
protected _dbContext: IGlobalDatabaseContext,
20+
) {
21+
super();
22+
}
23+
24+
protected async implementation(inputData: GetConnectionsInfoByIdsDS): Promise<Array<FoundConnectionInfoRO>> {
25+
const { connectionIds } = inputData;
26+
if (!connectionIds || connectionIds.length === 0) {
27+
throw new HttpException(
28+
{
29+
message: Messages.CONNECTION_ID_MISSING,
30+
},
31+
HttpStatus.BAD_REQUEST,
32+
);
33+
}
34+
35+
const connections = await this._dbContext.connectionRepository.findBy({
36+
id: In(connectionIds),
37+
});
38+
39+
return connections.map((connection) => this.buildConnectionInfoRO(connection));
40+
}
41+
42+
private buildConnectionInfoRO(connection: ConnectionEntity): FoundConnectionInfoRO {
43+
return {
44+
id: connection.id,
45+
title: connection.title,
46+
type: connection.type,
47+
host: connection.host,
48+
port: connection.port,
49+
database: connection.database,
50+
schema: connection.schema,
51+
sid: connection.sid,
52+
ssh: connection.ssh,
53+
ssl: connection.ssl,
54+
createdAt: connection.createdAt,
55+
updatedAt: connection.updatedAt,
56+
isTestConnection: connection.isTestConnection,
57+
is_frozen: connection.is_frozen,
58+
masterEncryption: connection.masterEncryption,
59+
azure_encryption: connection.azure_encryption,
60+
authSource: connection.authSource,
61+
dataCenter: connection.dataCenter,
62+
};
63+
}
64+
}

backend/src/microservices/saas-microservice/use-cases/saas-use-cases.interface.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { CompanyInfoEntity } from '../../../entities/company-info/company-info.entity.js';
22
import { CreatedConnectionDTO } from '../../../entities/connection/application/dto/created-connection.dto.js';
3+
import { FoundConnectionInfoRO } from '../data-structures/found-connection-info.ro.js';
34
import { SaaSRegisterDemoUserAccountDS } from '../../../entities/user/application/data-structures/demo-user-account-register.ds.js';
45
import { SaasUsualUserRegisterDS } from '../../../entities/user/application/data-structures/usual-register-user.ds.js';
56
import { FoundUserDto } from '../../../entities/user/dto/found-user.dto.js';
@@ -9,6 +10,7 @@ import { CreatedConnectionResponse, SuccessResponse } from '../data-structures/c
910
import { CreateConnectionForHostedDbDto } from '../data-structures/create-connecttion-for-selfhosted-db.dto.js';
1011
import { DeleteConnectionForHostedDbDto } from '../data-structures/delete-connection-for-hosted-db.dto.js';
1112
import { FreezeConnectionsInCompanyDS } from '../data-structures/freeze-connections-in-company.ds.js';
13+
import { GetConnectionsInfoByIdsDS } from '../data-structures/get-connections-info-by-ids.ds.js';
1214
import { GetUserInfoByIdDS } from '../data-structures/get-user-info.ds.js';
1315
import { GetUsersInfosByEmailDS } from '../data-structures/get-users-infos-by-email.ds.js';
1416
import { RegisterCompanyWebhookDS } from '../data-structures/register-company.ds.js';
@@ -82,3 +84,7 @@ export interface IDeleteConnectionForHostedDb {
8284
export interface IUpdateHostedConnectionPassword {
8385
execute(inputData: UpdateHostedConnectionPasswordDto): Promise<SuccessResponse>;
8486
}
87+
88+
export interface IGetConnectionsInfoByIds {
89+
execute(inputData: GetConnectionsInfoByIdsDS): Promise<Array<FoundConnectionInfoRO>>;
90+
}

0 commit comments

Comments
 (0)