@@ -5,7 +5,6 @@ const debug = require('debug')('tutorial:csv');
55const _ = require ( 'lodash' ) ;
66const Status = require ( 'http-status-codes' ) ;
77const path = require ( 'path' ) ;
8- const moment = require ( 'moment-timezone' ) ;
98
109/*
1110 * Delete the temporary file
@@ -40,30 +39,19 @@ function readCsvFile(path) {
4039 } ) ;
4140}
4241
43- /*
44- * Strip the id and an key from the header row.
45- */
46- function parseId ( input ) {
47- const regexId = / ^ [ ^ \s ] + / ;
48- const regexKey = / [ \w ] + $ / ;
49- const id = regexId . exec ( input ) [ 0 ] ;
50- const key = regexKey . exec ( input ) [ 0 ] ;
5142
52- return { id, key } ;
53- }
5443
5544function createEntitiesFromRows ( rows ) {
5645 const allEntities = [ ] ;
5746 const timestamp = new Date ( ) . toISOString ( ) ;
5847
5948 rows . forEach ( ( row ) => {
60- const timestamp = moment . tz ( row . annee , 'Etc/UTC' ) . toISOString ( ) ;
6149 const entity = {
6250 id : row . id ,
6351 type : row . type
6452 } ;
6553
66- Object . keys ( row ) . forEach ( ( key , index ) => {
54+ Object . keys ( row ) . forEach ( ( key ) => {
6755 const value = row [ key ] ;
6856 if ( value !== '' ) {
6957 switch ( key ) {
@@ -74,7 +62,7 @@ function createEntitiesFromRows(rows) {
7462 case 'legalId' :
7563 case 'name' :
7664 case 'species' :
77- entity [ key ] = { value : value , type : 'Property' } ;
65+ entity [ key ] = { value, type : 'Property' } ;
7866 break ;
7967
8068 case 'temperature' :
@@ -154,6 +142,8 @@ function createEntitiesFromRows(rows) {
154142 break ;
155143 case 'id' :
156144 case 'type' :
145+ case 'lat' :
146+ case 'lng' :
157147 break ;
158148 default :
159149 debug ( 'unknown : ' + key ) ;
@@ -200,7 +190,7 @@ const upload = (req, res) => {
200190 . then ( ( entities ) => {
201191 //console.log(JSON.stringify(entities[0], null, 2))
202192
203- batchEntities = [ ] ;
193+ const batchEntities = [ ] ;
204194 const chunkSize = 10 ;
205195
206196 for ( let i = 0 ; i < entities . length ; i += chunkSize ) {
@@ -213,6 +203,7 @@ const upload = (req, res) => {
213203 . then ( async ( promises ) => {
214204 const results = [ ] ;
215205 for ( const promise of promises ) {
206+ // eslint-disable-next-line no-await-in-loop
216207 const result = await promise ;
217208 results . push ( result ) ;
218209 }
0 commit comments