manniru
7/7/2017 - 5:55 AM

Move or copy a Firebase path to a new location - Promise

Move or copy a Firebase path to a new location - Promise

function moveFbRecord(oldRef, newRef) {    
     return Promise((resolve, reject) => {
          oldRef.once('value').then(snap => {
               return newRef.set(snap.val());
          }).then(() => {
               return oldRef.set(null);
          }).then(() => {
               console.log('Done!');
               resolve();
          }).catch(err => {
               console.log(err.message);
               reject();
          });
     })
}
function copyFbRecord(oldRef, newRef) {    
     return Promise((resolve, reject) => {
          oldRef.once('value').then(snap => {
               return newRef.set(snap.val());
          }).then(() => {
               console.log('Done!');
               resolve();
          }).catch(err => {
               console.log(err.message);
               reject();
          });
     });
}