Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { FoundSipleConnectionInfoDS } from '../../../connection/application/data-structures/found-connections.ds.js';
import { FoundSimpleConnectionInfoDS } from '../../../connection/application/data-structures/found-connections.ds.js';
import { FoundCompanyImageInfo } from '../dto/found-company-logo.ro.js';
import { FoundInvitationInCompanyDs } from './found-invitation-in-company.ds.js';

Expand Down Expand Up @@ -49,7 +49,7 @@ export class FoundUserCompanyInfoDs {

export class FoundUserFullCompanyInfoDs extends FoundUserCompanyInfoDs {
@ApiProperty({ isArray: true })
connections: Array<FoundSipleConnectionInfoDS>;
connections: Array<FoundSimpleConnectionInfoDS>;

@ApiProperty({ isArray: true, type: FoundInvitationInCompanyDs })
invitations: Array<FoundInvitationInCompanyDs>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FoundSassCompanyInfoDS } from '../../../microservices/gateways/saas-gateway.ts/data-structures/found-saas-company-info.ds.js';
import { FoundSipleConnectionInfoDS } from '../../connection/application/data-structures/found-connections.ds.js';
import { FoundSimpleConnectionInfoDS } from '../../connection/application/data-structures/found-connections.ds.js';
import { UserRoleEnum } from '../../user/enums/user-role.enum.js';
import { buildSimpleUserInfoDs } from '../../user/utils/build-created-user.ds.js';
import {
Expand All @@ -26,7 +26,7 @@ export function buildFoundCompanyFullInfoDs(
companyCustomDomain,
userRole,
) as any;
const connectionsRO: Array<FoundSipleConnectionInfoDS> = companyInfoFromCore.connections.map((connection) => {
const connectionsRO: Array<FoundSimpleConnectionInfoDS> = companyInfoFromCore.connections.map((connection) => {
return {
id: connection.id,
createdAt: connection.createdAt,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js';

export interface ConnectionParametersDs {
title?: string;
masterEncryption?: boolean;
type: ConnectionTypesEnum;
host?: string;
port?: number;
username?: string;
password?: string;
database?: string;
schema?: string;
sid?: string;
ssh?: boolean;
privateSSHKey?: string;
sshHost?: string;
sshPort?: number;
sshUsername?: string;
ssl?: boolean;
cert?: string;
azure_encryption?: boolean;
authSource?: string;
dataCenter?: string;
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js';
import { ConnectionParametersDs } from './connection-parameters.ds.js';

export class CreateConnectionDs {
connection_parameters: {
title: string;
masterEncryption: boolean;
type: ConnectionTypesEnum;
host: string;
port: number;
username: string;
password: string;
database: string;
schema: string;
sid: string;
ssh: boolean;
privateSSHKey: string;
sshHost: string;
sshPort: number;
sshUsername: string;
ssl: boolean;
cert: string;
azure_encryption: boolean;
authSource: string;
dataCenter: string;
};
connection_parameters: ConnectionParametersDs;
creation_info: {
authorId: string;
masterPwd: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { AccessLevelEnum } from '../../../../enums/index.js';
import { ConnectionPropertiesEntity } from '../../../connection-properties/connection-properties.entity.js';
import { FoundGroupDataWithUsersDs } from '../../../group/application/data-sctructures/found-user-groups.ds.js';
import { SimpleFoundUserInfoDs } from '../../../user/dto/found-user.dto.js';
import { UserEntity } from '../../../user/user.entity.js';

export class FoundDirectConnectionsDs {
@ApiProperty()
Expand All @@ -17,7 +16,7 @@ export class FoundDirectConnectionsDs {
masterEncryption: boolean;

@ApiProperty({ enum: ConnectionTypesEnum })
type?: ConnectionTypesEnum | string;
type?: ConnectionTypesEnum;

@ApiProperty()
host?: string;
Expand Down Expand Up @@ -59,7 +58,7 @@ export class FoundDirectConnectionsDs {
cert?: string;

@ApiProperty({ required: false })
author?: UserEntity | string;
author?: string;

@ApiProperty({ required: false })
token?: string;
Expand Down Expand Up @@ -94,7 +93,7 @@ export class FoundDirectConnectionsNonePermissionDs {
title?: string;

@ApiProperty()
type?: ConnectionTypesEnum | string;
type?: ConnectionTypesEnum;

@ApiProperty()
database: string;
Expand All @@ -117,10 +116,10 @@ export class FoundAgentConnectionsDs {
title?: string;

@ApiProperty({ enum: ConnectionTypesEnum })
type?: ConnectionTypesEnum | string;
type?: ConnectionTypesEnum;

@ApiProperty({ required: false })
author: UserEntity | string;
author?: string;

@ApiProperty()
token: string;
Expand All @@ -135,15 +134,15 @@ export class FoundAgentConnectionsDs {
connection_properties: ConnectionPropertiesEntity;
}

export class FoundSipleConnectionInfoDS {
export class FoundSimpleConnectionInfoDS {
@ApiProperty()
id: string;

@ApiProperty()
title?: string;

@ApiProperty({ enum: ConnectionTypesEnum })
type?: ConnectionTypesEnum | string;
type?: ConnectionTypesEnum;

@ApiProperty()
isTestConnection: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js';
import { ConnectionParametersDs } from './connection-parameters.ds.js';

export class UpdateConnectionDs {
connection_parameters: {
title: string;
masterEncryption: boolean;
type: ConnectionTypesEnum;
host: string;
port: number;
username: string;
password: string;
database: string;
schema: string;
sid: string;
ssh: boolean;
privateSSHKey: string;
sshHost: string;
sshPort: number;
sshUsername: string;
ssl: boolean;
cert: string;
azure_encryption: boolean;
authSource: string;
dataCenter: string;
};
connection_parameters: ConnectionParametersDs;
update_info: {
authorId: string;
connectionId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class CreatedConnectionDTO {
masterEncryption: boolean;

@ApiProperty({ enum: ConnectionTypesEnum })
type: ConnectionTypesEnum | string;
type: ConnectionTypesEnum;

@ApiProperty()
host: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { IsOptional, IsString } from 'class-validator';
export class DeleteConnectionReasonDto {
@IsOptional()
@IsString()
@ApiProperty()
reason: string;
@ApiProperty({ required: false })
reason?: string;

@IsOptional()
@IsString()
@ApiProperty()
message: string;
@ApiProperty({ required: false })
message?: string;
}
12 changes: 6 additions & 6 deletions backend/src/entities/connection/connection.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { SentryInterceptor } from '../../interceptors/index.js';
import { SuccessResponse } from '../../microservices/saas-microservice/data-structures/common-responce.ds.js';
import { AmplitudeService } from '../amplitude/amplitude.service.js';
import { FoundGroupResponseDto } from '../group/dto/found-group-response.dto.js';
import { IComplexPermission } from '../permission/permission.interface.js';
import { FindUserDs } from '../user/application/data-structures/find-user.ds.js';
import { FoundUserDto } from '../user/dto/found-user.dto.js';
import { CreateConnectionDs } from './application/data-structures/create-connection.ds.js';
Expand Down Expand Up @@ -291,7 +290,7 @@ export class ConnectionController {
@UserId() userId: string,
@MasterPassword() masterPwd: string,
): Promise<UpdatedConnectionResponseDTO> {
const errors = [];
const errors: string[] = [];
if (updateConnectionDto.masterEncryption && !masterPwd) {
errors.push(Messages.MASTER_PASSWORD_REQUIRED);
}
Expand Down Expand Up @@ -457,7 +456,7 @@ export class ConnectionController {
@QueryUuid('groupId') groupId: string,
@UserId() userId: string,
@MasterPassword() masterPwd: string,
): Promise<IComplexPermission> {
): Promise<FoundPermissionsInConnectionDs> {
if (!connectionId || !groupId) {
throw new BadRequestException(Messages.PARAMETER_MISSING);
}
Expand All @@ -481,7 +480,7 @@ export class ConnectionController {
@QueryUuid('groupId') groupId: string,
@UserId() userId: string,
@MasterPassword() masterPwd: string,
): Promise<IComplexPermission> {
): Promise<FoundPermissionsInConnectionDs> {
if (!connectionId || !groupId) {
throw new BadRequestException(Messages.PARAMETER_MISSING);
}
Expand Down Expand Up @@ -537,10 +536,11 @@ export class ConnectionController {
};
try {
await validateCreateConnectionData(inputData);
} catch (e) {
} catch (e: unknown) {
const err = e as { response?: { message?: string }; message?: string };
return {
result: false,
message: e?.response?.message || e?.message || Messages.CONNECTION_TYPE_INVALID,
message: err?.response?.message || err?.message || Messages.CONNECTION_TYPE_INVALID,
};
}
const result = await this.testConnectionUseCase.execute(inputData, InTransactionEnum.OFF);
Expand Down
5 changes: 3 additions & 2 deletions backend/src/entities/connection/connection.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
PrimaryColumn,
Relation,
} from 'typeorm';
import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js';
import { Constants } from '../../helpers/constants/constants.js';
import { Encryptor } from '../../helpers/encryption/encryptor.js';
import { isConnectionTypeAgent } from '../../helpers/index.js';
Expand Down Expand Up @@ -43,7 +44,7 @@ export class ConnectionEntity {
masterEncryption: boolean;

@Column({ default: null })
type?: string | null;
type?: ConnectionTypesEnum | null;

@Column({ default: null })
host?: string | null;
Expand Down Expand Up @@ -106,7 +107,7 @@ export class ConnectionEntity {
saved_table_info: number;

@Column({ default: null })
signing_key: string;
signing_key: string | null;

@Column({ default: null })
authSource?: string | null;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/entities/connection/connection.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ import { ValidateConnectionTokenUseCase } from './use-cases/validate-connection-
controllers: [ConnectionController],
})
export class ConnectionModule implements NestModule {
public configure(consumer: MiddlewareConsumer): any {
public configure(consumer: MiddlewareConsumer): void {
consumer
.apply(AuthMiddleware)
.forRoutes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ export interface IConnectionRepository {

findAllUserNonTestsConnections(userId: string): Promise<Array<ConnectionEntity>>;

findAllUsersInConnection(connectionId): Promise<Array<UserEntity>>;
findAllUsersInConnection(connectionId: string): Promise<Array<UserEntity>>;

findOneConnection(connectionId: string): Promise<ConnectionEntity>;
findOneConnection(connectionId: string): Promise<ConnectionEntity | null>;

findAndDecryptConnection(connectionId: string, masterPwd: string): Promise<ConnectionEntity>;
findAndDecryptConnection(connectionId: string, masterPwd: string): Promise<ConnectionEntity | null>;

removeConnection(connection: ConnectionEntity): Promise<ConnectionEntity>;

findConnectionWithGroups(connectionId: string): Promise<ConnectionEntity>;
findConnectionWithGroups(connectionId: string): Promise<ConnectionEntity | null>;
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repository contract was changed to allow null returns (e.g., findConnectionWithGroups). At least some call sites assume a non-null connection and immediately dereference (e.g., CreateGroupInConnectionUseCase uses .groups without a null check). Either keep these methods non-null and throw on missing records, or update all callers to handle null explicitly to avoid runtime crashes.

Suggested change
findConnectionWithGroups(connectionId: string): Promise<ConnectionEntity | null>;
findConnectionWithGroups(connectionId: string): Promise<ConnectionEntity>;

Copilot uses AI. Check for mistakes.

getWorkedConnectionsInTwoWeeks(): Promise<Array<ConnectionEntity>>;

getConnectionByGroupIdWithCompanyAndUsersInCompany(groupId: string): Promise<ConnectionEntity>;
getConnectionByGroupIdWithCompanyAndUsersInCompany(groupId: string): Promise<ConnectionEntity | null>;

findOneById(connectionId: string): Promise<ConnectionEntity>;
findOneById(connectionId: string): Promise<ConnectionEntity | null>;

isTestConnectionById(connectionId: string): Promise<boolean>;

saveUpdatedConnection(connection: ConnectionEntity): Promise<ConnectionEntity>;

findOneAgentConnectionByToken(connectionToken: string): Promise<ConnectionEntity>;
findOneAgentConnectionByToken(connectionToken: string): Promise<ConnectionEntity | null>;

decryptConnectionField(field: string): string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Repository } from 'typeorm';
import { Messages } from '../../../exceptions/text/messages.js';
import { Constants } from '../../../helpers/constants/constants.js';
import { Encryptor } from '../../../helpers/encryption/encryptor.js';
Expand All @@ -7,7 +8,8 @@ import { ConnectionEntity } from '../connection.entity.js';
import { isTestConnectionUtil } from '../utils/is-test-connection-util.js';
import { IConnectionRepository } from './connection.repository.interface.js';

export const customConnectionRepositoryExtension: IConnectionRepository = {
export const customConnectionRepositoryExtension: IConnectionRepository &
ThisType<Repository<ConnectionEntity> & IConnectionRepository> = {
async saveNewConnection(connection: ConnectionEntity): Promise<ConnectionEntity> {
const savedConnection = await this.save(connection);
if (!isConnectionTypeAgent(savedConnection.type)) {
Expand Down Expand Up @@ -65,7 +67,7 @@ export const customConnectionRepositoryExtension: IConnectionRepository = {
return await usersQb.getMany();
},

async findOneConnection(connectionId: string): Promise<ConnectionEntity> {
async findOneConnection(connectionId: string): Promise<ConnectionEntity | null> {
const connectionQb = this.createQueryBuilder('connection')
.leftJoinAndSelect('connection.connection_properties', 'connection_properties')
.where('connection.id = :connectionId', {
Expand All @@ -82,7 +84,7 @@ export const customConnectionRepositoryExtension: IConnectionRepository = {
return connection;
},

async findAndDecryptConnection(connectionId: string, masterPwd: string): Promise<ConnectionEntity> {
async findAndDecryptConnection(connectionId: string, masterPwd: string): Promise<ConnectionEntity | null> {
const qb = this.createQueryBuilder('connection')
.leftJoinAndSelect('connection.agent', 'agent')
.andWhere('connection.id = :connectionId', { connectionId: connectionId });
Expand Down Expand Up @@ -115,7 +117,7 @@ export const customConnectionRepositoryExtension: IConnectionRepository = {
return await this.remove(connection);
},

async findConnectionWithGroups(connectionId: string): Promise<ConnectionEntity> {
async findConnectionWithGroups(connectionId: string): Promise<ConnectionEntity | null> {
const qb = this.createQueryBuilder('connection')
.leftJoinAndSelect('connection.groups', 'group')
.andWhere('connection.id = :connectionId', { connectionId: connectionId });
Expand All @@ -134,7 +136,7 @@ export const customConnectionRepositoryExtension: IConnectionRepository = {
return freshNonTestConnectionsWithLogs;
},

async getConnectionByGroupIdWithCompanyAndUsersInCompany(groupId: string): Promise<ConnectionEntity> {
async getConnectionByGroupIdWithCompanyAndUsersInCompany(groupId: string): Promise<ConnectionEntity | null> {
const qb = this.createQueryBuilder('connection')
.leftJoinAndSelect('connection.groups', 'group')
.leftJoinAndSelect('connection.company', 'company')
Expand All @@ -143,11 +145,11 @@ export const customConnectionRepositoryExtension: IConnectionRepository = {
return await qb.getOne();
},

async findOneById(connectionId: string): Promise<ConnectionEntity> {
async findOneById(connectionId: string): Promise<ConnectionEntity | null> {
return await this.findOne({ where: { id: connectionId } });
},

async findOneAgentConnectionByToken(connectionToken: string): Promise<ConnectionEntity> {
async findOneAgentConnectionByToken(connectionToken: string): Promise<ConnectionEntity | null> {
const qb = this.createQueryBuilder('connection').leftJoinAndSelect('connection.agent', 'agent');
qb.andWhere('agent.token = :agentToken', { agentToken: connectionToken });
return await qb.getOne();
Expand Down
Loading
Loading