Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DR-861 :fixed internal server issue fixed due to oldercertificate log #396

Merged
merged 6 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ describe('CertificateLogService', () => {
end_date: '2024-02-14 12:51:000Z',
country: 'India',
SDGBenefits: undefined,
oldcertificatelog: false,
};
const pageNumber = 1;

Expand Down Expand Up @@ -559,6 +560,7 @@ describe('CertificateLogService', () => {
end_date: '2024-02-14 12:51:000Z',
country: 'India',
SDGBenefits: undefined,
oldcertificatelog: false,
};
const pageNumber = 1;

Expand Down
43 changes: 32 additions & 11 deletions apps/drec-api/src/pods/certificate-log/certificate-log.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ export class CertificateLogService {
currentpage?: number;
totalPages: number;
totalCount: number;
oldcertificatelog: boolean;
}> {
this.logger.verbose(`With in getCertifiedlogofDevices`);
const getnewreservationinfo =
Expand All @@ -656,26 +657,46 @@ export class CertificateLogService {
'getoldreservationinfo',
getoldreservationinfo.deviceGroups.length,
);
if (getoldreservationinfo.deviceGroups.length > 0) {
return this.getDeveloperfindreservationcertified(
getoldreservationinfo,
user.role,
);
}
if (getnewreservationinfo.deviceGroups.length > 0) {
const oldcertificatelog = this.isTrue(filterDto.oldcertificatelog);
if (!oldcertificatelog && getnewreservationinfo.deviceGroups.length > 0) {
this.logger.debug('Line No: 580');
return this.getDeveloperCertificatesUsingGroupIDVersionUpdateOrigin247(
getnewreservationinfo,
const newlog =
await this.getDeveloperCertificatesUsingGroupIDVersionUpdateOrigin247(
getnewreservationinfo,
user.role,
);

return {
...newlog,
oldcertificatelog:
getoldreservationinfo.deviceGroups.length > 0 ? true : false,
};
}

if (oldcertificatelog && getoldreservationinfo.deviceGroups.length > 0) {
this.logger.debug('Line No: 581');
const oldlog = await this.getDeveloperfindreservationcertified(
getoldreservationinfo,
user.role,
);
return {
...oldlog,
oldcertificatelog:
getoldreservationinfo.deviceGroups.length > 0 ? true : false,
};
}

return {
certificatelog: [],
currentpage: 0,
totalPages: 0,
totalCount: 0,
oldcertificatelog: false,
};
}
isTrue(value: string | boolean): boolean {
return value === 'true' || value === true;
}

async getDeveloperfindreservationcertified(
certifiedreservation:
Expand All @@ -695,7 +716,7 @@ export class CertificateLogService {
const newq = await this.certificaterrepository
.createQueryBuilder('issuar')
.where(
`issuar.id IN (${JSON.stringify(group.internalCertificateId).replace(/[[]]/g, '')})`,
`issuar.id IN (${JSON.stringify(group.internalCertificateId).replace(/[[\]]/g, '')})`,
);

const groupedDatasql = await newq.getQuery();
Expand Down Expand Up @@ -787,7 +808,7 @@ export class CertificateLogService {
}
}
}
if (role === 'Buyer') {
if (role === 'Buyer' || role === Role.ApiUser) {
devicelog =
await this.getCheckCertificateIssueDateLogForDevice(
parseInt(group.dg_id),
Expand Down
7 changes: 7 additions & 0 deletions apps/drec-api/src/pods/certificate-log/dto/filter.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class FilterDTO {
@IsOptional()
@ApiPropertyOptional({ description: 'Certificate End date filter' })
end_date: string;

@IsOptional()
@ApiPropertyOptional({ type: String, description: 'Country' })
country: string;
Expand All @@ -65,6 +66,12 @@ export class FilterDTO {
isArray: true,
})
SDGBenefits?: string[] | undefined;
@IsOptional()
@ApiPropertyOptional({
type: Boolean,
description: 'old certificate',
})
oldcertificatelog?: boolean;
}

export class GroupIDBasedFilteringDTO {
Expand Down
86 changes: 59 additions & 27 deletions apps/drec-api/src/pods/device-group/device-group.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2585,6 +2585,13 @@ export class DeviceGroupService {
certificateEndDate1: endTimestamp,
},
);
qb.orWhere(
'crm.generationEndTime BETWEEN :certificateStartDate2 AND :certificateEndDate2',
{
certificateStartDate2: startTimestamp,
certificateEndDate2: endTimestamp,
},
);
}
if (filterDto.SDGBenefits) {
const newsdg = filterDto.SDGBenefits.toString();
Expand Down Expand Up @@ -2636,11 +2643,6 @@ export class DeviceGroupService {
);
});
const totalCountQuery = await queryBuilder.getRawMany();
const groupedDatasql = await queryBuilder
.offset(skip)
.limit(pageSize)
.getSql();
this.logger.debug(groupedDatasql);
const groupedData = await queryBuilder
.offset(skip)
.limit(pageSize)
Expand All @@ -2655,8 +2657,10 @@ export class DeviceGroupService {
const existing = acc.find((item) => item.dg_id === curr.devicegroupid);

if (existing) {
const existing1 = acc.find((item) => item.id === curr.id);
if (existing1) {
const existingDevice = existing.developerdeviceIds.find(
(item) => item === curr.id,
);
if (!existingDevice) {
existing.developerdeviceIds.push(curr.id);
}
existing.internalCertificateId.push(curr.internalCertificateId);
Expand Down Expand Up @@ -2729,7 +2733,7 @@ export class DeviceGroupService {
'CAST(issuer.deviceId AS INTEGER) = dg.id',
)
.select(
'DISTINCT ON (dg.id, issuer.id) dg.id AS deviceGroupId, dg.name, dg.deviceIdsInt, d.*, dg_log.readvalue_watthour, issuer.id',
'DISTINCT ON (dg.id, issuer.id) dg.id AS deviceGroupId, dg.name, dg.deviceIdsInt, d.*, dg_log.readvalue_watthour, issuer.id As issuerId',
)
.orderBy('dg.id, issuer.id, dg_log.readvalue_watthour', 'ASC');

Expand Down Expand Up @@ -2856,6 +2860,13 @@ export class DeviceGroupService {
certificateEndDate1: endTimestamp,
},
);
qb.orWhere(
'issuer.generationEndTime BETWEEN :certificateStartDate2 AND :certificateEndDate2',
{
certificateStartDate2: startTimestamp,
certificateEndDate2: endTimestamp,
},
);
}
if (filterDto.SDGBenefits) {
const newsdg = filterDto.SDGBenefits.toString();
Expand Down Expand Up @@ -2920,27 +2931,48 @@ export class DeviceGroupService {
this.logger.debug('totalCountQuery', totalCount);
const totalPages = Math.ceil(totalCount / pageSize);

const deviceGroups = groupedData.reduce((acc, curr) => {
const existing = acc.find((item) => item.dg_id === curr.dg_id);
if (existing) {
const existing1 = acc.find((item) => item.id === curr.id);
if (existing1) {
existing.developerdeviceIds.push(curr.id);
}
existing.internalCertificateId.push(curr.id);
} else {
acc.push({
dg_id: curr.devicegroupid,
name: curr.name,
deviceIdsInt: curr.deviceIdsInt,
let deviceGroups: any;
if (role === 'OrganizationAdmin') {
deviceGroups = groupedData.reduce((acc, curr) => {
const existing = acc.find((item) => item.dg_id === curr.devicegroupid);

developerdeviceIds: [curr.id],
internalCertificateId: [curr.id],
});
}
return acc;
}, []);
if (existing) {
const existingDevice = existing.developerdeviceIds.find(
(item) => item === curr.id,
);
if (!existingDevice) {
existing.developerdeviceIds.push(curr.id);
}
existing.internalCertificateId.push(curr.issuerid);
} else {
acc.push({
dg_id: curr.devicegroupid,
name: curr.name,
deviceIdsInt: curr.deviceIdsInt,
developerdeviceIds: [curr.id],
internalCertificateId: [curr.issuerid],
});
}
return acc;
}, []);
}
if (role === 'Buyer' || role === Role.ApiUser) {
deviceGroups = groupedData.reduce((acc, curr) => {
const existing = acc.find((item) => item.dg_id === curr.devicegroupid);

if (existing) {
existing.internalCertificateId.push(curr.issuerid);
} else {
acc.push({
dg_id: curr.devicegroupid,
name: curr.name,
deviceIdsInt: curr.deviceIdsInt,
internalCertificateId: [curr.issuerid],
});
}
return acc;
}, []);
}
const response = {
deviceGroups,
pageNumber,
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.143
0.0.145
Loading