diff --git a/backend/src/common/data-injection.tokens.ts b/backend/src/common/data-injection.tokens.ts index aa88d7c4b..2b930729e 100644 --- a/backend/src/common/data-injection.tokens.ts +++ b/backend/src/common/data-injection.tokens.ts @@ -118,6 +118,7 @@ export enum UseCaseType { SAAS_CREATE_CONNECTION_FOR_HOSTED_DB = 'SAAS_CREATE_CONNECTION_FOR_HOSTED_DB', SAAS_DELETE_CONNECTION_FOR_HOSTED_DB = 'SAAS_DELETE_CONNECTION_FOR_HOSTED_DB', SAAS_UPDATE_HOSTED_CONNECTION_PASSWORD = 'SAAS_UPDATE_HOSTED_CONNECTION_PASSWORD', + SAAS_GET_CONNECTIONS_INFO_BY_IDS = 'SAAS_GET_CONNECTIONS_INFO_BY_IDS', INVITE_USER_IN_COMPANY_AND_CONNECTION_GROUP = 'INVITE_USER_IN_COMPANY_AND_CONNECTION_GROUP', VERIFY_INVITE_USER_IN_COMPANY_AND_CONNECTION_GROUP = 'VERIFY_INVITE_USER_IN_COMPANY_AND_CONNECTION_GROUP', diff --git a/backend/src/microservices/saas-microservice/data-structures/found-connection-info.ro.ts b/backend/src/microservices/saas-microservice/data-structures/found-connection-info.ro.ts new file mode 100644 index 000000000..4e6de6902 --- /dev/null +++ b/backend/src/microservices/saas-microservice/data-structures/found-connection-info.ro.ts @@ -0,0 +1,58 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; + +export class FoundConnectionInfoRO { + @ApiProperty() + id: string; + + @ApiProperty() + title: string; + + @ApiProperty({ enum: ConnectionTypesEnum }) + type: ConnectionTypesEnum; + + @ApiProperty() + host: string; + + @ApiProperty() + port: number; + + @ApiProperty() + database: string; + + @ApiProperty() + schema: string; + + @ApiProperty() + sid: string; + + @ApiProperty() + ssh: boolean; + + @ApiProperty() + ssl: boolean; + + @ApiProperty() + createdAt: Date; + + @ApiProperty() + updatedAt: Date; + + @ApiProperty() + isTestConnection: boolean; + + @ApiProperty() + is_frozen: boolean; + + @ApiProperty() + masterEncryption: boolean; + + @ApiProperty() + azure_encryption: boolean; + + @ApiProperty() + authSource: string; + + @ApiProperty() + dataCenter: string | null; +} diff --git a/backend/src/microservices/saas-microservice/data-structures/get-connections-info-by-ids.ds.ts b/backend/src/microservices/saas-microservice/data-structures/get-connections-info-by-ids.ds.ts new file mode 100644 index 000000000..edf0b9d62 --- /dev/null +++ b/backend/src/microservices/saas-microservice/data-structures/get-connections-info-by-ids.ds.ts @@ -0,0 +1,10 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { IsArray, IsNotEmpty, IsString } from 'class-validator'; + +export class GetConnectionsInfoByIdsDS { + @ApiProperty({ type: [String] }) + @IsArray() + @IsNotEmpty() + @IsString({ each: true }) + connectionIds: Array; +} diff --git a/backend/src/microservices/saas-microservice/saas.controller.ts b/backend/src/microservices/saas-microservice/saas.controller.ts index f9f876ff9..793524c60 100644 --- a/backend/src/microservices/saas-microservice/saas.controller.ts +++ b/backend/src/microservices/saas-microservice/saas.controller.ts @@ -25,8 +25,10 @@ import { InTransactionEnum } from '../../enums/in-transaction.enum.js'; import { Messages } from '../../exceptions/text/messages.js'; import { SentryInterceptor } from '../../interceptors/sentry.interceptor.js'; import { CreatedConnectionResponse, SuccessResponse } from './data-structures/common-responce.ds.js'; +import { FoundConnectionInfoRO } from './data-structures/found-connection-info.ro.js'; import { CreateConnectionForHostedDbDto } from './data-structures/create-connecttion-for-selfhosted-db.dto.js'; import { DeleteConnectionForHostedDbDto } from './data-structures/delete-connection-for-hosted-db.dto.js'; +import { GetConnectionsInfoByIdsDS } from './data-structures/get-connections-info-by-ids.ds.js'; import { RegisterCompanyWebhookDS } from './data-structures/register-company.ds.js'; import { RegisteredCompanyDS } from './data-structures/registered-company.ds.js'; import { SaasRegisterUserWithGithub } from './data-structures/saas-register-user-with-github.js'; @@ -38,6 +40,7 @@ import { ICreateConnectionForHostedDb, IDeleteConnectionForHostedDb, IFreezeConnectionsInCompany, + IGetConnectionsInfoByIds, IGetUserInfo, ILoginUserWithGitHub, ILoginUserWithGoogle, @@ -95,6 +98,8 @@ export class SaasController { private readonly deleteConnectionForHostedDbUseCase: IDeleteConnectionForHostedDb, @Inject(UseCaseType.SAAS_UPDATE_HOSTED_CONNECTION_PASSWORD) private readonly updateHostedConnectionPasswordUseCase: IUpdateHostedConnectionPassword, + @Inject(UseCaseType.SAAS_GET_CONNECTIONS_INFO_BY_IDS) + private readonly getConnectionsInfoByIdsUseCase: IGetConnectionsInfoByIds, ) {} @ApiOperation({ summary: 'Company registered webhook' }) @@ -326,4 +331,17 @@ export class SaasController { ): Promise { return await this.updateHostedConnectionPasswordUseCase.execute(updatePasswordData); } + + @ApiOperation({ summary: 'Get connections info by ids' }) + @ApiBody({ type: GetConnectionsInfoByIdsDS }) + @ApiResponse({ + status: 200, + type: [FoundConnectionInfoRO], + }) + @Post('/connections/info') + async getConnectionsInfoByIds( + @Body() connectionsData: GetConnectionsInfoByIdsDS, + ): Promise> { + return await this.getConnectionsInfoByIdsUseCase.execute(connectionsData); + } } diff --git a/backend/src/microservices/saas-microservice/saas.module.ts b/backend/src/microservices/saas-microservice/saas.module.ts index 88b28bbb7..2d43fd052 100644 --- a/backend/src/microservices/saas-microservice/saas.module.ts +++ b/backend/src/microservices/saas-microservice/saas.module.ts @@ -23,6 +23,7 @@ import { SaasUsualRegisterUseCase } from './use-cases/saas-usual-register-user.u import { SuspendUsersUseCase } from './use-cases/suspend-users.use.case.js'; import { SuspendUsersOverLimitUseCase } from './use-cases/suspend-users-over-limit.use.case.js'; import { UnFreezeConnectionsInCompanyUseCase } from './use-cases/unfreeze-connections-in-company-use.case.js'; +import { GetConnectionsInfoByIdsUseCase } from './use-cases/get-connections-info-by-ids.use.case.js'; import { UpdateHostedConnectionPasswordUseCase } from './use-cases/update-hosted-connection-password.use.case.js'; @Module({ @@ -100,6 +101,10 @@ import { UpdateHostedConnectionPasswordUseCase } from './use-cases/update-hosted provide: UseCaseType.SAAS_UPDATE_HOSTED_CONNECTION_PASSWORD, useClass: UpdateHostedConnectionPasswordUseCase, }, + { + provide: UseCaseType.SAAS_GET_CONNECTIONS_INFO_BY_IDS, + useClass: GetConnectionsInfoByIdsUseCase, + }, SignInAuditService, ], controllers: [SaasController], @@ -126,6 +131,7 @@ export class SaasModule { { path: 'saas/connection/hosted', method: RequestMethod.POST }, { path: 'saas/connection/hosted/delete', method: RequestMethod.POST }, { path: 'saas/connection/hosted/password', method: RequestMethod.POST }, + { path: 'saas/connections/info', method: RequestMethod.POST }, ); } } diff --git a/backend/src/microservices/saas-microservice/use-cases/get-connections-info-by-ids.use.case.ts b/backend/src/microservices/saas-microservice/use-cases/get-connections-info-by-ids.use.case.ts new file mode 100644 index 000000000..459cbe66a --- /dev/null +++ b/backend/src/microservices/saas-microservice/use-cases/get-connections-info-by-ids.use.case.ts @@ -0,0 +1,64 @@ +import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common'; +import { In } from 'typeorm'; +import AbstractUseCase from '../../../common/abstract-use.case.js'; +import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js'; +import { BaseType } from '../../../common/data-injection.tokens.js'; +import { ConnectionEntity } from '../../../entities/connection/connection.entity.js'; +import { Messages } from '../../../exceptions/text/messages.js'; +import { FoundConnectionInfoRO } from '../data-structures/found-connection-info.ro.js'; +import { GetConnectionsInfoByIdsDS } from '../data-structures/get-connections-info-by-ids.ds.js'; +import { IGetConnectionsInfoByIds } from './saas-use-cases.interface.js'; + +@Injectable() +export class GetConnectionsInfoByIdsUseCase + extends AbstractUseCase> + implements IGetConnectionsInfoByIds +{ + constructor( + @Inject(BaseType.GLOBAL_DB_CONTEXT) + protected _dbContext: IGlobalDatabaseContext, + ) { + super(); + } + + protected async implementation(inputData: GetConnectionsInfoByIdsDS): Promise> { + const { connectionIds } = inputData; + if (!connectionIds || connectionIds.length === 0) { + throw new HttpException( + { + message: Messages.CONNECTION_ID_MISSING, + }, + HttpStatus.BAD_REQUEST, + ); + } + + const connections = await this._dbContext.connectionRepository.findBy({ + id: In(connectionIds), + }); + + return connections.map((connection) => this.buildConnectionInfoRO(connection)); + } + + private buildConnectionInfoRO(connection: ConnectionEntity): FoundConnectionInfoRO { + return { + id: connection.id, + title: connection.title, + type: connection.type, + host: connection.host, + port: connection.port, + database: connection.database, + schema: connection.schema, + sid: connection.sid, + ssh: connection.ssh, + ssl: connection.ssl, + createdAt: connection.createdAt, + updatedAt: connection.updatedAt, + isTestConnection: connection.isTestConnection, + is_frozen: connection.is_frozen, + masterEncryption: connection.masterEncryption, + azure_encryption: connection.azure_encryption, + authSource: connection.authSource, + dataCenter: connection.dataCenter, + }; + } +} diff --git a/backend/src/microservices/saas-microservice/use-cases/saas-use-cases.interface.ts b/backend/src/microservices/saas-microservice/use-cases/saas-use-cases.interface.ts index 40b996e4e..76fae3296 100644 --- a/backend/src/microservices/saas-microservice/use-cases/saas-use-cases.interface.ts +++ b/backend/src/microservices/saas-microservice/use-cases/saas-use-cases.interface.ts @@ -1,5 +1,6 @@ import { CompanyInfoEntity } from '../../../entities/company-info/company-info.entity.js'; import { CreatedConnectionDTO } from '../../../entities/connection/application/dto/created-connection.dto.js'; +import { FoundConnectionInfoRO } from '../data-structures/found-connection-info.ro.js'; import { SaaSRegisterDemoUserAccountDS } from '../../../entities/user/application/data-structures/demo-user-account-register.ds.js'; import { SaasUsualUserRegisterDS } from '../../../entities/user/application/data-structures/usual-register-user.ds.js'; import { FoundUserDto } from '../../../entities/user/dto/found-user.dto.js'; @@ -9,6 +10,7 @@ import { CreatedConnectionResponse, SuccessResponse } from '../data-structures/c import { CreateConnectionForHostedDbDto } from '../data-structures/create-connecttion-for-selfhosted-db.dto.js'; import { DeleteConnectionForHostedDbDto } from '../data-structures/delete-connection-for-hosted-db.dto.js'; import { FreezeConnectionsInCompanyDS } from '../data-structures/freeze-connections-in-company.ds.js'; +import { GetConnectionsInfoByIdsDS } from '../data-structures/get-connections-info-by-ids.ds.js'; import { GetUserInfoByIdDS } from '../data-structures/get-user-info.ds.js'; import { GetUsersInfosByEmailDS } from '../data-structures/get-users-infos-by-email.ds.js'; import { RegisterCompanyWebhookDS } from '../data-structures/register-company.ds.js'; @@ -82,3 +84,7 @@ export interface IDeleteConnectionForHostedDb { export interface IUpdateHostedConnectionPassword { execute(inputData: UpdateHostedConnectionPasswordDto): Promise; } + +export interface IGetConnectionsInfoByIds { + execute(inputData: GetConnectionsInfoByIdsDS): Promise>; +}