Created
November 30, 2018 15:59
-
-
Save jefBinomed/cd5225a197ad9fcbbf0ea41b978bf6f8 to your computer and use it in GitHub Desktop.
2018-countdown-update-tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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