Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- await firebase
- .database()
- .ref('/Leagues/' + League_ID + '/GameResults')
- .on('child_added', snapshot => {
- const collection = snapshot.val();
- if (collection) {
- var objGameResults = null;
- const TeamIDsList = [];
- var matchdate = null;
- TeamIDsList.push(collection.TeamA);
- TeamIDsList.push(collection.TeamB);
- const LeaguePromises = TeamIDsList.map(TeamID => {
- return firebase
- .database()
- .ref()
- .child('Teams')
- .orderByKey()
- .equalTo(TeamID)
- .once('value', snapshot => snapshot);
- });
- Promise.all(LeaguePromises)
- .then(Teams => {
- Teams.forEach(singleObject => {
- var TList = JSON.stringify(singleObject);
- if (TList) {
- var Team_List = JSON.parse(TList);
- Object.keys(Team_List).forEach(key => {
- if (key == collection.WinnerTeam) {
- Team1Name = Team_List[key].TeamName;
- } else {
- Team2Name = Team_List[key].TeamName;
- }
- });
- }
- });
- GameResults.push({
- Scoredate: matchdate, //matchdate,
- ScoreData: {
- winnerTeam: {
- label: Team1Name,
- value: 123,
- division: 'South Division',
- ps: collection.TeamAScore,
- },
- loserTeam: {
- label: Team2Name,
- value: 123,
- division: 'South Division',
- ps: collection.TeamBScore,
- },
- },
- });
- this.setState({
- GameResults,
- isLoading: false,
- });
- // do something with the data
- })
- .catch(err => {
- // handle error
- this.setState({ isLoading: false });
- });
- }
- });
- await firebase
- .database()
- .ref('/Leagues/' + League_ID + '/GameResults')
- .on('child_added', snapshot => {
- const collection = snapshot.val();
- if (collection) {
- var objGameResults = null;
- const TeamIDsList = [];
- var matchdate = null;
- TeamIDsList.push(collection.TeamA);
- TeamIDsList.push(collection.TeamB);
- const LeaguePromises = TeamIDsList.map(TeamID => {
- return firebase
- .database()
- .ref()
- .child('Teams')
- .orderByKey()
- .equalTo(TeamID)
- .once('value', snapshot => snapshot);
- });
- Promise.all(LeaguePromises)
- .then(Teams => {
- Teams.forEach(singleObject => {
- var TList = JSON.stringify(singleObject);
- if (TList) {
- var Team_List = JSON.parse(TList);
- Object.keys(Team_List).forEach(key => {
- if (key == collection.WinnerTeam) {
- Team1Name = Team_List[key].TeamName;
- } else {
- Team2Name = Team_List[key].TeamName;
- }
- });
- }
- });
- GameResults.push({
- Scoredate: matchdate, //matchdate,
- ScoreData: {
- winnerTeam: {
- label: Team1Name,
- value: 123,
- division: 'South Division',
- ps: collection.TeamAScore,
- },
- loserTeam: {
- label: Team2Name,
- value: 123,
- division: 'South Division',
- ps: collection.TeamBScore,
- },
- },
- });
- this.setState({
- GameResults,
- isLoading: false,
- });
- // do something with the data
- })
- .catch(err => {
- // handle error
- this.setState({ isLoading: false });
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement