Advertisement
Guest User

Untitled

a guest
Jul 12th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component } from '@angular/core';
  2. import {AngularFirestore} from 'angularfire2/firestore';
  3. import {AngularFireAuth} from 'angularfire2/auth';
  4. /**
  5.  * Generated class for the ColaboradoresComponent component.
  6.  *
  7.  * See https://angular.io/api/core/Component for more info on Angular
  8.  * Components.
  9.  */
  10. @Component({
  11.   selector: 'colaboradores',
  12.   templateUrl: 'colaboradores.html'
  13. })
  14. export class ColaboradoresComponent {
  15.  
  16.  
  17.  
  18.   constructor(public afs: AngularFirestore, private afAuth: AngularFireAuth) {
  19.    
  20.   }
  21.  
  22.  
  23.   ngOnInit(){
  24.     this.sendCollaborationRequest('pedro.braga@ccc.ufcg.edu.br', 'nomeDoProjeto :)', 'idDoProjeto :)');
  25.   }
  26.  
  27.  
  28.   //Envia notificacao de colaboracao para um usuario do sistema
  29.   private sendCollaborationRequest(userEmail: String, projectName: String, projectId: String){
  30.     var userRequestedId = 'idDoUsuarioAReceberNotification'
  31.     const notificationsRef = this.afs.collection('notifications');
  32.     const usersRef = this.afs.firestore.collection('users');
  33.  
  34.  
  35.     /*usersRef.where('email', '==', userEmail).get()
  36.     .then(snap => userRequestedId = snap.docs[0].id)
  37.     .catch(err => userRequestedId = 'idDoDocumento'); */
  38.    
  39.     const notification = {
  40.       message: 'Você foi convidado para participar do projeto ' + projectName,
  41.       projectId: projectId,
  42.       seen: false,
  43.       type: 'chat',
  44.       userId: userRequestedId
  45.     }
  46.  
  47.     notificationsRef.add(notification)
  48.     .then(response => console.log("Notification sent!"))
  49.     .catch(err => console.log('Error while sending notification! id do usuario: ' + this.afAuth.auth.currentUser.uid));
  50.    
  51.  
  52. }  
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement