Skip to content

Commit

Permalink
feat: Omited data excel sheets while parsing template file
Browse files Browse the repository at this point in the history
  • Loading branch information
chavda-bhavik committed Feb 26, 2024
1 parent f356e8f commit 45c9fb0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable } from '@nestjs/common';
import { FileMimeTypesEnum } from '@impler/shared';

import { CONSTANTS } from '@shared/constants';
import { ExcelFileService } from '@shared/services/file';
import { GetSheetNamesCommand } from './get-sheet-names.command';
import { FileParseException } from '@shared/exceptions/file-parse-issue.exception';
Expand All @@ -11,8 +12,9 @@ export class GetSheetNames {
if (file.mimetype === FileMimeTypesEnum.EXCEL || file.mimetype === FileMimeTypesEnum.EXCELX) {
try {
const fileService = new ExcelFileService();
const sheetNames = await fileService.getExcelSheets(file);

return await fileService.getExcelSheets(file);
return sheetNames.filter((sheetName) => !sheetName.startsWith(CONSTANTS.EXCEL_DATA_SHEET_STARTER));
} catch (error) {
throw new FileParseException();
}
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/app/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const APIMessages = {

export const CONSTANTS = {
PASSWORD_SALT: 10,
EXCEL_DATA_SHEET_STARTER: 'imp_',
AUTH_COOKIE_NAME: 'authentication',
// eslint-disable-next-line no-magic-numbers
maxAge: 1000 * 60 * 60 * 24 * 1, // 1 day
Expand Down
5 changes: 3 additions & 2 deletions apps/api/src/app/shared/services/file/file.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as XLSX from 'xlsx';
import * as ExcelJS from 'exceljs';
import { ParseConfig, parse } from 'papaparse';
import { CONSTANTS } from '@shared/constants';
import { ColumnTypesEnum, Defaults, FileEncodingsEnum } from '@impler/shared';
import { EmptyFileException } from '@shared/exceptions/empty-file.exception';
import { InvalidFileException } from '@shared/exceptions/invalid-file.exception';
Expand All @@ -25,12 +26,12 @@ export class ExcelFileService {
});
}
formatName(name: string): string {
return name.replace(/[^a-zA-Z0-9]/g, '');
return CONSTANTS.EXCEL_DATA_SHEET_STARTER + name.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
}
addSelectSheet(wb: ExcelJS.Workbook, heading: IExcelFileHeading): string {
const name = this.formatName(heading.key);
const companies = wb.addWorksheet(name);
const companyHeadings = [name];
const companyHeadings = [heading.key];
companies.addRow(companyHeadings);
heading.selectValues.forEach((value) => companies.addRow([value]));

Expand Down

0 comments on commit 45c9fb0

Please sign in to comment.