From 73c23f1c2f7790250224fca07ca4a5c33b272120 Mon Sep 17 00:00:00 2001 From: RFlintstone Date: Wed, 24 May 2023 15:33:42 +0200 Subject: [PATCH] Updated insertData model - Creating and updating model now works better --- src/models/firebase/insert/insertData.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/models/firebase/insert/insertData.js b/src/models/firebase/insert/insertData.js index 18024af..75e1a33 100644 --- a/src/models/firebase/insert/insertData.js +++ b/src/models/firebase/insert/insertData.js @@ -8,18 +8,9 @@ async function timestamp() { } async function insertData(collection, newID, body) { - let json = { - first_name: body.first_name, - last_name: body.last_name, - age: body.age, - email: body.email, - iban: body.iban, - pin: body.pin, - balance: body.balance, - time: await timestamp() - } - - console.log(json) + // Set timestamp and log body + body.time = await timestamp(); + console.log(body); // Make sure we have the right reference const db = await require('../init/setupFirebase').getDB(); @@ -29,7 +20,7 @@ async function insertData(collection, newID, body) { // Insert the data in the newly created document let state; - await Ref.set(json) + await Ref.set(body, {merge: true}) .then(() => { // Log our document id console.log('Added/updated document with id', newID);