function createUpdate(snap, context, isNew) {
 // isNew just indicates if the function is call for create or update
     var a = context.params.id1;
     var b = context.params.id2;
     var logsToDbPath = 'logs/' + a + "_" + b;
 // onCreate the data from snap is retrieve snap.data(),
     if (isNew) {
         var userID = snap.data().createdBy;
         var logsObject = {
             content: snap.data().content || "No logged content",
             createdAt: snap.data().createdAt.toDate(),
             createdBy: snap.data().createdBy,
             companyId: b,
         };
 // onUpdate the data selected is the one AFTER the update snap.after.data()
 // If needed the previous data exist as snap.before.data()
     } else {
         var userID = snap.after.data().createdBy;
         var logsObject = {
             content: snap.after.data().content || "No logged content",
             createdAt: snap.after.data().createdAt.toDate(),
             createdBy: snap.after.data().createdBy,
             companyId: b,
         };
     }
 // We copy the object to the database
     var dbcreate = db.doc(logsToDbPath).set(logsObject);
 // Here we retrieve the data related to the logs author
     var userPath = `users/` + userID;
     var searchDbforuser = db.doc(userPath)
         .get()
         .then(doc => {
             if (!doc.exists) {
                 console.log('No such document!');
             } else {
                 logsObject.createdByName = doc.data().name;
                 logsObject.createbByImg = doc.data().img;
                 let f = db.doc(logsToDbPath).set(logsObject);
                 return console.log('USer name:', doc.data().name)
             }
         })
         .catch(err => {
             console.log('Error getting document', err);
         });
 // Here we retrieve the data relate to the client whose log is created
     var companyPath = 'clients/' + a;
     var dbsearchCompanyname = db.doc(companyPath)
         .get().then(doc => {
             if (!doc.exists) {
                 console.log('No such company!');
             } else {
                 logsObject.companyname = doc.data().name;
                 let f = db.doc(logsToDbPath).set(logsObject);
                 return console.log('Company name:', doc.data().name)
             }
         })
         .catch(err => {
             console.log('Error getting document', err);
         });
 }
// This functions takes the data on creation or Update an set it on the database
This functions takes the data on creation or Update an set it on the database
This functions takes the data on creation or Update an set it on the database
function createUpdate(snap, context, isNew) {
     var a = context.params.id1;
     var b = context.params.id2;
     var logsToDbPath = 'logs/' + a + "_" + b;
     if (isNew) {
         var userID = snap.data().createdBy;
         var logsObject = {
             content: snap.data().content || "No logged content",
             createdAt: snap.data().createdAt.toDate(),
             createdBy: snap.data().createdBy,
             companyId: b,
         };
     } else {
         var userID = snap.after.data().createdBy;
         var logsObject = {
             content: snap.after.data().content || "No logged content",
             createdAt: snap.after.data().createdAt.toDate(),
             createdBy: snap.after.data().createdBy,
             companyId: b,
         };
     }
     var dbcreate = db.doc(logsToDbPath).set(logsObject);
     var userPath = `users/` + userID;
     var searchDbforuser = db.doc(userPath)
         .get()
         .then(doc => {
             if (!doc.exists) {
                 console.log('No such document!');
             } else {
                 logsObject.createdByName = doc.data().name;
                 logsObject.createbByImg = doc.data().img;
                 let f = db.doc(logsToDbPath).set(logsObject);
                 return console.log('USer name:', doc.data().name)
             }
         })
         .catch(err => {
             console.log('Error getting document', err);
         });
     var companyPath = 'clients/' + a;
     var dbsearchCompanyname = db.doc(companyPath)
         .get().then(doc => {
             if (!doc.exists) {
                 console.log('No such company!');
             } else {
                 logsObject.companyname = doc.data().name;
                 let f = db.doc(logsToDbPath).set(logsObject);
                 return console.log('Company name:', doc.data().name)
             }
         })
         .catch(err => {
             console.log('Error getting document', err);
         });
 }
function createUpdate ( snap , context , isNew ) { var a = context . params . id1 ; var b = context . params . id2 ; var logsToDbPath = 'logs/' + a + "_" + b ; if ( isNew ) { var userID = snap . data ( ) . createdBy ; var logsObject = { content : snap . data ( ) . content || "No logged content" , createdAt : snap . data ( ) . createdAt . toDate ( ) , createdBy : snap . data ( ) . createdBy , companyId : b , } ; } else { var userID = snap . after . data ( ) . createdBy ; var logsObject = { content : snap . after . data ( ) . content || "No logged content" , createdAt : snap . after . data ( ) . createdAt . toDate ( ) , createdBy : snap . after . data ( ) . createdBy , companyId : b , } ; } var dbcreate = db . doc ( logsToDbPath ) . set ( logsObject ) ; var userPath = ` ` + userID ; var searchDbforuser = db . doc ( userPath ) . get ( ) . then ( doc => { if ( ! doc . exists ) { console . log ( 'No such document!' ) ; } else { logsObject . createdByName = doc . data ( ) . name ; logsObject . createbByImg = doc . data ( ) . img ; let f = db . doc ( logsToDbPath ) . set ( logsObject ) ; return console . log ( 'USer name:' , doc . data ( ) . name ) } } ) . catch ( err => { console . log ( 'Error getting document' , err ) ; } ) ; var companyPath = 'clients/' + a ; var dbsearchCompanyname = db . doc ( companyPath ) . get ( ) . then ( doc => { if ( ! doc . exists ) { console . log ( 'No such company!' ) ; } else { logsObject . companyname = doc . data ( ) . name ; let f = db . doc ( logsToDbPath ) . set ( logsObject ) ; return console . log ( 'Company name:' , doc . data ( ) . name ) } } ) . catch ( err => { console . log ( 'Error getting document' , err ) ; } ) ; }
This functions takes the data on creation or Update an set it on the database
This functions takes the data on creation or Update an set it on the database
// isNew just indicates if the function is call for create or update // onCreate the data from snap is retrieve snap.data(), // onUpdate the data selected is the one AFTER the update snap.after.data() // If needed the previous data exist as snap.before.data() // We copy the object to the database // Here we retrieve the data related to the logs author // Here we retrieve the data relate to the client whose log is created