Skip to content

Commit

Permalink
refactor: extract excel workbook creation in buildExcelWorkbook
Browse files Browse the repository at this point in the history
  • Loading branch information
xurxodev committed Dec 16, 2023
1 parent b011c16 commit fe542de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/data/repositories/ProductExportSpreadsheetRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export class ProductExportSpreadsheetRepository implements ProductExportReposito
],
};

const wb = this.buildExcelWorkbook(workbook);

this.saveWorkbook(wb, workbook.name);
}

private buildExcelWorkbook(workbook: Workbook) {
const wb = new ExcelJS.Workbook();

workbook.sheets.forEach(sheet => {
Expand All @@ -51,7 +57,7 @@ export class ProductExportSpreadsheetRepository implements ProductExportReposito
sh.addRows(sheet.rows);
});

this.saveWorkBook(wb, name);
return wb;
}

private splitProducts(products: Product[]) {
Expand Down Expand Up @@ -99,7 +105,7 @@ export class ProductExportSpreadsheetRepository implements ProductExportReposito
};
}

protected async saveWorkBook(wb: ExcelJS.Workbook, name: string): Promise<void> {
protected async saveWorkbook(wb: ExcelJS.Workbook, name: string): Promise<void> {
wb.xlsx.writeFile(name);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ProductExportSpreadsheetRepositoryTest extends ProductExportSpreads
wb: ExcelJS.Workbook = new ExcelJS.Workbook();
workBookName = "";

protected async saveWorkBook(wb: ExcelJS.Workbook, workBookName: string): Promise<void> {
protected async saveWorkbook(wb: ExcelJS.Workbook, workBookName: string): Promise<void> {
this.wb = wb;
this.workBookName = workBookName;
}
Expand Down

0 comments on commit fe542de

Please sign in to comment.