Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. 'use-strict';
  2.  
  3. const functions = require('firebase-functions');
  4. const admin = require('firebase-admin');
  5. admin.initializeApp(functions.config().firebase);
  6.  
  7. exports.sendNotification = functions.database.ref('/{teacherId}/{classId}/{notificationId}').onWrite((change, context)=>{
  8. const teacherId = context.params.teacherId;
  9. const classId = context.params.classId;
  10.  
  11. return admin.firestore().collection("Users").doc(teacherId).collection("Subjects").doc(classId).get().then(doc=>{
  12. const className = doc.data().Name;
  13.  
  14. }).then(result=>{
  15.  
  16. return admin.firestore().collection("Users").where(classId,"==","Added").get().then(queryResult=>{
  17. queryResult.forEach(documentSanpshot =>{
  18. const tokenId = documentSanpshot.data().token;
  19. const payload ={
  20. notification: {
  21. title : "New Announcement",
  22. body : "Subject: "+className,
  23. icon: "default"
  24. }
  25. };
  26. return admin.messaging().sendToDevice(tokenId,payload);
  27. });
  28. });
  29. });
  30. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement