Skip to content

Instantly share code, notes, and snippets.

@jefBinomed
Created November 30, 2018 15:59
Show Gist options
  • Save jefBinomed/cd5225a197ad9fcbbf0ea41b978bf6f8 to your computer and use it in GitHub Desktop.
Save jefBinomed/cd5225a197ad9fcbbf0ea41b978bf6f8 to your computer and use it in GitHub Desktop.
2018-countdown-update-tree
function updateTree(userId, drawId, result) {
return new Promise((resolve, reject) => {
admin.database().ref(`/drawUpload/${drawId}`).once('value', (snapshot) => {
try {
// prepare to update the tree
if (snapshot && snapshot.val()) {
let snapshotFb = snapshot.val();
// Update the drawing with the classifications
snapshotFb.tags = extractTags(result);
// Add the drawing in a new part of tree
admin.database().ref(`/draw/${drawId}`).set(snapshotFb)
// When it's done, I remove the drawing from it's old path
.then(() => admin.database().ref(`/drawUpload/${drawId}`).remove())
.then(() => {
resolve();
})
.catch((reason) => {
reject(reason);
});
}
} catch (e) {
reject(e);
}
}, (error) => {
reject(error);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment