From bb3d01933d2b0f7ab8ef319b5a1d118c8ea78727 Mon Sep 17 00:00:00 2001 From: Artem Niehrieiev Date: Tue, 9 Sep 2025 08:32:48 +0000 Subject: [PATCH 1/2] refactor: comment out SaaS-related logic in connection use cases --- .../use-cases/create-connection.use.case.ts | 29 +++++++--------- .../use-cases/restore-connection-use.case.ts | 21 ++---------- .../use-cases/unfreeze-connection.use.case.ts | 33 ++++++++----------- .../use-cases/update-connection.use.case.ts | 30 ++++++++--------- 4 files changed, 41 insertions(+), 72 deletions(-) diff --git a/backend/src/entities/connection/use-cases/create-connection.use.case.ts b/backend/src/entities/connection/use-cases/create-connection.use.case.ts index 104398da9..88995e20f 100644 --- a/backend/src/entities/connection/use-cases/create-connection.use.case.ts +++ b/backend/src/entities/connection/use-cases/create-connection.use.case.ts @@ -3,13 +3,8 @@ import { getDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-acce 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 { SubscriptionLevelEnum } from '../../../enums/subscription-level.enum.js'; -import { NonAvailableInFreePlanException } from '../../../exceptions/custom-exceptions/non-available-in-free-plan-exception.js'; import { Messages } from '../../../exceptions/text/messages.js'; -import { isSaaS } from '../../../helpers/app/is-saas.js'; -import { Constants } from '../../../helpers/constants/constants.js'; import { isConnectionTypeAgent, slackPostMessage } from '../../../helpers/index.js'; -import { SaasCompanyGatewayService } from '../../../microservices/gateways/saas-gateway.ts/saas-company-gateway.service.js'; import { UserRoleEnum } from '../../user/enums/user-role.enum.js'; import { UserEntity } from '../../user/user.entity.js'; import { CreateConnectionDs } from '../application/data-structures/create-connection.ds.js'; @@ -29,7 +24,7 @@ export class CreateConnectionUseCase constructor( @Inject(BaseType.GLOBAL_DB_CONTEXT) protected _dbContext: IGlobalDatabaseContext, - private readonly saasCompanyGatewayService: SaasCompanyGatewayService, + // private readonly saasCompanyGatewayService: SaasCompanyGatewayService, ) { super(); } @@ -39,17 +34,17 @@ export class CreateConnectionUseCase } = createConnectionData; const connectionAuthor: UserEntity = await this._dbContext.userRepository.findOneUserById(authorId); - if (isSaaS()) { - const userCompany = await this._dbContext.companyInfoRepository.finOneCompanyInfoByUserId(authorId); - const companyInfoFromSaas = await this.saasCompanyGatewayService.getCompanyInfo(userCompany.id); - if (companyInfoFromSaas.subscriptionLevel === SubscriptionLevelEnum.FREE_PLAN) { - if (Constants.NON_FREE_PLAN_CONNECTION_TYPES.includes(createConnectionData.connection_parameters.type)) { - throw new NonAvailableInFreePlanException( - Messages.CANNOT_CREATE_CONNECTION_THIS_TYPE_IN_FREE_PLAN(createConnectionData.connection_parameters.type), - ); - } - } - } + // if (isSaaS()) { + // const userCompany = await this._dbContext.companyInfoRepository.finOneCompanyInfoByUserId(authorId); + // const companyInfoFromSaas = await this.saasCompanyGatewayService.getCompanyInfo(userCompany.id); + // if (companyInfoFromSaas.subscriptionLevel === SubscriptionLevelEnum.FREE_PLAN) { + // if (Constants.NON_FREE_PLAN_CONNECTION_TYPES.includes(createConnectionData.connection_parameters.type)) { + // throw new NonAvailableInFreePlanException( + // Messages.CANNOT_CREATE_CONNECTION_THIS_TYPE_IN_FREE_PLAN(createConnectionData.connection_parameters.type), + // ); + // } + // } + // } if (!connectionAuthor) { throw new InternalServerErrorException(Messages.USER_NOT_FOUND); diff --git a/backend/src/entities/connection/use-cases/restore-connection-use.case.ts b/backend/src/entities/connection/use-cases/restore-connection-use.case.ts index 59aaec01c..2e0ca2f9a 100644 --- a/backend/src/entities/connection/use-cases/restore-connection-use.case.ts +++ b/backend/src/entities/connection/use-cases/restore-connection-use.case.ts @@ -3,13 +3,8 @@ import { HttpException } from '@nestjs/common/exceptions/http.exception.js'; 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 { SubscriptionLevelEnum } from '../../../enums/subscription-level.enum.js'; -import { NonAvailableInFreePlanException } from '../../../exceptions/custom-exceptions/non-available-in-free-plan-exception.js'; import { Messages } from '../../../exceptions/text/messages.js'; -import { isSaaS } from '../../../helpers/app/is-saas.js'; -import { Constants } from '../../../helpers/constants/constants.js'; import { isConnectionEntityAgent } from '../../../helpers/index.js'; -import { SaasCompanyGatewayService } from '../../../microservices/gateways/saas-gateway.ts/saas-company-gateway.service.js'; import { RestoredConnectionDs } from '../application/data-structures/restored-connection.ds.js'; import { UpdateConnectionDs } from '../application/data-structures/update-connection.ds.js'; import { buildCreatedConnectionDs } from '../utils/build-created-connection.ds.js'; @@ -26,7 +21,7 @@ export class RestoreConnectionUseCase constructor( @Inject(BaseType.GLOBAL_DB_CONTEXT) protected _dbContext: IGlobalDatabaseContext, - private readonly saasCompanyGatewayService: SaasCompanyGatewayService, + // private readonly saasCompanyGatewayService: SaasCompanyGatewayService, ) { super(); } @@ -34,7 +29,7 @@ export class RestoreConnectionUseCase protected async implementation(connectionData: UpdateConnectionDs): Promise { const { connection_parameters, - update_info: { connectionId, authorId }, + update_info: { connectionId }, } = connectionData; if (connection_parameters.masterEncryption && !connectionData.update_info.masterPwd) { @@ -65,18 +60,6 @@ export class RestoreConnectionUseCase ); } - if (isSaaS()) { - const userCompany = await this._dbContext.companyInfoRepository.finOneCompanyInfoByUserId(authorId); - const companyInfoFromSaas = await this.saasCompanyGatewayService.getCompanyInfo(userCompany.id); - if (companyInfoFromSaas.subscriptionLevel === SubscriptionLevelEnum.FREE_PLAN) { - if (Constants.NON_FREE_PLAN_CONNECTION_TYPES.includes(connection_parameters.type)) { - throw new NonAvailableInFreePlanException( - Messages.CANNOT_CREATE_CONNECTION_THIS_TYPE_IN_FREE_PLAN(connection_parameters.type), - ); - } - } - } - const isTestConnection = isHostTest(connectionData.connection_parameters.host); const updatedConnection = await updateConnectionEntityForRestoration( foundConnection, diff --git a/backend/src/entities/connection/use-cases/unfreeze-connection.use.case.ts b/backend/src/entities/connection/use-cases/unfreeze-connection.use.case.ts index 7535ce61a..8fe022a9c 100644 --- a/backend/src/entities/connection/use-cases/unfreeze-connection.use.case.ts +++ b/backend/src/entities/connection/use-cases/unfreeze-connection.use.case.ts @@ -5,13 +5,6 @@ import { BaseType } from '../../../common/data-injection.tokens.js'; import { SuccessResponse } from '../../../microservices/saas-microservice/data-structures/common-responce.ds.js'; import { UnfreezeConnectionDs } from '../application/data-structures/unfreeze-connection.ds.js'; import { IUnfreezeConnection } from './use-cases.interfaces.js'; -import { isSaaS } from '../../../helpers/app/is-saas.js'; -import { Messages } from '../../../exceptions/text/messages.js'; -import { NonAvailableInFreePlanException } from '../../../exceptions/custom-exceptions/non-available-in-free-plan-exception.js'; -import { Constants } from '../../../helpers/constants/constants.js'; -import { SaasCompanyGatewayService } from '../../../microservices/gateways/saas-gateway.ts/saas-company-gateway.service.js'; -import { SubscriptionLevelEnum } from '../../../enums/subscription-level.enum.js'; -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; @Injectable({ scope: Scope.REQUEST }) export class UnfreezeConnectionUseCase @@ -21,27 +14,27 @@ export class UnfreezeConnectionUseCase constructor( @Inject(BaseType.GLOBAL_DB_CONTEXT) protected _dbContext: IGlobalDatabaseContext, - private readonly saasCompanyGatewayService: SaasCompanyGatewayService, + // private readonly saasCompanyGatewayService: SaasCompanyGatewayService, ) { super(); } protected async implementation(inputData: UnfreezeConnectionDs): Promise { - const { connectionId, userId } = inputData; + const { connectionId } = inputData; const connection = await this._dbContext.connectionRepository.findOne({ where: { id: connectionId } }); - if (isSaaS()) { - const userCompany = await this._dbContext.companyInfoRepository.finOneCompanyInfoByUserId(userId); - const companyInfoFromSaas = await this.saasCompanyGatewayService.getCompanyInfo(userCompany.id); - if (companyInfoFromSaas.subscriptionLevel === SubscriptionLevelEnum.FREE_PLAN) { - if (Constants.NON_FREE_PLAN_CONNECTION_TYPES.includes(connection.type as ConnectionTypesEnum)) { - throw new NonAvailableInFreePlanException( - Messages.CANNOT_CREATE_CONNECTION_THIS_TYPE_IN_FREE_PLAN(connection.type as ConnectionTypesEnum), - ); - } - } - } + // if (isSaaS()) { + // const userCompany = await this._dbContext.companyInfoRepository.finOneCompanyInfoByUserId(userId); + // const companyInfoFromSaas = await this.saasCompanyGatewayService.getCompanyInfo(userCompany.id); + // if (companyInfoFromSaas.subscriptionLevel === SubscriptionLevelEnum.FREE_PLAN) { + // if (Constants.NON_FREE_PLAN_CONNECTION_TYPES.includes(connection.type as ConnectionTypesEnum)) { + // throw new NonAvailableInFreePlanException( + // Messages.CANNOT_CREATE_CONNECTION_THIS_TYPE_IN_FREE_PLAN(connection.type as ConnectionTypesEnum), + // ); + // } + // } + // } connection.is_frozen = false; await this._dbContext.connectionRepository.save(connection); diff --git a/backend/src/entities/connection/use-cases/update-connection.use.case.ts b/backend/src/entities/connection/use-cases/update-connection.use.case.ts index 1d21b70b4..5dfa9d07c 100644 --- a/backend/src/entities/connection/use-cases/update-connection.use.case.ts +++ b/backend/src/entities/connection/use-cases/update-connection.use.case.ts @@ -3,14 +3,12 @@ import { HttpException } from '@nestjs/common/exceptions/http.exception.js'; 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 { AmplitudeEventTypeEnum, SubscriptionLevelEnum } from '../../../enums/index.js'; -import { NonAvailableInFreePlanException } from '../../../exceptions/custom-exceptions/non-available-in-free-plan-exception.js'; +import { AmplitudeEventTypeEnum } from '../../../enums/index.js'; import { Messages } from '../../../exceptions/text/messages.js'; -import { isSaaS } from '../../../helpers/app/is-saas.js'; import { Constants } from '../../../helpers/constants/constants.js'; import { Encryptor } from '../../../helpers/encryption/encryptor.js'; import { isConnectionTypeAgent } from '../../../helpers/index.js'; -import { SaasCompanyGatewayService } from '../../../microservices/gateways/saas-gateway.ts/saas-company-gateway.service.js'; +// import { SaasCompanyGatewayService } from '../../../microservices/gateways/saas-gateway.ts/saas-company-gateway.service.js'; import { AmplitudeService } from '../../amplitude/amplitude.service.js'; import { UpdateConnectionDs } from '../application/data-structures/update-connection.ds.js'; import { CreatedConnectionDTO } from '../application/dto/created-connection.dto.js'; @@ -29,7 +27,7 @@ export class UpdateConnectionUseCase @Inject(BaseType.GLOBAL_DB_CONTEXT) protected _dbContext: IGlobalDatabaseContext, private readonly amplitudeService: AmplitudeService, - private readonly saasCompanyGatewayService: SaasCompanyGatewayService, + // private readonly saasCompanyGatewayService: SaasCompanyGatewayService, ) { super(); } @@ -43,17 +41,17 @@ export class UpdateConnectionUseCase let { connection_parameters } = updateConnectionData; await validateCreateConnectionData(updateConnectionData); - if (isSaaS()) { - const userCompany = await this._dbContext.companyInfoRepository.finOneCompanyInfoByUserId(authorId); - const companyInfoFromSaas = await this.saasCompanyGatewayService.getCompanyInfo(userCompany.id); - if (companyInfoFromSaas.subscriptionLevel === SubscriptionLevelEnum.FREE_PLAN) { - if (Constants.NON_FREE_PLAN_CONNECTION_TYPES.includes(updateConnectionData.connection_parameters.type)) { - throw new NonAvailableInFreePlanException( - Messages.CANNOT_CREATE_CONNECTION_THIS_TYPE_IN_FREE_PLAN(updateConnectionData.connection_parameters.type), - ); - } - } - } + // if (isSaaS()) { + // const userCompany = await this._dbContext.companyInfoRepository.finOneCompanyInfoByUserId(authorId); + // const companyInfoFromSaas = await this.saasCompanyGatewayService.getCompanyInfo(userCompany.id); + // if (companyInfoFromSaas.subscriptionLevel === SubscriptionLevelEnum.FREE_PLAN) { + // if (Constants.NON_FREE_PLAN_CONNECTION_TYPES.includes(updateConnectionData.connection_parameters.type)) { + // throw new NonAvailableInFreePlanException( + // Messages.CANNOT_CREATE_CONNECTION_THIS_TYPE_IN_FREE_PLAN(updateConnectionData.connection_parameters.type), + // ); + // } + // } + // } const foundConnectionToUpdate = await this._dbContext.connectionRepository.findAndDecryptConnection( connectionId, From 2f42b962c40c8ae248002fdbe19265bfb0dbcc34 Mon Sep 17 00:00:00 2001 From: Artem Niehrieiev Date: Tue, 9 Sep 2025 08:34:28 +0000 Subject: [PATCH 2/2] refactor: comment out implementation logic in FreezeConnectionsInCompanyUseCase --- .../freeze-connections-in-company.use.case.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/backend/src/microservices/saas-microservice/use-cases/freeze-connections-in-company.use.case.ts b/backend/src/microservices/saas-microservice/use-cases/freeze-connections-in-company.use.case.ts index 97be13ba7..a350a8faf 100644 --- a/backend/src/microservices/saas-microservice/use-cases/freeze-connections-in-company.use.case.ts +++ b/backend/src/microservices/saas-microservice/use-cases/freeze-connections-in-company.use.case.ts @@ -18,11 +18,12 @@ export class FreezeConnectionsInCompanyUseCase super(); } - protected async implementation(inputData: FreezeConnectionsInCompanyDS): Promise { - const { companyIds } = inputData; - const companyPaidConnections = await this._dbContext.companyInfoRepository.findCompaniesPaidConnections(companyIds); - const connectionsIds = companyPaidConnections.map((connection) => connection.id); - await this._dbContext.connectionRepository.freezeConnections(connectionsIds); + protected async implementation(_inputData: FreezeConnectionsInCompanyDS): Promise { return { success: true }; + // const { companyIds } = inputData; + // const companyPaidConnections = await this._dbContext.companyInfoRepository.findCompaniesPaidConnections(companyIds); + // const connectionsIds = companyPaidConnections.map((connection) => connection.id); + // await this._dbContext.connectionRepository.freezeConnections(connectionsIds); + // return { success: true }; } }