Skip to content

Commit

Permalink
feat: Renamed duplicate headers (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
chavda-bhavik authored Jul 20, 2023
2 parents 6ac7b15 + 08eaed2 commit d396d7a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion apps/api/src/app/shared/services/file/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,19 @@ export class CSVFileService extends FileService {
};
const fileContent = file.buffer.toString(FileEncodingsEnum.CSV);

parseString(fileContent, options)
parseString(fileContent, {
...options,
headers: (headers) => {
// rename duplicate
headers.map((el, i, ar) => {
if (ar.indexOf(el) !== i) {
headers[i] = `${el}_${i}`;
}
});

return headers;
},
})
.on('error', (error) => {
if (error.message.includes('Parse Error')) {
reject(new InvalidFileException());
Expand Down

0 comments on commit d396d7a

Please sign in to comment.