Skip to content

Commit

Permalink
fix parse crash
Browse files Browse the repository at this point in the history
  • Loading branch information
freddieptf committed Jan 17, 2024
1 parent 2037167 commit 7565b5a
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/services/place-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ export default class PlaceFactory {
private static async loadPlacesFromCsv(csvBuffer: Buffer, contactType: ContactType) : Promise<Place[]> {
const csvColumns: string[] = [];
const places: Place[] = [];

const parser = parse(csvBuffer, { delimiter: ",", from_line: 1 });
parser.on('data', function (row: string[]) {
if (csvColumns.length === 0) {
const parser = parse(csvBuffer, { delimiter: ",", trim: true, skip_empty_lines: true });
let count = 0;
for await (const row of parser) {
if (count === 0) {
const missingColumns = Config.getRequiredColumns(contactType, true).map(p => p.friendly_name)
.filter((csvName) => !row.includes(csvName));
if (missingColumns.length > 0) {
Expand All @@ -75,13 +75,10 @@ export default class PlaceFactory {
const columnIndex = csvColumns.indexOf(hierarchyConstraint.friendly_name);
place.hierarchyProperties[hierarchyConstraint.property_name] = row[columnIndex];
}

places.push(place);
}
});

// wait till dones
await once(parser, "finish");
count++
}
return places;
}
}

0 comments on commit 7565b5a

Please sign in to comment.