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 @@ -20,8 +20,6 @@ export interface IConnectionRepository {

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

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

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

getConnectionByGroupIdWithCompanyAndUsersInCompany(groupId: string): Promise<ConnectionEntity>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Messages } from '../../../exceptions/text/messages.js';
import { Constants } from '../../../helpers/constants/constants.js';
import { Encryptor } from '../../../helpers/encryption/encryptor.js';
import { isConnectionTypeAgent } from '../../../helpers/index.js';
import { TableLogsEntity } from '../../table-logs/table-logs.entity.js';
import { UserEntity } from '../../user/user.entity.js';
import { ConnectionEntity } from '../connection.entity.js';
import { isTestConnectionUtil } from '../utils/is-test-connection-util.js';
Expand Down Expand Up @@ -128,41 +127,16 @@ export const customConnectionRepositoryExtension: IConnectionRepository = {
return await qb.getOne();
},

async getConnectionsWithNonNullUsersGCLIDs(): Promise<Array<ConnectionEntity>> {
const dateTwoWeeksAgo = Constants.TWO_WEEKS_AGO();
const connectionsQB = this.createQueryBuilder('connection')
.where('connection.createdAt > :date', { date: dateTwoWeeksAgo })
.leftJoinAndSelect('connection.author', 'user')
.andWhere('user.gclid IS NOT NULL');
const freshConnections: Array<ConnectionEntity> = await connectionsQB.getMany();
const testConnectionsHosts = Constants.getTestConnectionsArr().map((connection) => {
return connection.host;
});
return freshConnections.filter((connection: ConnectionEntity) => {
return !testConnectionsHosts.includes(connection.host);
});
},

async getWorkedConnectionsInTwoWeeks(): Promise<Array<ConnectionEntity>> {
const freshConnections = await this.getConnectionsWithNonNullUsersGCLIDs();
const workedFreshConnections: Array<ConnectionEntity> = await Promise.all(
freshConnections.map(async (connection: ConnectionEntity): Promise<ConnectionEntity | null> => {
const qb = this.manager
.getRepository(TableLogsEntity)
.createQueryBuilder('tableLogs')
.leftJoinAndSelect('tableLogs.connection_id', 'connection_id');
qb.andWhere('tableLogs.connection_id = :connection_id', { connection_id: connection.id });
const logs = await qb.getMany();
if (logs && logs.length > 0) {
return connection;
} else {
return null;
}
}),
);
return workedFreshConnections.filter((connection) => {
return !!connection;
});
const freshNonTestConnectionsWithLogs = await this.createQueryBuilder('connection')
.leftJoinAndSelect('connection.author', 'author')
.leftJoin('connection.logs', 'logs')
.where('connection.createdAt > :date', { date: Constants.TWO_WEEKS_AGO() })
.andWhere('author.gclid IS NOT NULL')
.andWhere('connection.isTestConnection = :isTest', { isTest: false })
.andWhere('logs.id IS NOT NULL')
.getMany();
return freshNonTestConnectionsWithLogs;
},

async getConnectionByGroupIdWithCompanyAndUsersInCompany(groupId: string): Promise<ConnectionEntity> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ export const userCustomRepositoryExtension: IUserRepository = {
const dateTwoWeeksAgo = Constants.TWO_WEEKS_AGO();
const usersQB = this.createQueryBuilder('user')
.where('user.createdAt > :date', { date: dateTwoWeeksAgo })
.andWhere('user.gclid IS NOT NULL');
.andWhere('user.gclid IS NOT NULL')
.andWhere('user.isDemoAccount = :isDemo', { isDemo: false });
return await usersQB.getMany();
},

Expand Down