Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. await firebase
  2. .database()
  3. .ref('/Leagues/' + League_ID + '/GameResults')
  4. .on('child_added', snapshot => {
  5. const collection = snapshot.val();
  6. if (collection) {
  7. var objGameResults = null;
  8. const TeamIDsList = [];
  9. var matchdate = null;
  10. TeamIDsList.push(collection.TeamA);
  11. TeamIDsList.push(collection.TeamB);
  12. const LeaguePromises = TeamIDsList.map(TeamID => {
  13. return firebase
  14. .database()
  15. .ref()
  16. .child('Teams')
  17. .orderByKey()
  18. .equalTo(TeamID)
  19. .once('value', snapshot => snapshot);
  20. });
  21. Promise.all(LeaguePromises)
  22. .then(Teams => {
  23. Teams.forEach(singleObject => {
  24. var TList = JSON.stringify(singleObject);
  25. if (TList) {
  26. var Team_List = JSON.parse(TList);
  27. Object.keys(Team_List).forEach(key => {
  28. if (key == collection.WinnerTeam) {
  29. Team1Name = Team_List[key].TeamName;
  30. } else {
  31. Team2Name = Team_List[key].TeamName;
  32. }
  33. });
  34. }
  35. });
  36. GameResults.push({
  37. Scoredate: matchdate, //matchdate,
  38. ScoreData: {
  39. winnerTeam: {
  40. label: Team1Name,
  41. value: 123,
  42. division: 'South Division',
  43. ps: collection.TeamAScore,
  44. },
  45. loserTeam: {
  46. label: Team2Name,
  47. value: 123,
  48. division: 'South Division',
  49. ps: collection.TeamBScore,
  50. },
  51. },
  52. });
  53.  
  54. this.setState({
  55. GameResults,
  56. isLoading: false,
  57. });
  58. // do something with the data
  59. })
  60. .catch(err => {
  61. // handle error
  62. this.setState({ isLoading: false });
  63. });
  64. }
  65. });
  66.  
  67.  
  68. await firebase
  69. .database()
  70. .ref('/Leagues/' + League_ID + '/GameResults')
  71. .on('child_added', snapshot => {
  72. const collection = snapshot.val();
  73. if (collection) {
  74. var objGameResults = null;
  75. const TeamIDsList = [];
  76. var matchdate = null;
  77. TeamIDsList.push(collection.TeamA);
  78. TeamIDsList.push(collection.TeamB);
  79. const LeaguePromises = TeamIDsList.map(TeamID => {
  80. return firebase
  81. .database()
  82. .ref()
  83. .child('Teams')
  84. .orderByKey()
  85. .equalTo(TeamID)
  86. .once('value', snapshot => snapshot);
  87. });
  88. Promise.all(LeaguePromises)
  89. .then(Teams => {
  90. Teams.forEach(singleObject => {
  91. var TList = JSON.stringify(singleObject);
  92. if (TList) {
  93. var Team_List = JSON.parse(TList);
  94. Object.keys(Team_List).forEach(key => {
  95. if (key == collection.WinnerTeam) {
  96. Team1Name = Team_List[key].TeamName;
  97. } else {
  98. Team2Name = Team_List[key].TeamName;
  99. }
  100. });
  101. }
  102. });
  103. GameResults.push({
  104. Scoredate: matchdate, //matchdate,
  105. ScoreData: {
  106. winnerTeam: {
  107. label: Team1Name,
  108. value: 123,
  109. division: 'South Division',
  110. ps: collection.TeamAScore,
  111. },
  112. loserTeam: {
  113. label: Team2Name,
  114. value: 123,
  115. division: 'South Division',
  116. ps: collection.TeamBScore,
  117. },
  118. },
  119. });
  120.  
  121. this.setState({
  122. GameResults,
  123. isLoading: false,
  124. });
  125. // do something with the data
  126. })
  127. .catch(err => {
  128. // handle error
  129. this.setState({ isLoading: false });
  130. });
  131. }
  132. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement