diff --git a/package-lock.json b/package-lock.json index b00b7d4b..21c52230 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cht-user-management", - "version": "1.0.1", + "version": "1.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cht-user-management", - "version": "1.0.1", + "version": "1.0.2", "license": "ISC", "dependencies": { "@fastify/autoload": "^5.8.0", diff --git a/package.json b/package.json index 438aece7..4c43d72f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cht-user-management", - "version": "1.0.1", + "version": "1.0.2", "main": "dist/index.js", "dependencies": { "@fastify/autoload": "^5.8.0", diff --git a/src/services/place-factory.ts b/src/services/place-factory.ts index 1e2d21ab..739b8dfe 100644 --- a/src/services/place-factory.ts +++ b/src/services/place-factory.ts @@ -51,10 +51,10 @@ export default class PlaceFactory { private static async loadPlacesFromCsv(csvBuffer: Buffer, contactType: ContactType) : Promise { 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) { @@ -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; } } \ No newline at end of file