@@ -5,7 +5,6 @@ const debug = require('debug')('tutorial:csv');
5
5
const _ = require ( 'lodash' ) ;
6
6
const Status = require ( 'http-status-codes' ) ;
7
7
const path = require ( 'path' ) ;
8
- const moment = require ( 'moment-timezone' ) ;
9
8
10
9
/*
11
10
* Delete the temporary file
@@ -40,30 +39,19 @@ function readCsvFile(path) {
40
39
} ) ;
41
40
}
42
41
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 ] ;
51
42
52
- return { id, key } ;
53
- }
54
43
55
44
function createEntitiesFromRows ( rows ) {
56
45
const allEntities = [ ] ;
57
46
const timestamp = new Date ( ) . toISOString ( ) ;
58
47
59
48
rows . forEach ( ( row ) => {
60
- const timestamp = moment . tz ( row . annee , 'Etc/UTC' ) . toISOString ( ) ;
61
49
const entity = {
62
50
id : row . id ,
63
51
type : row . type
64
52
} ;
65
53
66
- Object . keys ( row ) . forEach ( ( key , index ) => {
54
+ Object . keys ( row ) . forEach ( ( key ) => {
67
55
const value = row [ key ] ;
68
56
if ( value !== '' ) {
69
57
switch ( key ) {
@@ -74,7 +62,7 @@ function createEntitiesFromRows(rows) {
74
62
case 'legalId' :
75
63
case 'name' :
76
64
case 'species' :
77
- entity [ key ] = { value : value , type : 'Property' } ;
65
+ entity [ key ] = { value, type : 'Property' } ;
78
66
break ;
79
67
80
68
case 'temperature' :
@@ -154,6 +142,8 @@ function createEntitiesFromRows(rows) {
154
142
break ;
155
143
case 'id' :
156
144
case 'type' :
145
+ case 'lat' :
146
+ case 'lng' :
157
147
break ;
158
148
default :
159
149
debug ( 'unknown : ' + key ) ;
@@ -200,7 +190,7 @@ const upload = (req, res) => {
200
190
. then ( ( entities ) => {
201
191
//console.log(JSON.stringify(entities[0], null, 2))
202
192
203
- batchEntities = [ ] ;
193
+ const batchEntities = [ ] ;
204
194
const chunkSize = 10 ;
205
195
206
196
for ( let i = 0 ; i < entities . length ; i += chunkSize ) {
@@ -213,6 +203,7 @@ const upload = (req, res) => {
213
203
. then ( async ( promises ) => {
214
204
const results = [ ] ;
215
205
for ( const promise of promises ) {
206
+ // eslint-disable-next-line no-await-in-loop
216
207
const result = await promise ;
217
208
results . push ( result ) ;
218
209
}
0 commit comments