From 86e358e85e067bc8e92f791581119fcc74f7a28a Mon Sep 17 00:00:00 2001 From: Kingcedru Date: Tue, 10 Dec 2024 17:19:01 +0200 Subject: [PATCH] feat: adding the storing method --- apps/drec-api/src/drec.module.ts | 2 ++ .../src/pods/file/file-processing.entity.ts | 3 --- apps/drec-api/src/pods/reads/reads.module.ts | 2 ++ apps/drec-api/src/pods/reads/reads.processor.ts | 2 ++ apps/drec-api/src/pods/reads/reads.service.ts | 16 ++++++++++++++++ 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/apps/drec-api/src/drec.module.ts b/apps/drec-api/src/drec.module.ts index 59580fd1b..cde00befb 100755 --- a/apps/drec-api/src/drec.module.ts +++ b/apps/drec-api/src/drec.module.ts @@ -63,6 +63,7 @@ import { UserLoginSessionEntity } from './pods/user/user_login_session.entity'; import { DeviceLateongoingIssueCertificateEntity } from './pods/device/device_lateongoing_certificate.entity'; import { CertificateSettingEntity } from './pods/device-group/certificate_setting.entity'; import { HttpModule } from '@nestjs/axios'; +import { FileProcessingEntity } from './pods/file/file-processing.entity'; const getEnvFilePath = () => { const pathsToTest = [ @@ -113,6 +114,7 @@ export const entities = [ ...IssuerEntities, ...OnChainCertificateEntities, ...OffChainCertificateEntities, + FileProcessingEntity, ]; const OriginAppTypeOrmModule = () => { diff --git a/apps/drec-api/src/pods/file/file-processing.entity.ts b/apps/drec-api/src/pods/file/file-processing.entity.ts index f34735e9b..bcb5099b7 100755 --- a/apps/drec-api/src/pods/file/file-processing.entity.ts +++ b/apps/drec-api/src/pods/file/file-processing.entity.ts @@ -17,9 +17,6 @@ export enum FileProcessingType { @Entity('file_processing_jobs') export class FileProcessingEntity extends ExtendedBaseEntity { - constructor() { - super(); - } @PrimaryGeneratedColumn('uuid') id: string; diff --git a/apps/drec-api/src/pods/reads/reads.module.ts b/apps/drec-api/src/pods/reads/reads.module.ts index e4cbf5a10..0e2a333da 100755 --- a/apps/drec-api/src/pods/reads/reads.module.ts +++ b/apps/drec-api/src/pods/reads/reads.module.ts @@ -18,6 +18,7 @@ import { DeltaFirstRead } from './delta_firstread.entity'; import { BullModule } from '@nestjs/bull'; import { FileModule } from '../file'; import { ReadsProcessor } from './reads.processor'; +import { FileProcessingEntity } from '../file/file-processing.entity'; const baseReadServiceProvider = { provide: BASE_READ_SERVICE, useFactory: (configService: ConfigService>) => { @@ -36,6 +37,7 @@ const baseReadServiceProvider = { AggregateMeterRead, HistoryIntermediate_MeterRead, DeltaFirstRead, + FileProcessingEntity ]), BullModule.registerQueue({ name: 'reads-queue', diff --git a/apps/drec-api/src/pods/reads/reads.processor.ts b/apps/drec-api/src/pods/reads/reads.processor.ts index f1edfd556..716a76ad5 100644 --- a/apps/drec-api/src/pods/reads/reads.processor.ts +++ b/apps/drec-api/src/pods/reads/reads.processor.ts @@ -47,6 +47,8 @@ export class ReadsProcessor { measurement, ); results.success++; + console.log("read", read) + await this.readsService.storeFileProccesingJobs(read, 2); } catch (error) { this.logger.error(`Error processing read: ${error.message}`); results.failed.push({ diff --git a/apps/drec-api/src/pods/reads/reads.service.ts b/apps/drec-api/src/pods/reads/reads.service.ts index 864cb6967..414e3a041 100755 --- a/apps/drec-api/src/pods/reads/reads.service.ts +++ b/apps/drec-api/src/pods/reads/reads.service.ts @@ -59,6 +59,8 @@ import { import { FileService } from '../file'; import { InjectQueue } from '@nestjs/bull'; import { Queue } from 'bull'; +import { MeterReadingCSV } from './parser/meter-reading-csv.parser'; +import { FileProcessingEntity, FileProcessingStatus, FileProcessingType } from '../file/file-processing.entity'; export type TUserBaseEntity = ExtendedBaseEntity & IAggregateintermediate; @@ -82,6 +84,8 @@ export class ReadsService { private readonly organizationService: OrganizationService, private readonly eventBus: EventBus, private readonly fileService: FileService, + @InjectRepository(FileProcessingEntity) + private readonly fileProcessingRepository: Repository, @InjectQueue('reads-queue') private readsQueue: Queue, ) { const url = process.env.INFLUXDB_URL || 'http://localhost:8086'; @@ -131,6 +135,18 @@ export class ReadsService { return aggregatedReads; } + + async storeFileProccesingJobs(record: MeterReadingCSV, user: any ): Promise { + const successful = { + userId: user, + fileId: record.deviceId, + organizationId: user.organizationId, + status: FileProcessingStatus.Completed, + type: FileProcessingType.AddMeterRead, + } + await this.fileProcessingRepository.save(successful); + console.log('success') + } async storeFailedReads( meterId: string, read: number,