feat: validate the given imported sheet whether is empty

This commit is contained in:
Ahmed Bouhuolia
2024-04-01 02:57:30 +02:00
parent 22a016b56e
commit 785045dbad
7 changed files with 133 additions and 22 deletions

View File

@@ -1,12 +1,11 @@
import { Inject, Service } from 'typedi';
import HasTenancyService from '../Tenancy/TenancyService';
import { sanitizeResourceName } from './_utils';
import { sanitizeResourceName, validateSheetEmpty } from './_utils';
import ResourceService from '../Resource/ResourceService';
import { IModelMetaField } from '@/interfaces';
import { ImportFileCommon } from './ImportFileCommon';
import { ImportFileDataValidator } from './ImportFileDataValidator';
import { ImportFileUploadPOJO } from './interfaces';
import { ServiceError } from '@/exceptions';
@Service()
export class ImportFileUploadService {
@@ -51,6 +50,10 @@ export class ImportFileUploadService {
// Parse the buffer file to array data.
const sheetData = this.importFileCommon.parseXlsxSheet(buffer);
// Throws service error if the sheet data is empty.
validateSheetEmpty(sheetData);
const sheetColumns = this.importFileCommon.parseSheetColumns(sheetData);
const coumnsStringified = JSON.stringify(sheetColumns);