From 57f1ef67df32df83a8d6e4f4d8f91aed8229b7c9 Mon Sep 17 00:00:00 2001 From: francodgstn Date: Sun, 20 Oct 2019 02:23:05 +0200 Subject: [PATCH] Removed parameterValid Removed parameterValid check. Documents (even in the same collection) may have different fields. --- src/import.ts | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/src/import.ts b/src/import.ts index c23bc68..2bbccc1 100644 --- a/src/import.ts +++ b/src/import.ts @@ -78,9 +78,7 @@ const updateCollection = async (db, dataArray: Array, dateArray: Array, geoArray: Array) => { - - let parameterValid = true; +const startUpdating = (db, collectionName: string, doc: string, data: object, dateArray: Array, geoArray: Array) => { if(typeof dateArray === 'object' && dateArray.length > 0) { dateArray.map(date => { @@ -89,7 +87,6 @@ const startUpdating = (db, collectionName: string, doc: string, data: object, da data[date] = new Date(data[date]._seconds * 1000); } else { console.log('Please check your date parameters!!!', dateArray); - parameterValid = false; } }); } @@ -101,25 +98,20 @@ const startUpdating = (db, collectionName: string, doc: string, data: object, da data[geo] = new admin.firestore.GeoPoint(data[geo]._latitude, data[geo]._longitude); } else { console.log('Please check your geo parameters!!!', geoArray); - parameterValid = false; } }) } - - if (parameterValid) { - return new Promise(resolve => { - db.collection(collectionName).doc(doc) - .set(data) - .then(() => { - console.log(`${doc} was successfully added to firestore!`); - resolve('Data written!'); - }) - .catch(error => { - console.log(error); - }); - }) - } else { - console.log(`${doc} was not imported to firestore. Please check your parameters!`); - return false; - } + + return new Promise(resolve => { + db.collection(collectionName).doc(doc) + .set(data) + .then(() => { + console.log(`${doc} was successfully added to firestore!`); + resolve('Data written!'); + }) + .catch(error => { + console.log(error); + }); + }) + } \ No newline at end of file