diff --git a/src/ORM/client-statistics/client-statistics.service.ts b/src/ORM/client-statistics/client-statistics.service.ts index 9db40dc..de288d7 100644 --- a/src/ORM/client-statistics/client-statistics.service.ts +++ b/src/ORM/client-statistics/client-statistics.service.ts @@ -1,27 +1,20 @@ -import { Injectable, OnModuleDestroy } from '@nestjs/common'; +import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; -import { DataSource, QueryRunner, Repository } from 'typeorm'; +import { Repository } from 'typeorm'; import { ClientStatisticsEntity } from './client-statistics.entity'; @Injectable() -export class ClientStatisticsService implements OnModuleDestroy { - - private readUncommittedQueryRunner: QueryRunner; +export class ClientStatisticsService { constructor( - private readonly dataSource: DataSource, + @InjectRepository(ClientStatisticsEntity) private clientStatisticsRepository: Repository, ) { - this.readUncommittedQueryRunner = this.dataSource.createQueryRunner(); - this.readUncommittedQueryRunner.query('SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;') - } - onModuleDestroy() { - this.readUncommittedQueryRunner.release(); } public async save(clientStatistic: Partial) { @@ -54,9 +47,9 @@ export class ClientStatisticsService implements OnModuleDestroy { var yesterday = new Date(new Date().getTime() - (24 * 60 * 60 * 1000)); + const query = ` + SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; - var result = await this.readUncommittedQueryRunner.query( - ` SELECT time AS label, ROUND(((SUM(shares) * 4294967296) / 600)) AS data @@ -68,9 +61,11 @@ export class ClientStatisticsService implements OnModuleDestroy { time ORDER BY time - LIMIT 144; - ` - ); + LIMIT 144; + + `; + + const result: any[] = await this.clientStatisticsRepository.query(query); return result.map(res => {