From b5af3d7baa44d8c7dbe220606661d2df94881de0 Mon Sep 17 00:00:00 2001 From: NamrataSweya Date: Fri, 20 Sep 2024 16:26:24 +0530 Subject: [PATCH 1/6] added default expire date in reservation on the bases on some no_of_days value if ,have no value in request,and chaned in lateongoing cron job,now as it is working on the bases of expire date lastcertiifcation --- .../1726558881946-certificate_setting.ts | 19 + .../drec-api/migrations/9999999999999-Seed.ts | 78 +++-- apps/drec-api/src/drec.module.ts | 2 + .../certificate-log.service.ts | 41 +-- .../buyer-reservation.controller.ts | 43 ++- .../certificate_setting.entity.ts | 18 + .../pods/device-group/device-group.module.ts | 3 + .../pods/device-group/device-group.service.ts | 75 ++-- .../src/pods/device/device.controller.ts | 2 +- .../src/pods/device/device.service.ts | 15 +- .../src/pods/issuer/issuer.service.ts | 328 ++++++++---------- .../synchronize-blockchain-task.service.ts | 2 +- .../src/pods/reads/reads.controller.ts | 2 +- version | 2 +- 14 files changed, 327 insertions(+), 303 deletions(-) create mode 100644 apps/drec-api/migrations/1726558881946-certificate_setting.ts create mode 100644 apps/drec-api/src/pods/device-group/certificate_setting.entity.ts diff --git a/apps/drec-api/migrations/1726558881946-certificate_setting.ts b/apps/drec-api/migrations/1726558881946-certificate_setting.ts new file mode 100644 index 000000000..d381aea93 --- /dev/null +++ b/apps/drec-api/migrations/1726558881946-certificate_setting.ts @@ -0,0 +1,19 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class certificateSetting1726558881946 implements MigrationInterface { + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + CREATE TABLE certificate_setting ( + id SERIAL PRIMARY KEY, + "no_of_days" integer NOT NULL DEFAULT 60, + "createdAt" timestamp with time zone NOT NULL DEFAULT now(), + "updatedAt" timestamp with time zone NOT NULL DEFAULT now() + )` + ); + } + + public async down(queryRunner: QueryRunner): Promise { + } + +} diff --git a/apps/drec-api/migrations/9999999999999-Seed.ts b/apps/drec-api/migrations/9999999999999-Seed.ts index dde8843f1..978e1a3d9 100644 --- a/apps/drec-api/migrations/9999999999999-Seed.ts +++ b/apps/drec-api/migrations/9999999999999-Seed.ts @@ -52,6 +52,7 @@ export class Seed9999999999999 implements MigrationInterface { await this.seedUsersRole(queryRunner); await this.seedAdmin(queryRunner); await this.seedACLModules(queryRunner); + await this.seedCertificateSetting(queryRunner);//set default no_of_days for generate certificate last day await queryRunner.query( `SELECT setval( pg_get_serial_sequence('public.organization', 'id'), @@ -72,7 +73,7 @@ export class Seed9999999999999 implements MigrationInterface { ); } - public async down(queryRunner: QueryRunner): Promise {} + public async down(queryRunner: QueryRunner): Promise { } private async seedBlockchain( queryRunner: QueryRunner, @@ -83,10 +84,8 @@ export class Seed9999999999999 implements MigrationInterface { if (provider && contractsLookup) { await queryRunner.query( - `INSERT INTO public.issuer_blockchain_properties ("netId", "registry", "issuer", "rpcNode", "rpcNodeFallback") VALUES (${ - provider.network.chainId - }, '${contractsLookup.registry}', '${ - contractsLookup.issuer + `INSERT INTO public.issuer_blockchain_properties ("netId", "registry", "issuer", "rpcNode", "rpcNodeFallback") VALUES (${provider.network.chainId + }, '${contractsLookup.registry}', '${contractsLookup.issuer }', '${primaryRpc}', '${fallbackRpc ?? ''}' )`, ); @@ -126,6 +125,7 @@ export class Seed9999999999999 implements MigrationInterface { }), ); } + private async deployContracts( deployer: Wallet, provider: providers.FallbackProvider, @@ -241,27 +241,27 @@ export class Seed9999999999999 implements MigrationInterface { bitPosition: number; andOperationNumber: number; }> = [ - { - permissionString: PermissionString.Read, - bitPosition: 1, - andOperationNumber: 1, - }, - { - permissionString: PermissionString.Write, - bitPosition: 2, - andOperationNumber: 2, - }, - { - permissionString: PermissionString.Update, - bitPosition: 3, - andOperationNumber: 4, - }, - { - permissionString: PermissionString.Delete, - bitPosition: 4, - andOperationNumber: 8, - }, - ]; + { + permissionString: PermissionString.Read, + bitPosition: 1, + andOperationNumber: 1, + }, + { + permissionString: PermissionString.Write, + bitPosition: 2, + andOperationNumber: 2, + }, + { + permissionString: PermissionString.Update, + bitPosition: 3, + andOperationNumber: 4, + }, + { + permissionString: PermissionString.Delete, + bitPosition: 4, + andOperationNumber: 8, + }, + ]; binaryFormPermission = '0000'; decimalFormPermission = 0; @@ -282,12 +282,12 @@ export class Seed9999999999999 implements MigrationInterface { (ACLModuleJSON as unknown as IACLModuleConfig[]).map( async (aclModule) => { const addedPermissionList: { [key in PermissionString]: boolean } = - { - Read: false, - Write: false, - Delete: false, - Update: false, - }; + { + Read: false, + Write: false, + Delete: false, + Update: false, + }; for (const key in addedPermissionList) { aclModule.permissions.map((myArr, index) => { if (myArr === key) { @@ -344,9 +344,21 @@ export class Seed9999999999999 implements MigrationInterface { decimalFormPermission = decimalFormPermission + Math.pow(2, ele.bitPosition - 1) * - (addedPermissionList[ele.permissionString] === true ? 1 : 0); + (addedPermissionList[ele.permissionString] === true ? 1 : 0); }); this.decimalFormPermission = decimalFormPermission; return this.decimalFormPermission; } + private async seedCertificateSetting(queryRunner: QueryRunner) { + const certificate_settingTable = await queryRunner.getTable('public.certificate_setting'); + + if (!certificate_settingTable) { + this.logger.verbose('certificate_setting table does not exist.'); + return; + } + queryRunner.query( + `INSERT INTO public.certificate_setting ("id","no_of_days") VALUES ( + 1,60)`, + ); + } } diff --git a/apps/drec-api/src/drec.module.ts b/apps/drec-api/src/drec.module.ts index b9edcc2ad..31118084d 100755 --- a/apps/drec-api/src/drec.module.ts +++ b/apps/drec-api/src/drec.module.ts @@ -61,6 +61,7 @@ import { OauthClientCredentials } from './pods/user/oauth_client_credentials.ent import { ApiUserEntity } from './pods/user/api-user.entity'; 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'; const getEnvFilePath = () => { @@ -108,6 +109,7 @@ export const entities = [ IrecErrorLogInformationEntity, UserLoginSessionEntity, DeviceLateongoingIssueCertificateEntity, + CertificateSettingEntity, ...IssuerEntities, ...OnChainCertificateEntities, ...OffChainCertificateEntities, 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 c9812f115..019dc3059 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 @@ -54,7 +54,7 @@ export class CertificateLogService { private deviceService: DeviceService, private devicegroupService: DeviceGroupService, - ) {} + ) { } public async find(): Promise { this.logger.verbose(`With in find`); @@ -625,8 +625,8 @@ export class CertificateLogService { pageNumber: number, ): Promise<{ certificatelog: - | CertificateNewWithPerDeviceLog[] - | CertificateWithPerdevicelog[]; + | CertificateNewWithPerDeviceLog[] + | CertificateWithPerdevicelog[]; currentpage?: number; totalPages: number; totalCount: number; @@ -701,11 +701,11 @@ export class CertificateLogService { async getDeveloperfindreservationcertified( certifiedreservation: | { - deviceGroups: any; - pageNumber: number; - totalPages: number; - totalCount: any; - } + deviceGroups: any; + pageNumber: number; + totalPages: number; + totalCount: any; + } | any, role: Role, ): Promise { @@ -850,11 +850,11 @@ export class CertificateLogService { async getDeveloperCertificatesUsingGroupIDVersionUpdateOrigin247( getreservationinfo: | { - deviceGroups: any; - pageNumber: number; - totalPages: number; - totalCount: any; - } + deviceGroups: any; + pageNumber: number; + totalPages: number; + totalCount: any; + } | any, role: Role, ): Promise { @@ -888,6 +888,7 @@ export class CertificateLogService { certifiedlist: ICertificateReadModel, index: number, ) => { + certificatesInReservationWithLog[index].certificateStartDate = new Date( certifiedlist.generationStartTime * 1000, @@ -923,9 +924,6 @@ 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); - - // const device = await this.deviceService.findOne(deviceid); let device: Device; if (typeof deviceid === 'number') { device = await this.deviceService.findOne(deviceid); @@ -933,11 +931,10 @@ export class CertificateLogService { if (typeof deviceid === 'string') { device = await this.deviceService.findReads(deviceid); } - let devicelog; if (role === 'OrganizationAdmin') { if ( - group.developerdeviceIds.find((ele) => ele === deviceid) + group.developerdeviceIds.find((ele) => ele === device.id) ) { devicelog = await this.getCheckCertificateIssueDateLogForDevice( @@ -1082,10 +1079,10 @@ export class CertificateLogService { res.setHeader( 'Content-Disposition', 'attachment; filename=' + - name + - ' ' + - new Date().toLocaleDateString() + - '.csv', + name + + ' ' + + new Date().toLocaleDateString() + + '.csv', ); res.setHeader('Content-Type', 'text/csv'); const csvString = `${headers.join(',')}\n${data.map((obj) => headers.map((key) => obj[key]).join(',')).join('\n')}`; diff --git a/apps/drec-api/src/pods/device-group/buyer-reservation.controller.ts b/apps/drec-api/src/pods/device-group/buyer-reservation.controller.ts index e2fb41890..30e025fa5 100644 --- a/apps/drec-api/src/pods/device-group/buyer-reservation.controller.ts +++ b/apps/drec-api/src/pods/device-group/buyer-reservation.controller.ts @@ -81,7 +81,7 @@ export class BuyerReservationController { private readonly fileService: FileService, private organizationService: OrganizationService, private readonly userService: UserService, - ) {} + ) { } /** * It is GET api to list all device group in reservation data @@ -132,11 +132,11 @@ export class BuyerReservationController { filterDto: UnreservedDeviceGroupsFilterDTO, ): Promise< | { - devicegroups: DeviceGroupDTO[]; - currentPage: number; - totalPages: number; - totalCount: number; - } + devicegroups: DeviceGroupDTO[]; + currentPage: number; + totalPages: number; + totalCount: number; + } | any | DeviceGroupDTO[] > { @@ -227,11 +227,11 @@ export class BuyerReservationController { @Query('pagenumber') pagenumber: number | null, ): Promise< | { - devicegroups: DeviceGroupDTO[]; - currentPage: number; - totalPages: number; - totalCount: number; - } + devicegroups: DeviceGroupDTO[]; + currentPage: number; + totalPages: number; + totalCount: number; + } | any | DeviceGroupDTO[] > { @@ -349,6 +349,7 @@ export class BuyerReservationController { @Query('orgId') orgId: number | null, ): Promise { this.logger.verbose(`With in createOne`); + deviceGroupToRegister.api_user_id = user.api_user_id; if (orgId) { const organization = await this.organizationService.findOne(orgId); const orguser = await this.userService.findByEmail(organization.orgEmail); @@ -360,12 +361,10 @@ export class BuyerReservationController { message: 'Organization requested belongs to other apiuser', }); } - if (orguser.role === Role.Buyer) { organizationId = orgId; deviceGroupToRegister.api_user_id = user.api_user_id; } - if (orguser.role != Role.Buyer) { this.logger.error(`Unauthorized for ${orguser.role}`); throw new UnauthorizedException({ @@ -502,7 +501,7 @@ export class BuyerReservationController { deviceGroupToRegister.reservationStartDate && deviceGroupToRegister.reservationEndDate && deviceGroupToRegister.reservationStartDate.getTime() >= - deviceGroupToRegister.reservationEndDate.getTime() + deviceGroupToRegister.reservationEndDate.getTime() ) { this.logger.error(`start date cannot be less than or same as end date`); throw new ConflictException({ @@ -517,7 +516,7 @@ export class BuyerReservationController { (deviceGroupToRegister.reservationExpiryDate.getTime() <= deviceGroupToRegister.reservationStartDate.getTime() || deviceGroupToRegister.reservationExpiryDate.getTime() < - deviceGroupToRegister.reservationEndDate.getTime()) + deviceGroupToRegister.reservationEndDate.getTime()) ) { this.logger.error( `Expiry date cannot be less than from start and end date`, @@ -533,9 +532,9 @@ export class BuyerReservationController { ); if ( deviceGroupToRegister.reservationStartDate.getTime() <= - maximumBackDateForReservation.getTime() || + maximumBackDateForReservation.getTime() || deviceGroupToRegister.reservationEndDate.getTime() <= - maximumBackDateForReservation.getTime() + maximumBackDateForReservation.getTime() ) { this.logger.error( `start date or end date cannot be less than 3 year from current date`, @@ -817,11 +816,11 @@ export class BuyerReservationController { @Query('limit', new DefaultValuePipe(0), ParseIntPipe) limit: number, ): Promise< | { - csvJobs: Array; - currentPage: number; - totalPages: number; - totalCount: number; - } + csvJobs: Array; + currentPage: number; + totalPages: number; + totalCount: number; + } | any > { this.logger.verbose(`With in getAllCsvJobsBelongingToOrganization`); diff --git a/apps/drec-api/src/pods/device-group/certificate_setting.entity.ts b/apps/drec-api/src/pods/device-group/certificate_setting.entity.ts new file mode 100644 index 000000000..06c9f2194 --- /dev/null +++ b/apps/drec-api/src/pods/device-group/certificate_setting.entity.ts @@ -0,0 +1,18 @@ +import { ExtendedBaseEntity } from '@energyweb/origin-backend-utils'; +import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'; + +import { IsNumber } from 'class-validator'; + +@Entity('certificate_setting') +export class CertificateSettingEntity extends ExtendedBaseEntity { + + + @PrimaryGeneratedColumn() + id: number; + + @Column() + @IsNumber() + no_of_days: number; + + +} \ No newline at end of file diff --git a/apps/drec-api/src/pods/device-group/device-group.module.ts b/apps/drec-api/src/pods/device-group/device-group.module.ts index f9cf28832..d3026da6f 100644 --- a/apps/drec-api/src/pods/device-group/device-group.module.ts +++ b/apps/drec-api/src/pods/device-group/device-group.module.ts @@ -16,6 +16,7 @@ import { CertificateReadModelEntity } from '@energyweb/origin-247-certificate/di import { CheckCertificateIssueDateLogForDeviceEntity } from '../device/check_certificate_issue_date_log_for_device.entity'; import { Certificate } from '@energyweb/issuer-api'; import { UserModule } from '../user/user.module'; +import {CertificateSettingEntity} from './certificate_setting.entity'; @Module({ imports: [ TypeOrmModule.forFeature([ @@ -28,6 +29,8 @@ import { UserModule } from '../user/user.module'; CertificateReadModelEntity, CheckCertificateIssueDateLogForDeviceEntity, Certificate, + CertificateSettingEntity + ]), forwardRef(() => DeviceModule), diff --git a/apps/drec-api/src/pods/device-group/device-group.service.ts b/apps/drec-api/src/pods/device-group/device-group.service.ts index 2aaa1bf77..4d74a65e7 100755 --- a/apps/drec-api/src/pods/device-group/device-group.service.ts +++ b/apps/drec-api/src/pods/device-group/device-group.service.ts @@ -84,7 +84,7 @@ import { Certificate } from '@energyweb/issuer-api'; import { UserService } from '../user/user.service'; import { ICertificateMetadata } from '../../utils/types'; import { FilterDTO } from '../certificate-log/dto'; - +import { CertificateSettingEntity } from './certificate_setting.entity'; @Injectable() export class DeviceGroupService { csvParser = csv({ separator: ',' }); @@ -112,7 +112,9 @@ export class DeviceGroupService { CertificateReadModelEntity >, private readonly userService: UserService, - ) {} + @InjectRepository(CertificateSettingEntity) + private readonly certificate_settingrepository: Repository + ) { } async getAll( user?: ILoggedInUser, @@ -123,11 +125,11 @@ export class DeviceGroupService { filterDto?: UnreservedDeviceGroupsFilterDTO, ): Promise< | { - devicegroups: DeviceGroupDTO[]; - currentPage: number; - totalPages: number; - totalCount: number; - } + devicegroups: DeviceGroupDTO[]; + currentPage: number; + totalPages: number; + totalCount: number; + } | any > { this.logger.verbose(`With in dg service ${filterDto}`); @@ -774,11 +776,11 @@ export class DeviceGroupService { limit?: number, ): Promise< | { - csvJobs: Array; - currentPage: number; - totalPages: number; - totalCount: number; - } + csvJobs: Array; + currentPage: number; + totalPages: number; + totalCount: number; + } | any > { this.logger.verbose(`With in getAllCSVJobsForOrganization`); @@ -819,11 +821,11 @@ export class DeviceGroupService { limit?: number, ): Promise< | { - csvJobs: Array; - currentPage: number; - totalPages: number; - totalCount: number; - } + csvJobs: Array; + currentPage: number; + totalPages: number; + totalCount: number; + } | any > { this.logger.verbose(`With in getAllCSVJobsForAdmin`); @@ -930,9 +932,9 @@ export class DeviceGroupService { devices.filter((ele) => { if ( new Date(data.reservationStartDate).getTime() < - new Date(ele.createdAt).getTime() && + new Date(ele.createdAt).getTime() && new Date(data.reservationEndDate).getTime() <= - new Date(ele.createdAt).getTime() + new Date(ele.createdAt).getTime() ) { return true; } @@ -1053,7 +1055,7 @@ export class DeviceGroupService { reservationStartDate: data.reservationStartDate, reservationEndDate: new Date(data.reservationEndDate).getTime() < - new Date(device.createdAt).getTime() + new Date(device.createdAt).getTime() ? data.reservationEndDate : device.createdAt, device_createdAt: device.createdAt, @@ -1088,8 +1090,8 @@ export class DeviceGroupService { devices.forEach((ele) => ele.groupId != null ? unavailableDeviceIdsDueToAlreadyIncludedInBuyerReservation.push( - ele.id, - ) + ele.id, + ) : '', ); devices = devices.filter((ele) => ele.groupId === null); @@ -1242,8 +1244,13 @@ export class DeviceGroupService { if (group.api_user_id) { deviceGroup['api_user_id'] = group.api_user_id; } - if (group.reservationExpiryDate) { + const configurationseting = await this.certificate_settingrepository.find(); + let lastCertifiableDate = new Date(group.reservationEndDate); + lastCertifiableDate.setDate(lastCertifiableDate.getDate() + configurationseting[0].no_of_days); + if (group.reservationExpiryDate === null) { deviceGroup['reservationExpiryDate'] = group.reservationExpiryDate; + } else { + deviceGroup['reservationExpiryDate'] = lastCertifiableDate; } const responseDeviceGroupDTO: ResponseDeviceGroupDTO = await this.create( organizationId, @@ -1252,8 +1259,8 @@ export class DeviceGroupService { responseDeviceGroupDTO.unavailableDeviceIDsDueToAreIncludedInBuyerReservation = unavailableDeviceIdsDueToAlreadyIncludedInBuyerReservation.length > 0 ? unavailableDeviceIdsDueToAlreadyIncludedInBuyerReservation.join( - ' , ', - ) + ' , ', + ) : ''; delete responseDeviceGroupDTO['deviceIdsInt']; return responseDeviceGroupDTO; @@ -1941,7 +1948,7 @@ export class DeviceGroupService { ) { if ( recordsCopy[i].externalId.toLowerCase() === - recordsCopy[j].externalId.toLowerCase() && + recordsCopy[j].externalId.toLowerCase() && recordsCopy[j]['statusDuplicate'] === false ) { recordsCopy[j]['statusDuplicate'] = true; @@ -2343,13 +2350,13 @@ export class DeviceGroupService { }); if (group === null) { this.logger.error( - `Group UId is not of this buyer, invalid value was sent`, + `Reservation expired`, ); return new Promise((resolve, reject) => { reject( new ConflictException({ success: false, - message: 'Group UId is not of this buyer, invalid value was sent', + message: 'Reservation expired', }), ); }); @@ -2650,7 +2657,6 @@ export class DeviceGroupService { const totalCount = totalCountQuery.length; this.logger.debug('totalCountQuery', totalCount); const totalPages = Math.ceil(totalCount / pageSize); - let deviceGroups: any; if (role === 'OrganizationAdmin') { deviceGroups = groupedData.reduce((acc, curr) => { @@ -3004,11 +3010,11 @@ export class DeviceGroupService { limit?: number, ): Promise< | { - csvJobs: Array; - currentPage: number; - totalPages: number; - totalCount: number; - } + csvJobs: Array; + currentPage: number; + totalPages: number; + totalCount: number; + } | any > { this.logger.verbose(`With in getAllCSVJobsForApiUser`); @@ -3051,4 +3057,5 @@ export class DeviceGroupService { totalCount, }; } + } diff --git a/apps/drec-api/src/pods/device/device.controller.ts b/apps/drec-api/src/pods/device/device.controller.ts index 5f75767a8..91fae8e08 100755 --- a/apps/drec-api/src/pods/device/device.controller.ts +++ b/apps/drec-api/src/pods/device/device.controller.ts @@ -998,7 +998,7 @@ export class DeviceController { const group: DeviceGroup | null = await this.deviceGroupService.findOne({ devicegroup_uid: groupuId, }); - if (group === null || group.buyerId != user.id) { + if (group === null || group.buyerId != user.id && user.role!= 'ApiUser'|| group.api_user_id != user.api_user_id) { this.logger.error( `Group UId is not of this buyer, invalid value was sent`, ); diff --git a/apps/drec-api/src/pods/device/device.service.ts b/apps/drec-api/src/pods/device/device.service.ts index 6f08b373b..9fd0afcef 100755 --- a/apps/drec-api/src/pods/device/device.service.ts +++ b/apps/drec-api/src/pods/device/device.service.ts @@ -1055,13 +1055,10 @@ export class DeviceService { }); } public async findAllLateCycle( - groupid: number, - externalid: string, ): Promise { + this.logger.verbose(`With in DeviceLateongoingIssueCertificateList`); return await this.latedevciecertificaterepository.find({ where: { - groupId: groupid, - device_externalid: externalid, certificate_issued: false, }, order: { @@ -1473,4 +1470,14 @@ export class DeviceService { { late_end_date: lateend_date, certificate_issued: true }, ); } + async updatelateongoingIfReservationInactive( + externalId: string + ): Promise { + this.logger.verbose(`With in updatelateongoingIfReservationInactive`); + this.logger.verbose(`With in updatelateongoingIfReservationInactive`, externalId); + return await this.latedevciecertificaterepository.update( + {device_externalid: externalId }, + { certificate_issued: true }, + ); + } } diff --git a/apps/drec-api/src/pods/issuer/issuer.service.ts b/apps/drec-api/src/pods/issuer/issuer.service.ts index 7386eeeae..ee69da8ef 100755 --- a/apps/drec-api/src/pods/issuer/issuer.service.ts +++ b/apps/drec-api/src/pods/issuer/issuer.service.ts @@ -55,7 +55,7 @@ export class IssuerService { private baseReadsService: BaseReadsService, private httpService: HttpService, private readonly offChainCertificateService: OffChainCertificateService, - ) {} + ) { } hitTheCronFromIssuerAPIOngoing(): void { this.logger.verbose(`With in hitTheCronFromIssuerAPIOngoing`); @@ -189,9 +189,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; } @@ -224,7 +224,7 @@ export class IssuerService { if ( device.meterReadtype === null && new Date(device.createdAt).getTime() <= - new Date(grouprequest.start_date).getTime() + new Date(grouprequest.start_date).getTime() ) { await this.addlateongoing_devicecertificatecycle( group.id, @@ -375,7 +375,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); @@ -396,7 +396,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); @@ -423,7 +423,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); @@ -542,13 +542,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; } @@ -722,8 +722,8 @@ export class IssuerService { (devicecertificatelogDto.certificate_issuance_startdate = previousReading.length > 0 ? new Date( - new Date(previousReading[0].timestamp).getTime() + 1000, - ) + new Date(previousReading[0].timestamp).getTime() + 1000, + ) : new Date(startDate.toString())), (devicecertificatelogDto.certificate_issuance_enddate = allDevicesCompleteReadsBetweenTimeRange[index][ @@ -809,8 +809,8 @@ export class IssuerService { if ( group.authorityToExceed === false && group.targetVolumeCertificateGenerationRequestedInMegaWattHour + - totalReadValueMegaWattHour >= - group.targetVolumeInMegaWattHour + totalReadValueMegaWattHour >= + group.targetVolumeInMegaWattHour ) { this.groupService.endReservation(group.id, group, grouprequest); } @@ -933,7 +933,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); @@ -1076,19 +1076,17 @@ export class IssuerService { }); } - @Cron('* */2 * * *') + @Cron('0 0 */2 * * *') async handleCronForOngoingLateIssuance(): Promise { this.logger.debug('late ongoing issuance'); this.logger.debug('Called every 2hr to check for issuance of certificates'); - - const devicegroups = await this.groupService.getallReservationactive(); - - await Promise.all( - devicegroups.map(async (grouprequest: DeviceGroup) => { - const group = grouprequest; + const lateongoing = await this.deviceService.findAllLateCycle(); + if (lateongoing) { + for (const element of lateongoing) { + const group = await this.groupService.findOne({ id: element.groupId }); if (!group) { - this.logger.error('late ongoing group is missing'); - return; + this.logger.error('LateOngoing group is missing'); + continue; // Skip to the next element if the group is missing } if ( group.leftoverReadsByCountryCode === null || @@ -1098,170 +1096,132 @@ export class IssuerService { group.leftoverReadsByCountryCode = {}; } if (typeof group.leftoverReadsByCountryCode === 'string') { - group.leftoverReadsByCountryCode = JSON.parse( - group.leftoverReadsByCountryCode, - ); + group.leftoverReadsByCountryCode = JSON.parse(group.leftoverReadsByCountryCode); } - const countryDevicegroup = await this.deviceService.NewfindForGroup( - group.id, - ); - const organization = await this.organizationService.findOne( - group.organizationId, - ); - group.organization = { - name: organization.name, - blockchainAccountAddress: organization.blockchainAccountAddress, - }; - const nextissuance = - await this.groupService.getGroupiCertificateIssueDate({ - groupId: group.id, - }); + if (group.reservationExpiryDate != null && group.reservationExpiryDate.getTime() <= new Date().getTime()) { + this.logger.error('ReservationExpiryDate has passed'); + continue; // Skip to the next element if the reservation expiry date has passed + } + const device = await this.deviceService.findReads(element.device_externalid); + const newGroupwithsingledevice: DeviceGroup = group; + newGroupwithsingledevice.devices = [device]; + const startDate = DateTime.fromISO(element.late_start_date).toUTC(); + const endDate = DateTime.fromISO(element.late_end_date).toUTC(); + const nextissuance = await this.groupService.getGroupiCertificateIssueDate({ groupId: group.id }); + + if (nextissuance) { + nextissuance.start_date = element.late_start_date; + nextissuance.end_date = element.late_end_date; + } + const lastread = await this.readservice.latestread(device.externalId, device.createdAt); + if (lastread.length === 0) { + this.logger.error('No last read found'); + continue; // Skip to the next element if no last read is found + } + if ( + new Date(lastread[0].timestamp).getTime() <= new Date(element.late_end_date).getTime() && + new Date(lastread[0].timestamp).getTime() >= new Date(element.late_start_date).getTime() + ) { + this.logger.verbose('If Lastread less from lateend_date and greater then from latestart_date'); + const endDate1 = new Date(lastread[0].timestamp).toISOString(); + const certifieddevices = await this.deviceService.getCheckCertificateIssueDateLogForDevice( + element.device_externalid, + new Date(startDate.toString()), + new Date(lastread[0].timestamp.toString()) + ); + const newsatrtdate = new Date(lastread[0].timestamp); + newsatrtdate.setTime(newsatrtdate.getTime() + 1); // Add one millisecond + if ( + certifieddevices.length === 0 && + new Date(newsatrtdate).getTime() !== new Date(element.late_start_date).getTime() + ) { + await this.deviceService.updatelateongoing( + device.externalId, + element.id, + new Date(lastread[0].timestamp).toISOString() + ); - for (const key in countryDevicegroup) { - const newGroup: DeviceGroup = JSON.parse(JSON.stringify(group)); - newGroup.devices = countryDevicegroup[key]; + const Islateongoingcycle = await this.deviceService.finddeviceLateCycleOfdaterange( + group.id, + device.externalId, + DateTime.fromISO(new Date(lastread[0].timestamp).toISOString()).toUTC(), + DateTime.fromISO(element.late_end_date).toUTC() + ); - await Promise.all( - newGroup.devices.map(async (element) => { - const lateongoing = await this.deviceService.findAllLateCycle( + if (!Islateongoingcycle) { + await this.addlateongoing_devicecertificatecycle( group.id, - element.externalId, + device.externalId, + new Date(newsatrtdate).toISOString(), + new Date(element.late_end_date).toISOString() ); + } - if (lateongoing) { - const newGroupwithsingledevice: DeviceGroup = JSON.parse( - JSON.stringify(newGroup), - ); - newGroupwithsingledevice.devices = [element]; - - for (const element1 of lateongoing) { - const lastread = await this.readservice.latestread( - element.externalId, - element.createdAt, - ); - const startDate = DateTime.fromISO( - element1.late_start_date, - ).toUTC(); - const endDate = DateTime.fromISO( - element1.late_end_date, - ).toUTC(); - nextissuance.start_date = element1.late_start_date; - nextissuance.end_date = element1.late_end_date; - if ( - new Date(lastread[0].timestamp).getTime() < - new Date(element1.late_end_date).getTime() - ) { - const endDate1 = new Date( - lastread[0].timestamp, - ).toISOString(); - nextissuance.end_date = new Date( - lastread[0].timestamp, - ).toISOString(); - const certifieddevices = - await this.deviceService.getCheckCertificateIssueDateLogForDevice( - element1.device_externalid, - new Date(startDate.toString()), - new Date(lastread[0].timestamp.toString()), - ); - const newsatrtdate = new Date(lastread[0].timestamp); - newsatrtdate.setTime(newsatrtdate.getTime() + 1); // Add one millisecond - if ( - certifieddevices.length === 0 && - new Date(newsatrtdate).getTime() !== - new Date(element1.late_start_date).getTime() - ) { - await this.deviceService.updatelateongoing( - element.externalId, - element1.id, - nextissuance.end_date, - ); - const Islateongoingcycle = - await this.deviceService.finddeviceLateCycleOfdaterange( - group.id, - element.externalId, - DateTime.fromISO(nextissuance.end_date).toUTC(), - DateTime.fromISO(element1.late_end_date).toUTC(), - ); - - if (!Islateongoingcycle) { - await this.addlateongoing_devicecertificatecycle( - group.id, - element.externalId, - new Date(newsatrtdate).toISOString(), - new Date(element1.late_end_date).toISOString(), - ); - } - await this.LateOngoingissueCertificateForGroup( - newGroupwithsingledevice, - nextissuance, - startDate, - DateTime.fromISO(endDate1).toUTC(), - key, - ); - } - - this.logger.error('late ongoing read is missing'); - return; // Break out of the loop when the condition is met - } else { - const certifieddevices = - await this.deviceService.getCheckCertificateIssueDateLogForDevice( - element1.device_externalid, - new Date(startDate.toString()), - new Date(endDate.toString()), - ); - - if (certifieddevices.length === 0) { - const readsFilter: FilterDTO = { - offset: 0, - limit: 5000, - start: startDate.toString(), - end: endDate.toString(), - }; - const allReadsForDeviceBetweenTimeRange: Array<{ - timestamp: Date; - value: number; - }> = - await this.getDeviceFullReadsWithTimestampAndValueAsArray( - newGroupwithsingledevice.devices[0].externalId, - readsFilter, - ); - if (allReadsForDeviceBetweenTimeRange.length > 0) { - await this.deviceService.updatelateongoing( - element.externalId, - element1.id, - element1.late_end_date, - ); - } - await this.LateOngoingissueCertificateForGroup( - newGroupwithsingledevice, - nextissuance, - startDate, - endDate, - key, - ); - } - await new Promise((resolve) => setTimeout(resolve, 5000)); - } - } - } else { - this.logger.error('late ongoing read is missing'); - return; - } - }), + await this.LateOngoingissueCertificateForGroup( + newGroupwithsingledevice, + startDate, + DateTime.fromISO(endDate1).toUTC(), + device.countryCode, + nextissuance + ); + } + } else { + this.logger.verbose("certifieddevices_else", new Date(startDate.toString()), new Date(endDate.toString())); + this.logger.verbose('else Lastread greater then from late_end_date'); + const certifieddevices = await this.deviceService.getCheckCertificateIssueDateLogForDevice( + element.device_externalid, + new Date(startDate.toString()), + new Date(endDate.toString()) + ); + const readsFilter: FilterDTO = { + offset: 0, + limit: 5000, + start: startDate.toString(), + end: endDate.toString() + }; + const allReadsForDeviceBetweenTimeRange = await this.getDeviceFullReadsWithTimestampAndValueAsArray( + newGroupwithsingledevice.devices[0].externalId, + readsFilter ); + if (allReadsForDeviceBetweenTimeRange.length > 0) { + this.logger.verbose('if read are available in date range'); + await this.deviceService.updatelateongoing( + device.externalId, + element.id, + element.late_end_date + ); + + await this.LateOngoingissueCertificateForGroup( + newGroupwithsingledevice, + startDate, + endDate, + device.countryCode, + nextissuance + ); + } + // } } - }), - ); + + // Add delay before moving to the next element + await new Promise((resolve) => setTimeout(resolve, 3000)); + } + } else { + this.logger.error('No late ongoing read found'); + } + + + } private async LateOngoingissueCertificateForGroup( group: DeviceGroup, - grouprequest: DeviceGroupNextIssueCertificate, startDate: DateTime, endDate: DateTime, countryCodeKey: string, + grouprequest?: DeviceGroupNextIssueCertificate, ): Promise { - this.logger.verbose(`With in newissueCertificateForGroup`); + + this.logger.verbose(`With in newissueCertificateForGrouplate`); if (!group?.devices?.length) { this.logger.debug('Line No: 463'); return; @@ -1323,13 +1283,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; } @@ -1464,11 +1424,11 @@ export class IssuerService { group.organizationId, totalReadValueMegaWattHour, ); - if ( + if (group.reservationActive && 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/issuer/synchronize-blockchain-task.service.ts b/apps/drec-api/src/pods/issuer/synchronize-blockchain-task.service.ts index c8237ff3a..75c9cad11 100755 --- a/apps/drec-api/src/pods/issuer/synchronize-blockchain-task.service.ts +++ b/apps/drec-api/src/pods/issuer/synchronize-blockchain-task.service.ts @@ -5,7 +5,7 @@ import { BlockchainSynchronizeService } from '@energyweb/origin-247-certificate' export class SynchronizeBlockchainTaskService { private logger = new Logger(SynchronizeBlockchainTaskService.name); constructor(private synchronizationService: BlockchainSynchronizeService) {} - @Cron(CronExpression.EVERY_MINUTE) + //@Cron(CronExpression.EVERY_MINUTE) public async synchronizeblockchain(): Promise { this.logger.log(`Synchronizing blockchain started`); await this.synchronizationService.synchronize(); diff --git a/apps/drec-api/src/pods/reads/reads.controller.ts b/apps/drec-api/src/pods/reads/reads.controller.ts index 3d3882601..b9c15b9a0 100644 --- a/apps/drec-api/src/pods/reads/reads.controller.ts +++ b/apps/drec-api/src/pods/reads/reads.controller.ts @@ -1566,7 +1566,7 @@ export class ReadsController extends BaseReadsController { this.logger.error(`Read Not found`); throw new HttpException('Read Not found', 400); } - if (user.role === 'Buyer') { + if (user.role === 'Buyer'|| user.role === 'ApiUser') { return { externalId: device.developerExternalId, timestamp: latestReadObject[0].timestamp, diff --git a/version b/version index b054b1a5a..c3fe93e2e 100755 --- a/version +++ b/version @@ -1 +1 @@ -0.0.145 +0.0.146 From 0b405094c07bc4c2f93875256f188c09a219f0c2 Mon Sep 17 00:00:00 2001 From: NamrataSweya Date: Fri, 20 Sep 2024 16:28:53 +0530 Subject: [PATCH 2/6] fixed prettier --- .../1726558881946-certificate_setting.ts | 16 +- .../drec-api/migrations/9999999999999-Seed.ts | 70 ++++---- apps/drec-api/src/drec.module.ts | 2 +- .../certificate-log.service.ts | 35 ++-- .../buyer-reservation.controller.ts | 40 ++--- .../certificate_setting.entity.ts | 32 ++-- .../pods/device-group/device-group.module.ts | 5 +- .../pods/device-group/device-group.service.ts | 72 ++++---- .../src/pods/device/device.controller.ts | 6 +- .../src/pods/device/device.service.ts | 14 +- .../src/pods/issuer/issuer.service.ts | 157 ++++++++++-------- .../src/pods/reads/reads.controller.ts | 2 +- 12 files changed, 239 insertions(+), 212 deletions(-) diff --git a/apps/drec-api/migrations/1726558881946-certificate_setting.ts b/apps/drec-api/migrations/1726558881946-certificate_setting.ts index d381aea93..70e5bec89 100644 --- a/apps/drec-api/migrations/1726558881946-certificate_setting.ts +++ b/apps/drec-api/migrations/1726558881946-certificate_setting.ts @@ -1,19 +1,15 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; +import { MigrationInterface, QueryRunner } from 'typeorm'; export class certificateSetting1726558881946 implements MigrationInterface { - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(` + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` CREATE TABLE certificate_setting ( id SERIAL PRIMARY KEY, "no_of_days" integer NOT NULL DEFAULT 60, "createdAt" timestamp with time zone NOT NULL DEFAULT now(), "updatedAt" timestamp with time zone NOT NULL DEFAULT now() - )` - ); - } - - public async down(queryRunner: QueryRunner): Promise { - } + )`); + } + public async down(queryRunner: QueryRunner): Promise {} } diff --git a/apps/drec-api/migrations/9999999999999-Seed.ts b/apps/drec-api/migrations/9999999999999-Seed.ts index 978e1a3d9..c1523d340 100644 --- a/apps/drec-api/migrations/9999999999999-Seed.ts +++ b/apps/drec-api/migrations/9999999999999-Seed.ts @@ -52,7 +52,7 @@ export class Seed9999999999999 implements MigrationInterface { await this.seedUsersRole(queryRunner); await this.seedAdmin(queryRunner); await this.seedACLModules(queryRunner); - await this.seedCertificateSetting(queryRunner);//set default no_of_days for generate certificate last day + await this.seedCertificateSetting(queryRunner); //set default no_of_days for generate certificate last day await queryRunner.query( `SELECT setval( pg_get_serial_sequence('public.organization', 'id'), @@ -73,7 +73,7 @@ export class Seed9999999999999 implements MigrationInterface { ); } - public async down(queryRunner: QueryRunner): Promise { } + public async down(queryRunner: QueryRunner): Promise {} private async seedBlockchain( queryRunner: QueryRunner, @@ -84,8 +84,10 @@ export class Seed9999999999999 implements MigrationInterface { if (provider && contractsLookup) { await queryRunner.query( - `INSERT INTO public.issuer_blockchain_properties ("netId", "registry", "issuer", "rpcNode", "rpcNodeFallback") VALUES (${provider.network.chainId - }, '${contractsLookup.registry}', '${contractsLookup.issuer + `INSERT INTO public.issuer_blockchain_properties ("netId", "registry", "issuer", "rpcNode", "rpcNodeFallback") VALUES (${ + provider.network.chainId + }, '${contractsLookup.registry}', '${ + contractsLookup.issuer }', '${primaryRpc}', '${fallbackRpc ?? ''}' )`, ); @@ -241,27 +243,27 @@ export class Seed9999999999999 implements MigrationInterface { bitPosition: number; andOperationNumber: number; }> = [ - { - permissionString: PermissionString.Read, - bitPosition: 1, - andOperationNumber: 1, - }, - { - permissionString: PermissionString.Write, - bitPosition: 2, - andOperationNumber: 2, - }, - { - permissionString: PermissionString.Update, - bitPosition: 3, - andOperationNumber: 4, - }, - { - permissionString: PermissionString.Delete, - bitPosition: 4, - andOperationNumber: 8, - }, - ]; + { + permissionString: PermissionString.Read, + bitPosition: 1, + andOperationNumber: 1, + }, + { + permissionString: PermissionString.Write, + bitPosition: 2, + andOperationNumber: 2, + }, + { + permissionString: PermissionString.Update, + bitPosition: 3, + andOperationNumber: 4, + }, + { + permissionString: PermissionString.Delete, + bitPosition: 4, + andOperationNumber: 8, + }, + ]; binaryFormPermission = '0000'; decimalFormPermission = 0; @@ -282,12 +284,12 @@ export class Seed9999999999999 implements MigrationInterface { (ACLModuleJSON as unknown as IACLModuleConfig[]).map( async (aclModule) => { const addedPermissionList: { [key in PermissionString]: boolean } = - { - Read: false, - Write: false, - Delete: false, - Update: false, - }; + { + Read: false, + Write: false, + Delete: false, + Update: false, + }; for (const key in addedPermissionList) { aclModule.permissions.map((myArr, index) => { if (myArr === key) { @@ -344,13 +346,15 @@ export class Seed9999999999999 implements MigrationInterface { decimalFormPermission = decimalFormPermission + Math.pow(2, ele.bitPosition - 1) * - (addedPermissionList[ele.permissionString] === true ? 1 : 0); + (addedPermissionList[ele.permissionString] === true ? 1 : 0); }); this.decimalFormPermission = decimalFormPermission; return this.decimalFormPermission; } private async seedCertificateSetting(queryRunner: QueryRunner) { - const certificate_settingTable = await queryRunner.getTable('public.certificate_setting'); + const certificate_settingTable = await queryRunner.getTable( + 'public.certificate_setting', + ); if (!certificate_settingTable) { this.logger.verbose('certificate_setting table does not exist.'); diff --git a/apps/drec-api/src/drec.module.ts b/apps/drec-api/src/drec.module.ts index 31118084d..159a0524f 100755 --- a/apps/drec-api/src/drec.module.ts +++ b/apps/drec-api/src/drec.module.ts @@ -61,7 +61,7 @@ import { OauthClientCredentials } from './pods/user/oauth_client_credentials.ent import { ApiUserEntity } from './pods/user/api-user.entity'; 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 { CertificateSettingEntity } from './pods/device-group/certificate_setting.entity'; import { HttpModule } from '@nestjs/axios'; const getEnvFilePath = () => { 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 019dc3059..1742706c8 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 @@ -54,7 +54,7 @@ export class CertificateLogService { private deviceService: DeviceService, private devicegroupService: DeviceGroupService, - ) { } + ) {} public async find(): Promise { this.logger.verbose(`With in find`); @@ -625,8 +625,8 @@ export class CertificateLogService { pageNumber: number, ): Promise<{ certificatelog: - | CertificateNewWithPerDeviceLog[] - | CertificateWithPerdevicelog[]; + | CertificateNewWithPerDeviceLog[] + | CertificateWithPerdevicelog[]; currentpage?: number; totalPages: number; totalCount: number; @@ -701,11 +701,11 @@ export class CertificateLogService { async getDeveloperfindreservationcertified( certifiedreservation: | { - deviceGroups: any; - pageNumber: number; - totalPages: number; - totalCount: any; - } + deviceGroups: any; + pageNumber: number; + totalPages: number; + totalCount: any; + } | any, role: Role, ): Promise { @@ -850,11 +850,11 @@ export class CertificateLogService { async getDeveloperCertificatesUsingGroupIDVersionUpdateOrigin247( getreservationinfo: | { - deviceGroups: any; - pageNumber: number; - totalPages: number; - totalCount: any; - } + deviceGroups: any; + pageNumber: number; + totalPages: number; + totalCount: any; + } | any, role: Role, ): Promise { @@ -888,7 +888,6 @@ export class CertificateLogService { certifiedlist: ICertificateReadModel, index: number, ) => { - certificatesInReservationWithLog[index].certificateStartDate = new Date( certifiedlist.generationStartTime * 1000, @@ -1079,10 +1078,10 @@ export class CertificateLogService { res.setHeader( 'Content-Disposition', 'attachment; filename=' + - name + - ' ' + - new Date().toLocaleDateString() + - '.csv', + name + + ' ' + + new Date().toLocaleDateString() + + '.csv', ); res.setHeader('Content-Type', 'text/csv'); const csvString = `${headers.join(',')}\n${data.map((obj) => headers.map((key) => obj[key]).join(',')).join('\n')}`; diff --git a/apps/drec-api/src/pods/device-group/buyer-reservation.controller.ts b/apps/drec-api/src/pods/device-group/buyer-reservation.controller.ts index 30e025fa5..7db7bdf69 100644 --- a/apps/drec-api/src/pods/device-group/buyer-reservation.controller.ts +++ b/apps/drec-api/src/pods/device-group/buyer-reservation.controller.ts @@ -81,7 +81,7 @@ export class BuyerReservationController { private readonly fileService: FileService, private organizationService: OrganizationService, private readonly userService: UserService, - ) { } + ) {} /** * It is GET api to list all device group in reservation data @@ -132,11 +132,11 @@ export class BuyerReservationController { filterDto: UnreservedDeviceGroupsFilterDTO, ): Promise< | { - devicegroups: DeviceGroupDTO[]; - currentPage: number; - totalPages: number; - totalCount: number; - } + devicegroups: DeviceGroupDTO[]; + currentPage: number; + totalPages: number; + totalCount: number; + } | any | DeviceGroupDTO[] > { @@ -227,11 +227,11 @@ export class BuyerReservationController { @Query('pagenumber') pagenumber: number | null, ): Promise< | { - devicegroups: DeviceGroupDTO[]; - currentPage: number; - totalPages: number; - totalCount: number; - } + devicegroups: DeviceGroupDTO[]; + currentPage: number; + totalPages: number; + totalCount: number; + } | any | DeviceGroupDTO[] > { @@ -501,7 +501,7 @@ export class BuyerReservationController { deviceGroupToRegister.reservationStartDate && deviceGroupToRegister.reservationEndDate && deviceGroupToRegister.reservationStartDate.getTime() >= - deviceGroupToRegister.reservationEndDate.getTime() + deviceGroupToRegister.reservationEndDate.getTime() ) { this.logger.error(`start date cannot be less than or same as end date`); throw new ConflictException({ @@ -516,7 +516,7 @@ export class BuyerReservationController { (deviceGroupToRegister.reservationExpiryDate.getTime() <= deviceGroupToRegister.reservationStartDate.getTime() || deviceGroupToRegister.reservationExpiryDate.getTime() < - deviceGroupToRegister.reservationEndDate.getTime()) + deviceGroupToRegister.reservationEndDate.getTime()) ) { this.logger.error( `Expiry date cannot be less than from start and end date`, @@ -532,9 +532,9 @@ export class BuyerReservationController { ); if ( deviceGroupToRegister.reservationStartDate.getTime() <= - maximumBackDateForReservation.getTime() || + maximumBackDateForReservation.getTime() || deviceGroupToRegister.reservationEndDate.getTime() <= - maximumBackDateForReservation.getTime() + maximumBackDateForReservation.getTime() ) { this.logger.error( `start date or end date cannot be less than 3 year from current date`, @@ -816,11 +816,11 @@ export class BuyerReservationController { @Query('limit', new DefaultValuePipe(0), ParseIntPipe) limit: number, ): Promise< | { - csvJobs: Array; - currentPage: number; - totalPages: number; - totalCount: number; - } + csvJobs: Array; + currentPage: number; + totalPages: number; + totalCount: number; + } | any > { this.logger.verbose(`With in getAllCsvJobsBelongingToOrganization`); diff --git a/apps/drec-api/src/pods/device-group/certificate_setting.entity.ts b/apps/drec-api/src/pods/device-group/certificate_setting.entity.ts index 06c9f2194..7ef681394 100644 --- a/apps/drec-api/src/pods/device-group/certificate_setting.entity.ts +++ b/apps/drec-api/src/pods/device-group/certificate_setting.entity.ts @@ -1,18 +1,14 @@ -import { ExtendedBaseEntity } from '@energyweb/origin-backend-utils'; -import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'; - -import { IsNumber } from 'class-validator'; - -@Entity('certificate_setting') -export class CertificateSettingEntity extends ExtendedBaseEntity { - - - @PrimaryGeneratedColumn() - id: number; - - @Column() - @IsNumber() - no_of_days: number; - - -} \ No newline at end of file +import { ExtendedBaseEntity } from '@energyweb/origin-backend-utils'; +import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'; + +import { IsNumber } from 'class-validator'; + +@Entity('certificate_setting') +export class CertificateSettingEntity extends ExtendedBaseEntity { + @PrimaryGeneratedColumn() + id: number; + + @Column() + @IsNumber() + no_of_days: number; +} diff --git a/apps/drec-api/src/pods/device-group/device-group.module.ts b/apps/drec-api/src/pods/device-group/device-group.module.ts index d3026da6f..590d4805c 100644 --- a/apps/drec-api/src/pods/device-group/device-group.module.ts +++ b/apps/drec-api/src/pods/device-group/device-group.module.ts @@ -16,7 +16,7 @@ import { CertificateReadModelEntity } from '@energyweb/origin-247-certificate/di import { CheckCertificateIssueDateLogForDeviceEntity } from '../device/check_certificate_issue_date_log_for_device.entity'; import { Certificate } from '@energyweb/issuer-api'; import { UserModule } from '../user/user.module'; -import {CertificateSettingEntity} from './certificate_setting.entity'; +import { CertificateSettingEntity } from './certificate_setting.entity'; @Module({ imports: [ TypeOrmModule.forFeature([ @@ -29,8 +29,7 @@ import {CertificateSettingEntity} from './certificate_setting.entity'; CertificateReadModelEntity, CheckCertificateIssueDateLogForDeviceEntity, Certificate, - CertificateSettingEntity - + CertificateSettingEntity, ]), forwardRef(() => DeviceModule), diff --git a/apps/drec-api/src/pods/device-group/device-group.service.ts b/apps/drec-api/src/pods/device-group/device-group.service.ts index 4d74a65e7..5324862b7 100755 --- a/apps/drec-api/src/pods/device-group/device-group.service.ts +++ b/apps/drec-api/src/pods/device-group/device-group.service.ts @@ -113,8 +113,8 @@ export class DeviceGroupService { >, private readonly userService: UserService, @InjectRepository(CertificateSettingEntity) - private readonly certificate_settingrepository: Repository - ) { } + private readonly certificate_settingrepository: Repository, + ) {} async getAll( user?: ILoggedInUser, @@ -125,11 +125,11 @@ export class DeviceGroupService { filterDto?: UnreservedDeviceGroupsFilterDTO, ): Promise< | { - devicegroups: DeviceGroupDTO[]; - currentPage: number; - totalPages: number; - totalCount: number; - } + devicegroups: DeviceGroupDTO[]; + currentPage: number; + totalPages: number; + totalCount: number; + } | any > { this.logger.verbose(`With in dg service ${filterDto}`); @@ -776,11 +776,11 @@ export class DeviceGroupService { limit?: number, ): Promise< | { - csvJobs: Array; - currentPage: number; - totalPages: number; - totalCount: number; - } + csvJobs: Array; + currentPage: number; + totalPages: number; + totalCount: number; + } | any > { this.logger.verbose(`With in getAllCSVJobsForOrganization`); @@ -821,11 +821,11 @@ export class DeviceGroupService { limit?: number, ): Promise< | { - csvJobs: Array; - currentPage: number; - totalPages: number; - totalCount: number; - } + csvJobs: Array; + currentPage: number; + totalPages: number; + totalCount: number; + } | any > { this.logger.verbose(`With in getAllCSVJobsForAdmin`); @@ -932,9 +932,9 @@ export class DeviceGroupService { devices.filter((ele) => { if ( new Date(data.reservationStartDate).getTime() < - new Date(ele.createdAt).getTime() && + new Date(ele.createdAt).getTime() && new Date(data.reservationEndDate).getTime() <= - new Date(ele.createdAt).getTime() + new Date(ele.createdAt).getTime() ) { return true; } @@ -1055,7 +1055,7 @@ export class DeviceGroupService { reservationStartDate: data.reservationStartDate, reservationEndDate: new Date(data.reservationEndDate).getTime() < - new Date(device.createdAt).getTime() + new Date(device.createdAt).getTime() ? data.reservationEndDate : device.createdAt, device_createdAt: device.createdAt, @@ -1090,8 +1090,8 @@ export class DeviceGroupService { devices.forEach((ele) => ele.groupId != null ? unavailableDeviceIdsDueToAlreadyIncludedInBuyerReservation.push( - ele.id, - ) + ele.id, + ) : '', ); devices = devices.filter((ele) => ele.groupId === null); @@ -1244,9 +1244,12 @@ export class DeviceGroupService { if (group.api_user_id) { deviceGroup['api_user_id'] = group.api_user_id; } - const configurationseting = await this.certificate_settingrepository.find(); + const configurationseting = + await this.certificate_settingrepository.find(); let lastCertifiableDate = new Date(group.reservationEndDate); - lastCertifiableDate.setDate(lastCertifiableDate.getDate() + configurationseting[0].no_of_days); + lastCertifiableDate.setDate( + lastCertifiableDate.getDate() + configurationseting[0].no_of_days, + ); if (group.reservationExpiryDate === null) { deviceGroup['reservationExpiryDate'] = group.reservationExpiryDate; } else { @@ -1259,8 +1262,8 @@ export class DeviceGroupService { responseDeviceGroupDTO.unavailableDeviceIDsDueToAreIncludedInBuyerReservation = unavailableDeviceIdsDueToAlreadyIncludedInBuyerReservation.length > 0 ? unavailableDeviceIdsDueToAlreadyIncludedInBuyerReservation.join( - ' , ', - ) + ' , ', + ) : ''; delete responseDeviceGroupDTO['deviceIdsInt']; return responseDeviceGroupDTO; @@ -1948,7 +1951,7 @@ export class DeviceGroupService { ) { if ( recordsCopy[i].externalId.toLowerCase() === - recordsCopy[j].externalId.toLowerCase() && + recordsCopy[j].externalId.toLowerCase() && recordsCopy[j]['statusDuplicate'] === false ) { recordsCopy[j]['statusDuplicate'] = true; @@ -2349,9 +2352,7 @@ export class DeviceGroupService { reservationActive: true, }); if (group === null) { - this.logger.error( - `Reservation expired`, - ); + this.logger.error(`Reservation expired`); return new Promise((resolve, reject) => { reject( new ConflictException({ @@ -3010,11 +3011,11 @@ export class DeviceGroupService { limit?: number, ): Promise< | { - csvJobs: Array; - currentPage: number; - totalPages: number; - totalCount: number; - } + csvJobs: Array; + currentPage: number; + totalPages: number; + totalCount: number; + } | any > { this.logger.verbose(`With in getAllCSVJobsForApiUser`); @@ -3057,5 +3058,4 @@ export class DeviceGroupService { totalCount, }; } - } diff --git a/apps/drec-api/src/pods/device/device.controller.ts b/apps/drec-api/src/pods/device/device.controller.ts index 91fae8e08..2f9112b27 100755 --- a/apps/drec-api/src/pods/device/device.controller.ts +++ b/apps/drec-api/src/pods/device/device.controller.ts @@ -998,7 +998,11 @@ export class DeviceController { const group: DeviceGroup | null = await this.deviceGroupService.findOne({ devicegroup_uid: groupuId, }); - if (group === null || group.buyerId != user.id && user.role!= 'ApiUser'|| group.api_user_id != user.api_user_id) { + if ( + group === null || + (group.buyerId != user.id && user.role != 'ApiUser') || + group.api_user_id != user.api_user_id + ) { this.logger.error( `Group UId is not of this buyer, invalid value was sent`, ); diff --git a/apps/drec-api/src/pods/device/device.service.ts b/apps/drec-api/src/pods/device/device.service.ts index 9fd0afcef..cceb393a0 100755 --- a/apps/drec-api/src/pods/device/device.service.ts +++ b/apps/drec-api/src/pods/device/device.service.ts @@ -1054,8 +1054,9 @@ export class DeviceService { ...params, }); } - public async findAllLateCycle( - ): Promise { + public async findAllLateCycle(): Promise< + DeviceLateongoingIssueCertificateEntity[] + > { this.logger.verbose(`With in DeviceLateongoingIssueCertificateList`); return await this.latedevciecertificaterepository.find({ where: { @@ -1471,12 +1472,15 @@ export class DeviceService { ); } async updatelateongoingIfReservationInactive( - externalId: string + externalId: string, ): Promise { this.logger.verbose(`With in updatelateongoingIfReservationInactive`); - this.logger.verbose(`With in updatelateongoingIfReservationInactive`, externalId); + this.logger.verbose( + `With in updatelateongoingIfReservationInactive`, + externalId, + ); return await this.latedevciecertificaterepository.update( - {device_externalid: externalId }, + { device_externalid: externalId }, { certificate_issued: true }, ); } diff --git a/apps/drec-api/src/pods/issuer/issuer.service.ts b/apps/drec-api/src/pods/issuer/issuer.service.ts index ee69da8ef..dc1f67b23 100755 --- a/apps/drec-api/src/pods/issuer/issuer.service.ts +++ b/apps/drec-api/src/pods/issuer/issuer.service.ts @@ -55,7 +55,7 @@ export class IssuerService { private baseReadsService: BaseReadsService, private httpService: HttpService, private readonly offChainCertificateService: OffChainCertificateService, - ) { } + ) {} hitTheCronFromIssuerAPIOngoing(): void { this.logger.verbose(`With in hitTheCronFromIssuerAPIOngoing`); @@ -189,9 +189,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; } @@ -224,7 +224,7 @@ export class IssuerService { if ( device.meterReadtype === null && new Date(device.createdAt).getTime() <= - new Date(grouprequest.start_date).getTime() + new Date(grouprequest.start_date).getTime() ) { await this.addlateongoing_devicecertificatecycle( group.id, @@ -375,7 +375,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); @@ -396,7 +396,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); @@ -423,7 +423,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); @@ -542,13 +542,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; } @@ -722,8 +722,8 @@ export class IssuerService { (devicecertificatelogDto.certificate_issuance_startdate = previousReading.length > 0 ? new Date( - new Date(previousReading[0].timestamp).getTime() + 1000, - ) + new Date(previousReading[0].timestamp).getTime() + 1000, + ) : new Date(startDate.toString())), (devicecertificatelogDto.certificate_issuance_enddate = allDevicesCompleteReadsBetweenTimeRange[index][ @@ -809,8 +809,8 @@ export class IssuerService { if ( group.authorityToExceed === false && group.targetVolumeCertificateGenerationRequestedInMegaWattHour + - totalReadValueMegaWattHour >= - group.targetVolumeInMegaWattHour + totalReadValueMegaWattHour >= + group.targetVolumeInMegaWattHour ) { this.groupService.endReservation(group.id, group, grouprequest); } @@ -933,7 +933,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); @@ -1096,64 +1096,86 @@ export class IssuerService { group.leftoverReadsByCountryCode = {}; } if (typeof group.leftoverReadsByCountryCode === 'string') { - group.leftoverReadsByCountryCode = JSON.parse(group.leftoverReadsByCountryCode); + group.leftoverReadsByCountryCode = JSON.parse( + group.leftoverReadsByCountryCode, + ); } - if (group.reservationExpiryDate != null && group.reservationExpiryDate.getTime() <= new Date().getTime()) { + if ( + group.reservationExpiryDate != null && + group.reservationExpiryDate.getTime() <= new Date().getTime() + ) { this.logger.error('ReservationExpiryDate has passed'); continue; // Skip to the next element if the reservation expiry date has passed } - const device = await this.deviceService.findReads(element.device_externalid); + const device = await this.deviceService.findReads( + element.device_externalid, + ); const newGroupwithsingledevice: DeviceGroup = group; newGroupwithsingledevice.devices = [device]; const startDate = DateTime.fromISO(element.late_start_date).toUTC(); const endDate = DateTime.fromISO(element.late_end_date).toUTC(); - const nextissuance = await this.groupService.getGroupiCertificateIssueDate({ groupId: group.id }); + const nextissuance = + await this.groupService.getGroupiCertificateIssueDate({ + groupId: group.id, + }); if (nextissuance) { nextissuance.start_date = element.late_start_date; nextissuance.end_date = element.late_end_date; } - const lastread = await this.readservice.latestread(device.externalId, device.createdAt); + const lastread = await this.readservice.latestread( + device.externalId, + device.createdAt, + ); if (lastread.length === 0) { this.logger.error('No last read found'); continue; // Skip to the next element if no last read is found } if ( - new Date(lastread[0].timestamp).getTime() <= new Date(element.late_end_date).getTime() && - new Date(lastread[0].timestamp).getTime() >= new Date(element.late_start_date).getTime() + new Date(lastread[0].timestamp).getTime() <= + new Date(element.late_end_date).getTime() && + new Date(lastread[0].timestamp).getTime() >= + new Date(element.late_start_date).getTime() ) { - this.logger.verbose('If Lastread less from lateend_date and greater then from latestart_date'); - const endDate1 = new Date(lastread[0].timestamp).toISOString(); - const certifieddevices = await this.deviceService.getCheckCertificateIssueDateLogForDevice( - element.device_externalid, - new Date(startDate.toString()), - new Date(lastread[0].timestamp.toString()) + this.logger.verbose( + 'If Lastread less from lateend_date and greater then from latestart_date', ); + const endDate1 = new Date(lastread[0].timestamp).toISOString(); + const certifieddevices = + await this.deviceService.getCheckCertificateIssueDateLogForDevice( + element.device_externalid, + new Date(startDate.toString()), + new Date(lastread[0].timestamp.toString()), + ); const newsatrtdate = new Date(lastread[0].timestamp); newsatrtdate.setTime(newsatrtdate.getTime() + 1); // Add one millisecond if ( certifieddevices.length === 0 && - new Date(newsatrtdate).getTime() !== new Date(element.late_start_date).getTime() + new Date(newsatrtdate).getTime() !== + new Date(element.late_start_date).getTime() ) { await this.deviceService.updatelateongoing( device.externalId, element.id, - new Date(lastread[0].timestamp).toISOString() + new Date(lastread[0].timestamp).toISOString(), ); - const Islateongoingcycle = await this.deviceService.finddeviceLateCycleOfdaterange( - group.id, - device.externalId, - DateTime.fromISO(new Date(lastread[0].timestamp).toISOString()).toUTC(), - DateTime.fromISO(element.late_end_date).toUTC() - ); + const Islateongoingcycle = + await this.deviceService.finddeviceLateCycleOfdaterange( + group.id, + device.externalId, + DateTime.fromISO( + new Date(lastread[0].timestamp).toISOString(), + ).toUTC(), + DateTime.fromISO(element.late_end_date).toUTC(), + ); if (!Islateongoingcycle) { await this.addlateongoing_devicecertificatecycle( group.id, device.externalId, new Date(newsatrtdate).toISOString(), - new Date(element.late_end_date).toISOString() + new Date(element.late_end_date).toISOString(), ); } @@ -1162,33 +1184,39 @@ export class IssuerService { startDate, DateTime.fromISO(endDate1).toUTC(), device.countryCode, - nextissuance + nextissuance, ); } } else { - this.logger.verbose("certifieddevices_else", new Date(startDate.toString()), new Date(endDate.toString())); - this.logger.verbose('else Lastread greater then from late_end_date'); - const certifieddevices = await this.deviceService.getCheckCertificateIssueDateLogForDevice( - element.device_externalid, + this.logger.verbose( + 'certifieddevices_else', new Date(startDate.toString()), - new Date(endDate.toString()) + new Date(endDate.toString()), ); + this.logger.verbose('else Lastread greater then from late_end_date'); + const certifieddevices = + await this.deviceService.getCheckCertificateIssueDateLogForDevice( + element.device_externalid, + new Date(startDate.toString()), + new Date(endDate.toString()), + ); const readsFilter: FilterDTO = { offset: 0, limit: 5000, start: startDate.toString(), - end: endDate.toString() + end: endDate.toString(), }; - const allReadsForDeviceBetweenTimeRange = await this.getDeviceFullReadsWithTimestampAndValueAsArray( - newGroupwithsingledevice.devices[0].externalId, - readsFilter - ); + const allReadsForDeviceBetweenTimeRange = + await this.getDeviceFullReadsWithTimestampAndValueAsArray( + newGroupwithsingledevice.devices[0].externalId, + readsFilter, + ); if (allReadsForDeviceBetweenTimeRange.length > 0) { this.logger.verbose('if read are available in date range'); await this.deviceService.updatelateongoing( device.externalId, element.id, - element.late_end_date + element.late_end_date, ); await this.LateOngoingissueCertificateForGroup( @@ -1196,7 +1224,7 @@ export class IssuerService { startDate, endDate, device.countryCode, - nextissuance + nextissuance, ); } // } @@ -1208,9 +1236,6 @@ export class IssuerService { } else { this.logger.error('No late ongoing read found'); } - - - } private async LateOngoingissueCertificateForGroup( @@ -1220,7 +1245,6 @@ export class IssuerService { countryCodeKey: string, grouprequest?: DeviceGroupNextIssueCertificate, ): Promise { - this.logger.verbose(`With in newissueCertificateForGrouplate`); if (!group?.devices?.length) { this.logger.debug('Line No: 463'); @@ -1283,13 +1307,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; } @@ -1424,11 +1448,12 @@ export class IssuerService { group.organizationId, totalReadValueMegaWattHour, ); - if (group.reservationActive && + if ( + group.reservationActive && 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.controller.ts b/apps/drec-api/src/pods/reads/reads.controller.ts index b9c15b9a0..84919ebef 100644 --- a/apps/drec-api/src/pods/reads/reads.controller.ts +++ b/apps/drec-api/src/pods/reads/reads.controller.ts @@ -1566,7 +1566,7 @@ export class ReadsController extends BaseReadsController { this.logger.error(`Read Not found`); throw new HttpException('Read Not found', 400); } - if (user.role === 'Buyer'|| user.role === 'ApiUser') { + if (user.role === 'Buyer' || user.role === 'ApiUser') { return { externalId: device.developerExternalId, timestamp: latestReadObject[0].timestamp, From 910c5d8dd9fb9054408c6ac26584e2723d24d6c1 Mon Sep 17 00:00:00 2001 From: NamrataSweya Date: Fri, 20 Sep 2024 16:54:05 +0530 Subject: [PATCH 3/6] fixed eslint checker --- apps/drec-api/migrations/1726558881946-certificate_setting.ts | 4 +++- apps/drec-api/src/pods/device-group/device-group.service.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/drec-api/migrations/1726558881946-certificate_setting.ts b/apps/drec-api/migrations/1726558881946-certificate_setting.ts index 70e5bec89..b0bcd1b8a 100644 --- a/apps/drec-api/migrations/1726558881946-certificate_setting.ts +++ b/apps/drec-api/migrations/1726558881946-certificate_setting.ts @@ -11,5 +11,7 @@ export class certificateSetting1726558881946 implements MigrationInterface { )`); } - public async down(queryRunner: QueryRunner): Promise {} + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE IF EXISTS certificate_setting`); + } } diff --git a/apps/drec-api/src/pods/device-group/device-group.service.ts b/apps/drec-api/src/pods/device-group/device-group.service.ts index 5324862b7..ead4c5d1c 100755 --- a/apps/drec-api/src/pods/device-group/device-group.service.ts +++ b/apps/drec-api/src/pods/device-group/device-group.service.ts @@ -1246,7 +1246,7 @@ export class DeviceGroupService { } const configurationseting = await this.certificate_settingrepository.find(); - let lastCertifiableDate = new Date(group.reservationEndDate); + const lastCertifiableDate = new Date(group.reservationEndDate); lastCertifiableDate.setDate( lastCertifiableDate.getDate() + configurationseting[0].no_of_days, ); From 745c009d58876747998dd23b1fb88a12ffe65f25 Mon Sep 17 00:00:00 2001 From: NamrataSweya Date: Fri, 20 Sep 2024 17:03:56 +0530 Subject: [PATCH 4/6] fixed eslint warning --- apps/drec-api/src/pods/issuer/issuer.service.ts | 6 ------ .../src/pods/issuer/synchronize-blockchain-task.service.ts | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/apps/drec-api/src/pods/issuer/issuer.service.ts b/apps/drec-api/src/pods/issuer/issuer.service.ts index dc1f67b23..a7ce93b0b 100755 --- a/apps/drec-api/src/pods/issuer/issuer.service.ts +++ b/apps/drec-api/src/pods/issuer/issuer.service.ts @@ -1194,12 +1194,6 @@ export class IssuerService { new Date(endDate.toString()), ); this.logger.verbose('else Lastread greater then from late_end_date'); - const certifieddevices = - await this.deviceService.getCheckCertificateIssueDateLogForDevice( - element.device_externalid, - new Date(startDate.toString()), - new Date(endDate.toString()), - ); const readsFilter: FilterDTO = { offset: 0, limit: 5000, diff --git a/apps/drec-api/src/pods/issuer/synchronize-blockchain-task.service.ts b/apps/drec-api/src/pods/issuer/synchronize-blockchain-task.service.ts index 75c9cad11..c8237ff3a 100755 --- a/apps/drec-api/src/pods/issuer/synchronize-blockchain-task.service.ts +++ b/apps/drec-api/src/pods/issuer/synchronize-blockchain-task.service.ts @@ -5,7 +5,7 @@ import { BlockchainSynchronizeService } from '@energyweb/origin-247-certificate' export class SynchronizeBlockchainTaskService { private logger = new Logger(SynchronizeBlockchainTaskService.name); constructor(private synchronizationService: BlockchainSynchronizeService) {} - //@Cron(CronExpression.EVERY_MINUTE) + @Cron(CronExpression.EVERY_MINUTE) public async synchronizeblockchain(): Promise { this.logger.log(`Synchronizing blockchain started`); await this.synchronizationService.synchronize(); From eff73f490d4966b90b2d4097376c9a17015e608a Mon Sep 17 00:00:00 2001 From: NamrataSweya Date: Tue, 24 Sep 2024 14:12:58 +0530 Subject: [PATCH 5/6] dev test fixed issue --- apps/drec-api/src/pods/device-group/device-group.service.ts | 2 +- version | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/drec-api/src/pods/device-group/device-group.service.ts b/apps/drec-api/src/pods/device-group/device-group.service.ts index ead4c5d1c..26c1626d7 100755 --- a/apps/drec-api/src/pods/device-group/device-group.service.ts +++ b/apps/drec-api/src/pods/device-group/device-group.service.ts @@ -1250,7 +1250,7 @@ export class DeviceGroupService { lastCertifiableDate.setDate( lastCertifiableDate.getDate() + configurationseting[0].no_of_days, ); - if (group.reservationExpiryDate === null) { + if (group.reservationExpiryDate != null) { deviceGroup['reservationExpiryDate'] = group.reservationExpiryDate; } else { deviceGroup['reservationExpiryDate'] = lastCertifiableDate; diff --git a/version b/version index c3fe93e2e..95323f178 100755 --- a/version +++ b/version @@ -1 +1 @@ -0.0.146 +0.0.147 \ No newline at end of file From ba5e9a52bb56f09f0b3e7321b8952b4a1f8f1ee3 Mon Sep 17 00:00:00 2001 From: Daniel Mohns Date: Wed, 25 Sep 2024 14:36:37 +0200 Subject: [PATCH 6/6] Add `.git-glame-ignore-revs` This repository was reformatted using Prettier here: https://github.com/d-rec/drec-origin/pull/155 But the commit was never added to `.git-glame-ignore-revs`. Adding it here --- .git-blame-ignore-revs | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .git-blame-ignore-revs diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 000000000..1f809c8ea --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,2 @@ +# Apply `Prettier` to entire code base +c3d98ff4ececdd9041aea74d5db2be30dc089283