Guest User

Untitled

a guest
Jun 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. this.datesIdCollection = this.afs.collection('dates');
  2. this.afs.collection('dates').valueChanges().subscribe(dateIdAmounts =>{
  3. this.dateIdAmounts = dateIdAmounts as DateAmountId[];
  4. });
  5.  
  6. updateOrAddToDates(){
  7. for(let dateAmount of this.dateIdAmounts){
  8. for (let selectedDate of this.selectedDates) {
  9. if(selectedDate.getTime()=== dateAmount.date.getTime()){
  10. this.datesCollection.doc(dateAmount.id).update(new DateAmount(selectedDate, this.amount));
  11. }else{
  12. this.pushToDates(new DateAmount(selectedDate, this.amount));
  13. break;
  14. }
  15. }
  16. }
  17. }
  18.  
  19. pushToDates(datAmount){
  20. const datum = new Date();
  21. this.datesCollection.add({
  22. amount: datAmount.amount,
  23. date: datAmount.date
  24. }).then(
  25. (docRef) =>{
  26. this.datesCollection.doc(docRef.id).update({
  27. id: docRef.id
  28. })
  29. }
  30. );
  31. }
Add Comment
Please, Sign In to add comment