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

MAT-7238: refactor how stratification worksheets are created and adde… #14

Merged
merged 1 commit into from
May 24, 2024
Merged
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
44 changes: 33 additions & 11 deletions src/services/export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
TestCaseExcelExportDto,
PopulationDto,
StratificationDto,
GroupedStratificationDto,
} from '@madie/madie-models';

@Injectable()
Expand All @@ -42,22 +41,36 @@ export class ExportService {
index += 1;
});

// collect all the distinct stratifications by stratification name
const stratNames = new Set<string>();
const stratNamesToGroup = {};
testCaseExcelExportDtos.forEach((testCaseExcelExportDto) => {
testCaseExcelExportDto.testCaseExecutionResults.forEach((result) => {
result.stratifications?.forEach((stratification) => {
const stratificationWorksheet = workbook.addWorksheet(
`${index} - ${stratification.stratName}`,
);
this.generateStratificationWorksheet(
stratificationWorksheet,
testCaseExcelExportDto,
stratification,
);
index += 1;
stratNames.add(stratification.stratName);
stratNamesToGroup[stratification.stratName] =
testCaseExcelExportDto.groupId;
});
});
});

// create a worksheet for each stratification
for (const stratName of stratNames) {
const groupId = stratNamesToGroup[stratName];
const stratificationWorksheet = workbook.addWorksheet(
`${index} - ${stratName}`,
);
const testCaseExcelExportDto = testCaseExcelExportDtos.find(
(dto) => dto.groupId === groupId,
);
this.generateStratificationWorksheet(
stratificationWorksheet,
stratName,
testCaseExcelExportDto,
);
index++;
}

// Return final workbook
return workbook.xlsx.writeBuffer() as Promise<Buffer>;
}
Expand Down Expand Up @@ -350,8 +363,8 @@ export class ExportService {

public generateStratificationWorksheet(
worksheet: ExcelJS.Worksheet,
stratName: string,
testCaseGroupDto: TestCaseExcelExportDto,
groupedStratificationDto: GroupedStratificationDto,
) {
let firstRow = [];
let headerRow = [];
Expand All @@ -366,6 +379,15 @@ export class ExportService {
const firstRowData = [];
const headerRowData = [];
const testCaseData = [];
const groupedStratificationDto = result.stratifications?.find(
(s) => s.stratName === stratName,
);
if (
undefined === groupedStratificationDto ||
null === groupedStratificationDto
) {
return;
}

const numValues: number =
groupedStratificationDto.stratificationDtos?.length;
Expand Down
Loading