Skip to content

Commit bc55751

Browse files
Merge branch 'main' into saml
2 parents 76bc1d7 + 1bebb1d commit bc55751

8 files changed

Lines changed: 58 additions & 115 deletions

File tree

backend/src/entities/connection/repository/connection.repository.interface.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ export interface IConnectionRepository {
2020

2121
findConnectionWithGroups(connectionId: string): Promise<ConnectionEntity>;
2222

23-
getConnectionsWithNonNullUsersGCLIDs(): Promise<Array<ConnectionEntity>>;
24-
2523
getWorkedConnectionsInTwoWeeks(): Promise<Array<ConnectionEntity>>;
2624

2725
getConnectionByGroupIdWithCompanyAndUsersInCompany(groupId: string): Promise<ConnectionEntity>;

backend/src/entities/connection/repository/custom-connection-repository-extension.ts

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Messages } from '../../../exceptions/text/messages.js';
22
import { Constants } from '../../../helpers/constants/constants.js';
33
import { Encryptor } from '../../../helpers/encryption/encryptor.js';
44
import { isConnectionTypeAgent } from '../../../helpers/index.js';
5-
import { TableLogsEntity } from '../../table-logs/table-logs.entity.js';
65
import { UserEntity } from '../../user/user.entity.js';
76
import { ConnectionEntity } from '../connection.entity.js';
87
import { isTestConnectionUtil } from '../utils/is-test-connection-util.js';
@@ -128,41 +127,16 @@ export const customConnectionRepositoryExtension: IConnectionRepository = {
128127
return await qb.getOne();
129128
},
130129

131-
async getConnectionsWithNonNullUsersGCLIDs(): Promise<Array<ConnectionEntity>> {
132-
const dateTwoWeeksAgo = Constants.TWO_WEEKS_AGO();
133-
const connectionsQB = this.createQueryBuilder('connection')
134-
.where('connection.createdAt > :date', { date: dateTwoWeeksAgo })
135-
.leftJoinAndSelect('connection.author', 'user')
136-
.andWhere('user.gclid IS NOT NULL');
137-
const freshConnections: Array<ConnectionEntity> = await connectionsQB.getMany();
138-
const testConnectionsHosts = Constants.getTestConnectionsArr().map((connection) => {
139-
return connection.host;
140-
});
141-
return freshConnections.filter((connection: ConnectionEntity) => {
142-
return !testConnectionsHosts.includes(connection.host);
143-
});
144-
},
145-
146130
async getWorkedConnectionsInTwoWeeks(): Promise<Array<ConnectionEntity>> {
147-
const freshConnections = await this.getConnectionsWithNonNullUsersGCLIDs();
148-
const workedFreshConnections: Array<ConnectionEntity> = await Promise.all(
149-
freshConnections.map(async (connection: ConnectionEntity): Promise<ConnectionEntity | null> => {
150-
const qb = this.manager
151-
.getRepository(TableLogsEntity)
152-
.createQueryBuilder('tableLogs')
153-
.leftJoinAndSelect('tableLogs.connection_id', 'connection_id');
154-
qb.andWhere('tableLogs.connection_id = :connection_id', { connection_id: connection.id });
155-
const logs = await qb.getMany();
156-
if (logs && logs.length > 0) {
157-
return connection;
158-
} else {
159-
return null;
160-
}
161-
}),
162-
);
163-
return workedFreshConnections.filter((connection) => {
164-
return !!connection;
165-
});
131+
const freshNonTestConnectionsWithLogs = await this.createQueryBuilder('connection')
132+
.leftJoinAndSelect('connection.author', 'author')
133+
.leftJoin('connection.logs', 'logs')
134+
.where('connection.createdAt > :date', { date: Constants.TWO_WEEKS_AGO() })
135+
.andWhere('author.gclid IS NOT NULL')
136+
.andWhere('connection.isTestConnection = :isTest', { isTest: false })
137+
.andWhere('logs.id IS NOT NULL')
138+
.getMany();
139+
return freshNonTestConnectionsWithLogs;
166140
},
167141

168142
async getConnectionByGroupIdWithCompanyAndUsersInCompany(groupId: string): Promise<ConnectionEntity> {

backend/src/entities/connection/use-cases/create-connection.use.case.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@ import { getDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-acce
33
import AbstractUseCase from '../../../common/abstract-use.case.js';
44
import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js';
55
import { BaseType } from '../../../common/data-injection.tokens.js';
6-
import { SubscriptionLevelEnum } from '../../../enums/subscription-level.enum.js';
7-
import { NonAvailableInFreePlanException } from '../../../exceptions/custom-exceptions/non-available-in-free-plan-exception.js';
86
import { Messages } from '../../../exceptions/text/messages.js';
9-
import { isSaaS } from '../../../helpers/app/is-saas.js';
10-
import { Constants } from '../../../helpers/constants/constants.js';
117
import { isConnectionTypeAgent, slackPostMessage } from '../../../helpers/index.js';
12-
import { SaasCompanyGatewayService } from '../../../microservices/gateways/saas-gateway.ts/saas-company-gateway.service.js';
138
import { UserRoleEnum } from '../../user/enums/user-role.enum.js';
149
import { UserEntity } from '../../user/user.entity.js';
1510
import { CreateConnectionDs } from '../application/data-structures/create-connection.ds.js';
@@ -29,7 +24,7 @@ export class CreateConnectionUseCase
2924
constructor(
3025
@Inject(BaseType.GLOBAL_DB_CONTEXT)
3126
protected _dbContext: IGlobalDatabaseContext,
32-
private readonly saasCompanyGatewayService: SaasCompanyGatewayService,
27+
// private readonly saasCompanyGatewayService: SaasCompanyGatewayService,
3328
) {
3429
super();
3530
}
@@ -39,17 +34,17 @@ export class CreateConnectionUseCase
3934
} = createConnectionData;
4035
const connectionAuthor: UserEntity = await this._dbContext.userRepository.findOneUserById(authorId);
4136

42-
if (isSaaS()) {
43-
const userCompany = await this._dbContext.companyInfoRepository.finOneCompanyInfoByUserId(authorId);
44-
const companyInfoFromSaas = await this.saasCompanyGatewayService.getCompanyInfo(userCompany.id);
45-
if (companyInfoFromSaas.subscriptionLevel === SubscriptionLevelEnum.FREE_PLAN) {
46-
if (Constants.NON_FREE_PLAN_CONNECTION_TYPES.includes(createConnectionData.connection_parameters.type)) {
47-
throw new NonAvailableInFreePlanException(
48-
Messages.CANNOT_CREATE_CONNECTION_THIS_TYPE_IN_FREE_PLAN(createConnectionData.connection_parameters.type),
49-
);
50-
}
51-
}
52-
}
37+
// if (isSaaS()) {
38+
// const userCompany = await this._dbContext.companyInfoRepository.finOneCompanyInfoByUserId(authorId);
39+
// const companyInfoFromSaas = await this.saasCompanyGatewayService.getCompanyInfo(userCompany.id);
40+
// if (companyInfoFromSaas.subscriptionLevel === SubscriptionLevelEnum.FREE_PLAN) {
41+
// if (Constants.NON_FREE_PLAN_CONNECTION_TYPES.includes(createConnectionData.connection_parameters.type)) {
42+
// throw new NonAvailableInFreePlanException(
43+
// Messages.CANNOT_CREATE_CONNECTION_THIS_TYPE_IN_FREE_PLAN(createConnectionData.connection_parameters.type),
44+
// );
45+
// }
46+
// }
47+
// }
5348

5449
if (!connectionAuthor) {
5550
throw new InternalServerErrorException(Messages.USER_NOT_FOUND);

backend/src/entities/connection/use-cases/restore-connection-use.case.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@ import { HttpException } from '@nestjs/common/exceptions/http.exception.js';
33
import AbstractUseCase from '../../../common/abstract-use.case.js';
44
import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js';
55
import { BaseType } from '../../../common/data-injection.tokens.js';
6-
import { SubscriptionLevelEnum } from '../../../enums/subscription-level.enum.js';
7-
import { NonAvailableInFreePlanException } from '../../../exceptions/custom-exceptions/non-available-in-free-plan-exception.js';
86
import { Messages } from '../../../exceptions/text/messages.js';
9-
import { isSaaS } from '../../../helpers/app/is-saas.js';
10-
import { Constants } from '../../../helpers/constants/constants.js';
117
import { isConnectionEntityAgent } from '../../../helpers/index.js';
12-
import { SaasCompanyGatewayService } from '../../../microservices/gateways/saas-gateway.ts/saas-company-gateway.service.js';
138
import { RestoredConnectionDs } from '../application/data-structures/restored-connection.ds.js';
149
import { UpdateConnectionDs } from '../application/data-structures/update-connection.ds.js';
1510
import { buildCreatedConnectionDs } from '../utils/build-created-connection.ds.js';
@@ -26,15 +21,15 @@ export class RestoreConnectionUseCase
2621
constructor(
2722
@Inject(BaseType.GLOBAL_DB_CONTEXT)
2823
protected _dbContext: IGlobalDatabaseContext,
29-
private readonly saasCompanyGatewayService: SaasCompanyGatewayService,
24+
// private readonly saasCompanyGatewayService: SaasCompanyGatewayService,
3025
) {
3126
super();
3227
}
3328

3429
protected async implementation(connectionData: UpdateConnectionDs): Promise<RestoredConnectionDs> {
3530
const {
3631
connection_parameters,
37-
update_info: { connectionId, authorId },
32+
update_info: { connectionId },
3833
} = connectionData;
3934

4035
if (connection_parameters.masterEncryption && !connectionData.update_info.masterPwd) {
@@ -65,18 +60,6 @@ export class RestoreConnectionUseCase
6560
);
6661
}
6762

68-
if (isSaaS()) {
69-
const userCompany = await this._dbContext.companyInfoRepository.finOneCompanyInfoByUserId(authorId);
70-
const companyInfoFromSaas = await this.saasCompanyGatewayService.getCompanyInfo(userCompany.id);
71-
if (companyInfoFromSaas.subscriptionLevel === SubscriptionLevelEnum.FREE_PLAN) {
72-
if (Constants.NON_FREE_PLAN_CONNECTION_TYPES.includes(connection_parameters.type)) {
73-
throw new NonAvailableInFreePlanException(
74-
Messages.CANNOT_CREATE_CONNECTION_THIS_TYPE_IN_FREE_PLAN(connection_parameters.type),
75-
);
76-
}
77-
}
78-
}
79-
8063
const isTestConnection = isHostTest(connectionData.connection_parameters.host);
8164
const updatedConnection = await updateConnectionEntityForRestoration(
8265
foundConnection,

backend/src/entities/connection/use-cases/unfreeze-connection.use.case.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ import { BaseType } from '../../../common/data-injection.tokens.js';
55
import { SuccessResponse } from '../../../microservices/saas-microservice/data-structures/common-responce.ds.js';
66
import { UnfreezeConnectionDs } from '../application/data-structures/unfreeze-connection.ds.js';
77
import { IUnfreezeConnection } from './use-cases.interfaces.js';
8-
import { isSaaS } from '../../../helpers/app/is-saas.js';
9-
import { Messages } from '../../../exceptions/text/messages.js';
10-
import { NonAvailableInFreePlanException } from '../../../exceptions/custom-exceptions/non-available-in-free-plan-exception.js';
11-
import { Constants } from '../../../helpers/constants/constants.js';
12-
import { SaasCompanyGatewayService } from '../../../microservices/gateways/saas-gateway.ts/saas-company-gateway.service.js';
13-
import { SubscriptionLevelEnum } from '../../../enums/subscription-level.enum.js';
14-
import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js';
158

169
@Injectable({ scope: Scope.REQUEST })
1710
export class UnfreezeConnectionUseCase
@@ -21,27 +14,27 @@ export class UnfreezeConnectionUseCase
2114
constructor(
2215
@Inject(BaseType.GLOBAL_DB_CONTEXT)
2316
protected _dbContext: IGlobalDatabaseContext,
24-
private readonly saasCompanyGatewayService: SaasCompanyGatewayService,
17+
// private readonly saasCompanyGatewayService: SaasCompanyGatewayService,
2518
) {
2619
super();
2720
}
2821

2922
protected async implementation(inputData: UnfreezeConnectionDs): Promise<SuccessResponse> {
30-
const { connectionId, userId } = inputData;
23+
const { connectionId } = inputData;
3124

3225
const connection = await this._dbContext.connectionRepository.findOne({ where: { id: connectionId } });
3326

34-
if (isSaaS()) {
35-
const userCompany = await this._dbContext.companyInfoRepository.finOneCompanyInfoByUserId(userId);
36-
const companyInfoFromSaas = await this.saasCompanyGatewayService.getCompanyInfo(userCompany.id);
37-
if (companyInfoFromSaas.subscriptionLevel === SubscriptionLevelEnum.FREE_PLAN) {
38-
if (Constants.NON_FREE_PLAN_CONNECTION_TYPES.includes(connection.type as ConnectionTypesEnum)) {
39-
throw new NonAvailableInFreePlanException(
40-
Messages.CANNOT_CREATE_CONNECTION_THIS_TYPE_IN_FREE_PLAN(connection.type as ConnectionTypesEnum),
41-
);
42-
}
43-
}
44-
}
27+
// if (isSaaS()) {
28+
// const userCompany = await this._dbContext.companyInfoRepository.finOneCompanyInfoByUserId(userId);
29+
// const companyInfoFromSaas = await this.saasCompanyGatewayService.getCompanyInfo(userCompany.id);
30+
// if (companyInfoFromSaas.subscriptionLevel === SubscriptionLevelEnum.FREE_PLAN) {
31+
// if (Constants.NON_FREE_PLAN_CONNECTION_TYPES.includes(connection.type as ConnectionTypesEnum)) {
32+
// throw new NonAvailableInFreePlanException(
33+
// Messages.CANNOT_CREATE_CONNECTION_THIS_TYPE_IN_FREE_PLAN(connection.type as ConnectionTypesEnum),
34+
// );
35+
// }
36+
// }
37+
// }
4538

4639
connection.is_frozen = false;
4740
await this._dbContext.connectionRepository.save(connection);

backend/src/entities/connection/use-cases/update-connection.use.case.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ import { HttpException } from '@nestjs/common/exceptions/http.exception.js';
33
import AbstractUseCase from '../../../common/abstract-use.case.js';
44
import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js';
55
import { BaseType } from '../../../common/data-injection.tokens.js';
6-
import { AmplitudeEventTypeEnum, SubscriptionLevelEnum } from '../../../enums/index.js';
7-
import { NonAvailableInFreePlanException } from '../../../exceptions/custom-exceptions/non-available-in-free-plan-exception.js';
6+
import { AmplitudeEventTypeEnum } from '../../../enums/index.js';
87
import { Messages } from '../../../exceptions/text/messages.js';
9-
import { isSaaS } from '../../../helpers/app/is-saas.js';
108
import { Constants } from '../../../helpers/constants/constants.js';
119
import { Encryptor } from '../../../helpers/encryption/encryptor.js';
1210
import { isConnectionTypeAgent } from '../../../helpers/index.js';
13-
import { SaasCompanyGatewayService } from '../../../microservices/gateways/saas-gateway.ts/saas-company-gateway.service.js';
11+
// import { SaasCompanyGatewayService } from '../../../microservices/gateways/saas-gateway.ts/saas-company-gateway.service.js';
1412
import { AmplitudeService } from '../../amplitude/amplitude.service.js';
1513
import { UpdateConnectionDs } from '../application/data-structures/update-connection.ds.js';
1614
import { CreatedConnectionDTO } from '../application/dto/created-connection.dto.js';
@@ -29,7 +27,7 @@ export class UpdateConnectionUseCase
2927
@Inject(BaseType.GLOBAL_DB_CONTEXT)
3028
protected _dbContext: IGlobalDatabaseContext,
3129
private readonly amplitudeService: AmplitudeService,
32-
private readonly saasCompanyGatewayService: SaasCompanyGatewayService,
30+
// private readonly saasCompanyGatewayService: SaasCompanyGatewayService,
3331
) {
3432
super();
3533
}
@@ -43,17 +41,17 @@ export class UpdateConnectionUseCase
4341
let { connection_parameters } = updateConnectionData;
4442
await validateCreateConnectionData(updateConnectionData);
4543

46-
if (isSaaS()) {
47-
const userCompany = await this._dbContext.companyInfoRepository.finOneCompanyInfoByUserId(authorId);
48-
const companyInfoFromSaas = await this.saasCompanyGatewayService.getCompanyInfo(userCompany.id);
49-
if (companyInfoFromSaas.subscriptionLevel === SubscriptionLevelEnum.FREE_PLAN) {
50-
if (Constants.NON_FREE_PLAN_CONNECTION_TYPES.includes(updateConnectionData.connection_parameters.type)) {
51-
throw new NonAvailableInFreePlanException(
52-
Messages.CANNOT_CREATE_CONNECTION_THIS_TYPE_IN_FREE_PLAN(updateConnectionData.connection_parameters.type),
53-
);
54-
}
55-
}
56-
}
44+
// if (isSaaS()) {
45+
// const userCompany = await this._dbContext.companyInfoRepository.finOneCompanyInfoByUserId(authorId);
46+
// const companyInfoFromSaas = await this.saasCompanyGatewayService.getCompanyInfo(userCompany.id);
47+
// if (companyInfoFromSaas.subscriptionLevel === SubscriptionLevelEnum.FREE_PLAN) {
48+
// if (Constants.NON_FREE_PLAN_CONNECTION_TYPES.includes(updateConnectionData.connection_parameters.type)) {
49+
// throw new NonAvailableInFreePlanException(
50+
// Messages.CANNOT_CREATE_CONNECTION_THIS_TYPE_IN_FREE_PLAN(updateConnectionData.connection_parameters.type),
51+
// );
52+
// }
53+
// }
54+
// }
5755

5856
const foundConnectionToUpdate = await this._dbContext.connectionRepository.findAndDecryptConnection(
5957
connectionId,

backend/src/entities/user/repository/user-custom-repository-extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ export const userCustomRepositoryExtension: IUserRepository = {
118118
const dateTwoWeeksAgo = Constants.TWO_WEEKS_AGO();
119119
const usersQB = this.createQueryBuilder('user')
120120
.where('user.createdAt > :date', { date: dateTwoWeeksAgo })
121-
.andWhere('user.gclid IS NOT NULL');
121+
.andWhere('user.gclid IS NOT NULL')
122+
.andWhere('user.isDemoAccount = :isDemo', { isDemo: false });
122123
return await usersQB.getMany();
123124
},
124125

backend/src/microservices/saas-microservice/use-cases/freeze-connections-in-company.use.case.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ export class FreezeConnectionsInCompanyUseCase
1818
super();
1919
}
2020

21-
protected async implementation(inputData: FreezeConnectionsInCompanyDS): Promise<SuccessResponse> {
22-
const { companyIds } = inputData;
23-
const companyPaidConnections = await this._dbContext.companyInfoRepository.findCompaniesPaidConnections(companyIds);
24-
const connectionsIds = companyPaidConnections.map((connection) => connection.id);
25-
await this._dbContext.connectionRepository.freezeConnections(connectionsIds);
21+
protected async implementation(_inputData: FreezeConnectionsInCompanyDS): Promise<SuccessResponse> {
2622
return { success: true };
23+
// const { companyIds } = inputData;
24+
// const companyPaidConnections = await this._dbContext.companyInfoRepository.findCompaniesPaidConnections(companyIds);
25+
// const connectionsIds = companyPaidConnections.map((connection) => connection.id);
26+
// await this._dbContext.connectionRepository.freezeConnections(connectionsIds);
27+
// return { success: true };
2728
}
2829
}

0 commit comments

Comments
 (0)