Guest User

Untitled

a guest
Nov 18th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. exports.handler = functions.firestore.document('/Polls/{pollId}/followers/{followerId}').onCreate((data, context) => {
  2.  
  3. const followerId = data.data().follower_id;
  4. const userId = admin.firestore().doc(`Polls/${context.params.pollId}`/{user_id:doc.data().user_id});
  5.  
  6. //iterate through all collections under "Polls"
  7. const parentRef = admin.database().ref("Polls");
  8. return parentRef.once('value').then(snapshot => {
  9. const updates = {};
  10. snapshot.forEach(function(child) {
  11. //if the collection has user_ID field == the user id of the the wildcard pollId, add the follwerId the
  12. if (child.pollid.userId == userId){
  13. //write that user ID to the "followers" subcollection of that node
  14. }
  15. });
  16. return parentRef.update(updates);
  17. });
  18.  
  19. });
Add Comment
Please, Sign In to add comment