Skip to content

Commit

Permalink
update report service search function
Browse files Browse the repository at this point in the history
  • Loading branch information
mgtennant committed Mar 11, 2024
1 parent bc847ee commit 24f5f57
Showing 1 changed file with 44 additions and 50 deletions.
94 changes: 44 additions & 50 deletions frontend/src/report/report.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ export class ReportService {
}

async getGroupMaxByVariant(variantName: string): Promise<any> {
console.log(variantName);
const url = `${hostname}:${port}/nfr-provision/get-group-max/variant/${variantName}`;
return await axios.get(url).then((res) => {
return res.data;
Expand Down Expand Up @@ -732,59 +733,52 @@ export class ReportService {
async getNFRData() {
const nfrDataUrl = `${hostname}:${port}/nfr-data`;
const templateUrl = `${hostname}:${port}/document-template/nfr-template-info`;
const nfrData = await axios
.get(nfrDataUrl)
.then((res) => {
return res.data;
})
.catch((err) => console.log(err.response.data));
const templateIds = [];
for (let entry of nfrData) {
templateIds.push(entry.template_id);

// get NFR data
let nfrData;
try {
const response = await axios.get(nfrDataUrl);
nfrData = response.data;
} catch (err) {
console.log(err.response.data);
return;
}
const allTemplates: {
id: number;
file_name: string;
active_flag: boolean;
is_deleted: boolean;
template_version: number;
}[] = await axios
.post(templateUrl, templateIds)
.then((res) => {
return res.data;
})
.catch((err) => console.log(err.response.data));

// Combine the corresponding templates with the nfr data.
const combinedArray = [];

let i = 0;
let j = 0;

while (i < allTemplates.length && j < nfrData.length) {
const template = allTemplates[i];
const nfr = nfrData[j];

if (template.id === nfr.template_id) {
if (!template.is_deleted) {
combinedArray.push({
dtid: nfr.dtid,
version: template.template_version,
file_name: template.file_name,
updated_date: nfr.update_timestamp.split('T')[0],
status: nfr.status,
active: template.active_flag,
nfr_id: nfr.id,
variant_name: nfr.variant_name,
});
}
j++;
} else if (template.id < nfr.template_id) {
i++;
} else {
j++;
}
// get template IDs from NFR data
const templateIds = nfrData.map((entry) => entry.template_id);

// get templates using template IDs
let allTemplates;
try {
const response = await axios.post(templateUrl, templateIds);
allTemplates = response.data;
} catch (err) {
console.log(err.response.data);
return;
}

// filter out deleted templates and create a lookup table
const templatesLookup = allTemplates.reduce((acc, template) => {
if (!template.is_deleted) {
acc[template.id] = template;
}
return acc;
}, {});

// combine NFR data with their corresponding templates
const combinedArray = nfrData
.filter((nfr) => templatesLookup[nfr.template_id])
.map((nfr) => ({
dtid: nfr.dtid,
version: templatesLookup[nfr.template_id].template_version,
file_name: templatesLookup[nfr.template_id].file_name,
updated_date: nfr.update_timestamp.split('T')[0],
status: nfr.status,
active: templatesLookup[nfr.template_id].active_flag,
nfr_id: nfr.id,
variant_name: nfr.variant_name,
}));

return combinedArray;
}

Expand Down

0 comments on commit 24f5f57

Please sign in to comment.