Skip to content

Commit

Permalink
feat: adding the storing method
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingcedru committed Dec 10, 2024
1 parent 3de8814 commit 86e358e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions apps/drec-api/src/drec.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -113,6 +114,7 @@ export const entities = [
...IssuerEntities,
...OnChainCertificateEntities,
...OffChainCertificateEntities,
FileProcessingEntity,
];

const OriginAppTypeOrmModule = () => {
Expand Down
3 changes: 0 additions & 3 deletions apps/drec-api/src/pods/file/file-processing.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ export enum FileProcessingType {

@Entity('file_processing_jobs')
export class FileProcessingEntity extends ExtendedBaseEntity {
constructor() {
super();
}

@PrimaryGeneratedColumn('uuid')
id: string;
Expand Down
2 changes: 2 additions & 0 deletions apps/drec-api/src/pods/reads/reads.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, any>>) => {
Expand All @@ -36,6 +37,7 @@ const baseReadServiceProvider = {
AggregateMeterRead,
HistoryIntermediate_MeterRead,
DeltaFirstRead,
FileProcessingEntity
]),
BullModule.registerQueue({
name: 'reads-queue',
Expand Down
2 changes: 2 additions & 0 deletions apps/drec-api/src/pods/reads/reads.processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
16 changes: 16 additions & 0 deletions apps/drec-api/src/pods/reads/reads.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<FileProcessingEntity>,
@InjectQueue('reads-queue') private readsQueue: Queue,
) {
const url = process.env.INFLUXDB_URL || 'http://localhost:8086';
Expand Down Expand Up @@ -131,6 +135,18 @@ export class ReadsService {

return aggregatedReads;
}

async storeFileProccesingJobs(record: MeterReadingCSV, user: any ): Promise<void> {

Check warning on line 139 in apps/drec-api/src/pods/reads/reads.service.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

Argument 'user' should be typed with a non-any type
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,
Expand Down

0 comments on commit 86e358e

Please sign in to comment.