Skip to content

Commit

Permalink
Merge pull request #394 from d-rec/DR-861
Browse files Browse the repository at this point in the history
fixed certificatelog in certifcate manu in apiuser login
  • Loading branch information
NamrataSweya authored Aug 29, 2024
2 parents bdd9591 + 9348789 commit 3adaf1d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -656,19 +656,20 @@ export class CertificateLogService {
'getoldreservationinfo',
getoldreservationinfo.deviceGroups.length,
);
if (getoldreservationinfo.deviceGroups.length > 0) {
return this.getDeveloperfindreservationcertified(
getoldreservationinfo,
user.role,
);
}
if (getnewreservationinfo.deviceGroups.length > 0) {
this.logger.debug('Line No: 580');
return this.getDeveloperCertificatesUsingGroupIDVersionUpdateOrigin247(
getnewreservationinfo,
user.role,
);
}
if (getoldreservationinfo.deviceGroups.length > 0) {
return this.getDeveloperfindreservationcertified(
getoldreservationinfo,
user.role,
);
}

return {
certificatelog: [],
currentpage: 0,
Expand All @@ -695,7 +696,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 +788,7 @@ export class CertificateLogService {
}
}
}
if (role === 'Buyer') {
if (role === 'Buyer' || role === Role.ApiUser) {
devicelog =
await this.getCheckCertificateIssueDateLogForDevice(
parseInt(group.dg_id),
Expand Down
79 changes: 52 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 :certificateStartDate1 AND :certificateEndDate1',
{
certificateStartDate1: startTimestamp,
certificateEndDate1: 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 @@ -2920,27 +2924,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.144

0 comments on commit 3adaf1d

Please sign in to comment.