Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -26,15 +21,15 @@ export class RestoreConnectionUseCase
constructor(
@Inject(BaseType.GLOBAL_DB_CONTEXT)
protected _dbContext: IGlobalDatabaseContext,
private readonly saasCompanyGatewayService: SaasCompanyGatewayService,
// private readonly saasCompanyGatewayService: SaasCompanyGatewayService,
) {
super();
}

protected async implementation(connectionData: UpdateConnectionDs): Promise<RestoredConnectionDs> {
const {
connection_parameters,
update_info: { connectionId, authorId },
update_info: { connectionId },
} = connectionData;

if (connection_parameters.masterEncryption && !connectionData.update_info.masterPwd) {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<SuccessResponse> {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
}
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ export class FreezeConnectionsInCompanyUseCase
super();
}

protected async implementation(inputData: FreezeConnectionsInCompanyDS): Promise<SuccessResponse> {
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<SuccessResponse> {
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 };
}
}