@@ -2,14 +2,16 @@ const fs = require('fs');
22const moment = require ( 'moment' ) ;
33const logger = require ( '../helpers/logger' ) ;
44const { validateCSV } = require ( '../helpers/csvValidator' ) ;
5- const { csvParse, stringNormalizer, normalizeEmptyValues } = require ( '../helpers/csvParsingUtils' ) ;
5+ const { csvParse, stringNormalizer, normalizeEmptyValues, getCSVHeader } = require ( '../helpers/csvParsingUtils' ) ;
66
77class CSVFileModule {
88 constructor ( csvFilePath , unalterableColumns , parserOptions ) {
99 // Parse then normalize the data
10- const parsedData = csvParse ( fs . readFileSync ( csvFilePath ) , parserOptions ) ;
10+ const csvData = fs . readFileSync ( csvFilePath ) ;
11+ const parsedData = csvParse ( csvData , parserOptions ) ;
1112 this . filePath = csvFilePath ;
1213 this . data = normalizeEmptyValues ( parsedData , unalterableColumns ) ;
14+ this . header = getCSVHeader ( csvData ) ;
1315 }
1416
1517 async get ( key , value , fromDate , toDate ) {
@@ -32,7 +34,7 @@ class CSVFileModule {
3234 async validate ( csvSchema ) {
3335 if ( csvSchema ) {
3436 logger . info ( `Validating CSV file for ${ this . filePath } ` ) ;
35- return validateCSV ( this . filePath , csvSchema , this . data ) ;
37+ return validateCSV ( this . filePath , csvSchema , this . data , this . header ) ;
3638 }
3739 logger . warn ( `No CSV schema provided for ${ this . filePath } ` ) ;
3840 return true ;
0 commit comments