From 344610ddc75b4de000d5abcc0c53ec4649138d3e Mon Sep 17 00:00:00 2001 From: NamrataSweya Date: Thu, 25 Apr 2024 17:11:01 +0530 Subject: [PATCH 1/2] DR-758,worked on certificate issue,change in issuermeta data payload now added devcie internal_externalId instead of device row id --- apps/drec-api/private_key.pem | 28 ++++++++ .../certificate-log.service.ts | 20 +++++- .../src/pods/device/device.service.ts | 6 +- .../src/pods/issuer/issuer.service.ts | 67 +++++++++---------- apps/drec-api/src/pods/reads/reads.service.ts | 41 ++++++------ apps/drec-api/src/utils/types.ts | 2 +- 6 files changed, 105 insertions(+), 59 deletions(-) create mode 100644 apps/drec-api/private_key.pem diff --git a/apps/drec-api/private_key.pem b/apps/drec-api/private_key.pem new file mode 100644 index 000000000..499a6f211 --- /dev/null +++ b/apps/drec-api/private_key.pem @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDFHMSNmqhrUKjp +5NkcKyvD/oT5obYYxceFkS3qpJRdsmBGebjcJYloYUH5temaI7ptfX+i1G1aZHiR +znnfbwALh7pOLCegzfQZxdSSCdqj2O8Rp49vkFOM50yt8YKUCh557tk7tcMzaDTi +ti65Lw2nEEyqFXZNrGr6VUB0sKOPU4wjWfR2acYH3Lm3QhFJiIq9l6KEQhT/LRue +RakHU2zOnpBlwTEVGPYVE8B0TIv9NjdM0watKdJKAvR7Q+daR2GMuBDWbavKF7xM +8zjTFeCT7nw0cy2B2ma9pG/tUHHfY3l4obIwoUmVmNZES9/drNFsXz+Uq4NSR0qL +VzOQ4EknAgMBAAECggEABXuiYAoAS1PoDvGFtIni4sXOrx73cML3pNh//Xnsgpq2 +oN877CvDIbsq2aZcxCPgSLFn/oCINi57SBsFOtjcmHWDEi+aPpfcBWeCXTmW8l3T +cJtHmyPZnx7D/Eauii2p4VxqgIWy01g/uFq2/AG6EH6ck1Kbgteb9jCu5VAQjKkK +yoD14meaHhadJeC3avpxlwSm/bEnJgDh295R82gPQhLE7GtWBTrh2UcY1XjHceSp +J+DveQeetC6+cd/M/cVD55BAVul2IZgvHBGfqJVI7CiqeWIDOfD/lX5Axe5vb/AB +GQpM8eGnj5uhtFRWd+KgI5n8elFc13gNhYJBpJ1LuQKBgQDibAKieULkRwlePRZJ +JP1oeBBSYlyr4uWFLogaP4gSmkGsDfrcclW8nONf1Doa3prMPyUxZ9xJmlRicQ0c +jreN9oqScwbp8/6x1z4WTkvaVW+h8XD6dc90UFp+9zzcd9AMetMYlrfMR1a9FNV2 +BIfIQOVypdNqKGWCdrd27RaCVQKBgQDe3JbhLIxWfgUJHhHC2W8b4zHufJeizeqk +y44eVgvbGUGmP03IIOFnyckBwbBLY/awfU5u51f2h1D1GFzd9BwE5p75GWyCNvLi +0tlDWYuaeUCN3LVws4qpncJkFhCVNjlEHuReUKo8HD0juRNwsqd9aYb9VoCW3sSS +64KBraBxiwKBgQCxoBRNC54bYVMLGBckmJ0n2JDNYJbczWpLmd5x4QdJuLPuWyVC +zXtPNTD225IdxCZiNuNhp93b6/NpKtEjZx6+gvvgudZhsOVM9NOjQhclmEK0I6oD +AmsWD3d/BUw8lM2lDLIQJyTXX9u/B9oR9Knkwmx+DXMWY8yGlcWFyacP5QKBgQCn +Rd6haDR1fuT8sOsX2ufAgMirfiy6b+AcjQRA1MjVTKGvzHfvLG7C3fvXK6/NBlzU +n1jNeSrWyT4EmKKrnVuieg78XQ7Ktb+cbDHSkVVtPnEriWtOChSbtuN/B+iudiKJ +dL5n5BfCQlfJhlKHFjEMurYtVE3z74SP2eD8wHtafQKBgFsg04triENjWPexrudE +aR97QVcdwjHYRBlEWL/fjvmx33nviFPdhOkUrArSa76YuFIYkl7mIo7Ew58o1bQ+ +KCre6htOXf5mowRjA6eGso6e+kQ8Ok9ezqUqrwDMdbQEPI97cSL2hAO3pKqbUCSj +Y2SKht7m6SCySscqOtUbKcPD +-----END PRIVATE KEY----- diff --git a/apps/drec-api/src/pods/certificate-log/certificate-log.service.ts b/apps/drec-api/src/pods/certificate-log/certificate-log.service.ts index 69f5e664f..c94eaa3de 100755 --- a/apps/drec-api/src/pods/certificate-log/certificate-log.service.ts +++ b/apps/drec-api/src/pods/certificate-log/certificate-log.service.ts @@ -203,8 +203,15 @@ export class CertificateLogService { ); //going back 1 second in start and going forward 1 second in end await Promise.all( - obj.deviceIds.map(async (deviceid: number) => { - const device = await this.deviceService.findOne(deviceid); + obj.deviceIds.map(async (deviceid) => { + let device: Device; + if(typeof deviceid==='number'){ + device = await this.deviceService.findOne(deviceid); + } + if (typeof deviceid==='string'){ + device = await this.deviceService.findReads(deviceid); + } + const devicelog = await this.getCheckCertificateIssueDateLogForDevice( parseInt(groupid), @@ -291,7 +298,14 @@ export class CertificateLogService { await Promise.all( obj.deviceIds.map(async (deviceid: number) => { - const device = await this.deviceService.findOne(deviceid); + let device: Device; + if(typeof deviceid==='number'){ + device = await this.deviceService.findOne(deviceid); + } + if (typeof deviceid==='string'){ + device = await this.deviceService.findReads(deviceid); + } + const devicelog = await this.getCheckCertificateIssueDateLogForDevice( parseInt(groupid), diff --git a/apps/drec-api/src/pods/device/device.service.ts b/apps/drec-api/src/pods/device/device.service.ts index 3c7ad2563..6cb1ddda0 100755 --- a/apps/drec-api/src/pods/device/device.service.ts +++ b/apps/drec-api/src/pods/device/device.service.ts @@ -460,11 +460,15 @@ export class DeviceService { return device; } - async findReads(meterId: string): Promise { + async findReads(meterId: string): Promise { this.logger.verbose(`With in findReads`); const result = await this.repository.findOne({ where: { externalId: meterId }, }); + result.timezone = await getLocalTimeZoneFromDevice( + result.createdAt, + result, + ); delete result['organization']; return result ?? null; diff --git a/apps/drec-api/src/pods/issuer/issuer.service.ts b/apps/drec-api/src/pods/issuer/issuer.service.ts index 538d104bd..bc551f395 100755 --- a/apps/drec-api/src/pods/issuer/issuer.service.ts +++ b/apps/drec-api/src/pods/issuer/issuer.service.ts @@ -63,7 +63,7 @@ export class IssuerService { private baseReadsService: BaseReadsService, private httpService: HttpService, private readonly offChainCertificateService: OffChainCertificateService, - ) {} + ) { } // @Cron(CronExpression.EVERY_30_SECONDS) // @Cron('0 00 21 * * *') // Every day at 23:30 - Server Time @@ -238,9 +238,9 @@ export class IssuerService { //returns first find which is minimum and between next frequency if ( new Date(ele.createdAt).getTime() > - new Date(start_date).getTime() && + new Date(start_date).getTime() && new Date(ele.createdAt).getTime() < - new Date(newEndDate).getTime() + new Date(newEndDate).getTime() ) { return true; } @@ -422,7 +422,7 @@ export class IssuerService { if (group.reservationExpiryDate !== null) { if ( group.reservationExpiryDate.getTime() <= - group.reservationEndDate.getTime() || + group.reservationEndDate.getTime() || group.reservationExpiryDate.getTime() <= new Date().getTime() ) { await this.deviceService.removeFromGroup(device.id, group.id); @@ -443,7 +443,7 @@ export class IssuerService { if (group.reservationExpiryDate !== null) { if ( group.reservationExpiryDate.getTime() <= - group.reservationEndDate.getTime() || + group.reservationEndDate.getTime() || group.reservationExpiryDate.getTime() <= new Date().getTime() ) { await this.deviceService.removeFromGroup(device.id, group.id); @@ -470,7 +470,7 @@ export class IssuerService { if (group.reservationExpiryDate !== null) { if ( group.reservationExpiryDate.getTime() <= - group.reservationEndDate.getTime() || + group.reservationEndDate.getTime() || group.reservationExpiryDate.getTime() <= new Date().getTime() ) { await this.groupService.deactiveReaservation(group); @@ -627,7 +627,7 @@ export class IssuerService { start: startDate.toString(), end: endDate.toString(), }; - // console.log(readsFilter) + let allReadsForDeviceBetweenTimeRange: Array<{ timestamp: Date; value: number; @@ -635,7 +635,7 @@ export class IssuerService { device.externalId, readsFilter, ); - //console.log("482readdata", index, allReadsForDeviceBetweenTimeRange); + // console.log("482readdata", index, allReadsForDeviceBetweenTimeRange); if (allReadsForDeviceBetweenTimeRange != undefined) { if ( device.meterReadtype === 'Delta' || @@ -660,7 +660,7 @@ export class IssuerService { new Date(startDate.toString()), new Date(endDate.toString()), ); - // console.log("502certifieddevices", certifieddevices); + // console.log("502certifieddevices", certifieddevices); if ( certifieddevices.length > 0 && allReadsForDeviceBetweenTimeRange.length > 0 @@ -671,13 +671,13 @@ export class IssuerService { certifieddevices.forEach((certifieddevicesEle) => { if ( ele.timestamp.getTime() >= - new Date( - certifieddevicesEle.certificate_issuance_startdate, - ).getTime() && + new Date( + certifieddevicesEle.certificate_issuance_startdate, + ).getTime() && ele.timestamp.getTime() <= - new Date( - certifieddevicesEle.certificate_issuance_enddate, - ).getTime() + new Date( + certifieddevicesEle.certificate_issuance_enddate, + ).getTime() ) { readingInBetween = true; } @@ -689,7 +689,7 @@ export class IssuerService { } }); } - // console.log("521afterallReadsForDeviceBetweenTimeRange", allReadsForDeviceBetweenTimeRange); + // console.log("521afterallReadsForDeviceBetweenTimeRange", allReadsForDeviceBetweenTimeRange); allDevicesCompleteReadsBetweenTimeRange[index] = allReadsForDeviceBetweenTimeRange; @@ -766,7 +766,7 @@ export class IssuerService { let certificateTransactionUID = uuid(); await Promise.all( group.devices.map(async (device: IDevice, index) => { - // console.log("came inside previous readings check", allDevicesCompleteReadsBetweenTimeRange[index]); + console.log("came inside previous readings check", allDevicesCompleteReadsBetweenTimeRange[index]); let previousReading: Array<{ timestamp: Date; value: number }> = []; if (allDevicesCompleteReadsBetweenTimeRange[index].length > 0) { let endTimestampToCheck = new Date( @@ -775,7 +775,6 @@ export class IssuerService { ][0].timestamp.getTime() - 1000, ); let startTimeToCheck = device.createdAt; - try { previousReading = await this.readservice.findLastReadForMeterWithinRange( @@ -783,7 +782,7 @@ export class IssuerService { new Date(startTimeToCheck), endTimestampToCheck, ); - + if (previousReading.length == 0) { if (device.meterReadtype === ReadType.Delta) { previousReading = [ @@ -827,7 +826,7 @@ export class IssuerService { (accumulator, currentValue) => accumulator + currentValue.value, 0, ); - + let devicecertificatelogDto = new CheckCertificateIssueDateLogForDeviceEntity(); (devicecertificatelogDto.externalId = device.externalId), @@ -899,7 +898,7 @@ export class IssuerService { buyerReservationId: group.devicegroup_uid, isStandardIssuanceRequested: StandardCompliance.IREC, type: CertificateType.REC, - deviceIds: group.devices.map((device: IDevice) => device.id), + deviceIds: group.devices.map((device: IDevice) => device.externalId), //deviceGroup, groupId: group.id?.toString() || null, certificateTransactionUID: certificateTransactionUID.toString(), @@ -917,8 +916,8 @@ export class IssuerService { if ( group.authorityToExceed === false && group.targetVolumeCertificateGenerationRequestedInMegaWattHour + - totalReadValueMegaWattHour >= - group.targetVolumeInMegaWattHour + totalReadValueMegaWattHour >= + group.targetVolumeInMegaWattHour ) { this.groupService.endReservation(group.id, group, grouprequest); } @@ -994,7 +993,7 @@ export class IssuerService { buyerReservationId: group.devicegroup_uid, isStandardIssuanceRequested: StandardCompliance.IREC, type: CertificateType.REC, - deviceIds: [device.id], + deviceIds: [device.externalId], //deviceGroup, certificateTransactionUID: certificateTransactionUID.toString(), groupId: group.id?.toString() || null, @@ -1078,7 +1077,7 @@ export class IssuerService { this.logger.verbose(`With in handleLeftoverReadsByCountryCode`); const totalReadValueKw = group.leftoverReadsByCountryCode[countryCodeKey] ? totalReadValueW / 10 ** 3 + - group.leftoverReadsByCountryCode[countryCodeKey] + group.leftoverReadsByCountryCode[countryCodeKey] : totalReadValueW / 10 ** 3; const { integralVal, decimalVal } = this.separateIntegerAndDecimalByCountryCode(totalReadValueKw); @@ -1425,13 +1424,13 @@ export class IssuerService { certifieddevices.forEach((certifieddevicesEle) => { if ( ele.timestamp.getTime() >= - new Date( - certifieddevicesEle.certificate_issuance_startdate, - ).getTime() && + new Date( + certifieddevicesEle.certificate_issuance_startdate, + ).getTime() && ele.timestamp.getTime() <= - new Date( - certifieddevicesEle.certificate_issuance_enddate, - ).getTime() + new Date( + certifieddevicesEle.certificate_issuance_enddate, + ).getTime() ) { readingInBetween = true; } @@ -1555,7 +1554,7 @@ export class IssuerService { buyerReservationId: group.devicegroup_uid, isStandardIssuanceRequested: StandardCompliance.IREC, type: CertificateType.REC, - deviceIds: group.devices.map((device: IDevice) => device.id), + deviceIds: group.devices.map((device: IDevice) => device.externalId), //deviceGroup, groupId: group.id?.toString() || null, certificateTransactionUID: certificateTransactionUID.toString(), @@ -1570,8 +1569,8 @@ export class IssuerService { if ( group.authorityToExceed === false && group.targetVolumeCertificateGenerationRequestedInMegaWattHour + - totalReadValueMegaWattHour >= - group.targetVolumeInMegaWattHour + totalReadValueMegaWattHour >= + group.targetVolumeInMegaWattHour ) { this.groupService.endReservation(group.id, group, grouprequest); } diff --git a/apps/drec-api/src/pods/reads/reads.service.ts b/apps/drec-api/src/pods/reads/reads.service.ts index 4032015ed..e91efbc9a 100755 --- a/apps/drec-api/src/pods/reads/reads.service.ts +++ b/apps/drec-api/src/pods/reads/reads.service.ts @@ -425,15 +425,15 @@ export class ReadsService { // @ts-ignore if ( requeststartdate <= - DateTime.fromISO(new Date(historyAge).toISOString()) || + DateTime.fromISO(new Date(historyAge).toISOString()) || // @ts-ignore requeststartdate >= - DateTime.fromISO(new Date(device?.createdAt).toISOString()) || + DateTime.fromISO(new Date(device?.createdAt).toISOString()) || requestcurrentend <= - DateTime.fromISO(new Date(historyAge).toISOString()) || + DateTime.fromISO(new Date(historyAge).toISOString()) || // @ts-ignore requestcurrentend >= - DateTime.fromISO(new Date(device?.createdAt).toISOString()) + DateTime.fromISO(new Date(device?.createdAt).toISOString()) ) { return reject( new ConflictException({ @@ -601,7 +601,7 @@ export class ReadsService { if ( new Date(element.endtimestamp).getTime() < - new Date(lastvalue[0].datetime).getTime() || + new Date(lastvalue[0].datetime).getTime() || element.value <= lastvalue[0].value ) { return reject( @@ -687,7 +687,7 @@ export class ReadsService { Delta = Math.abs(element.value - lastvalue[0].value); if ( new Date(element.endtimestamp).getTime() < - new Date(lastvalue[0].datetime).getTime() || + new Date(lastvalue[0].datetime).getTime() || element.value <= lastvalue[0].value ) { return reject( @@ -761,6 +761,7 @@ export class ReadsService { |> range(start: ${startdate.getTime()}, stop: ${enddate.getTime()}) |> filter(fn: (r) => r.meter == "${meterId}" and r._field == "read") |> last()`; + return await this.execute(fluxQuery); } @@ -1357,13 +1358,13 @@ export class ReadsService { if (new Date(deviceOnboarded).getTime() < new Date(filter.end).getTime()) { this.logger.verbose( 'offset::::::::::::' + - filter.offset + - '\nlimit:::::::::::::' + - filter.limit + - '\n device onboarded::::::::::' + - deviceOnboarded.toString() + - '\nend:::::::::' + - filter.end.toString(), + filter.offset + + '\nlimit:::::::::::::' + + filter.limit + + '\n device onboarded::::::::::' + + deviceOnboarded.toString() + + '\nend:::::::::' + + filter.end.toString(), ); let readsFilter: FilterDTO = { @@ -1391,7 +1392,7 @@ export class ReadsService { } if ( new Date(filter.start).getTime() < - new Date(deviceOnboarded).getTime() || + new Date(deviceOnboarded).getTime() || new Date(filter.end).getTime() > new Date(deviceOnboarded).getTime() ) { const finalongoing = await this.getPaginatedData( @@ -1460,12 +1461,12 @@ export class ReadsService { this.logger.verbose( 'count of ong reads:::::::::::::::::::::::::::::::::::' + - (await this.getnumberOfOngReads( - filter.start, - filter.end, - externalId, - deviceOnboarded, - )), + (await this.getnumberOfOngReads( + filter.start, + filter.end, + externalId, + deviceOnboarded, + )), ); if (typeof pageNumber === 'number' && !isNaN(pageNumber)) { return { diff --git a/apps/drec-api/src/utils/types.ts b/apps/drec-api/src/utils/types.ts index 6378d31af..7bb233186 100755 --- a/apps/drec-api/src/utils/types.ts +++ b/apps/drec-api/src/utils/types.ts @@ -4,7 +4,7 @@ import { StandardCompliance, CertificateType } from './enums'; export interface ICertificateMetadata { version: string; - deviceIds: number[]; + deviceIds: string[]; //deviceGroup: DeviceGroupDTO; groupId: null | string; buyerReservationId?: string; From 3b8a25c77d5b85e196f133cb79ad303fde0ef17e Mon Sep 17 00:00:00 2001 From: NamrataSweya Date: Thu, 25 Apr 2024 17:14:20 +0530 Subject: [PATCH 2/2] delete apiuser private key file --- apps/drec-api/private_key.pem | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 apps/drec-api/private_key.pem diff --git a/apps/drec-api/private_key.pem b/apps/drec-api/private_key.pem deleted file mode 100644 index 499a6f211..000000000 --- a/apps/drec-api/private_key.pem +++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