server/sports/sports-parsing.js
// Sends notifications about every game result from the current day.
Sends notifications about every game result from the current day.
Sends notifications about every game result from the current day .
function sendGameResultNotifications() {
    parseAllSportsData(function () {
        helper.findAllGameResults(function (gameResults) {
            if (gameResults) {
                gameResults.forEach(function (gameResult) {
                    var gameDate = moment(gameResult.game_date, 'yyyy.MM.ddTHH:mm:ss.SSSZ');
                    if (gameResult.home_score != -1 && gameResult.opponent_score != -1 && gameDate.isSame(moment(), 'd')) {
                        var notificationText = '';
                        if (gameResult.home_score > gameResult.opponent_score) {
                            notificationText = 'Shorecrest ' + gameResult.sport_name + ' won ' + gameResult.home_score + '-' + gameResult.opponent_score + ' vs. ' + gameResult.opponent_name;
                        } else if (gameResult.home_score < gameResult.opponent_score) {
                            notificationText = 'Shorecrest ' + gameResult.sport_name + ' lost ' + gameResult.opponent_score + '-' + gameResult.home_score + ' vs. ' + gameResult.opponent_name;
                        } else {
                            notificationText = 'Shorecrest ' + gameResult.sport_name + ' tied ' + gameResult.home_score + '-' + gameResult.opponent_score + ' vs. ' + gameResult.opponent_name;
                        }
                        helper.findAllClients(function (clients) {
                            if (clients) {
                                clients.forEach(function (client) {
                                    if (client.push_token) {
                                        notifications.sendNotification([client.push_token], notificationText, false);
                                    }
                                });
                            }
                        });
                    }
                });
            }
        });
    });
}
function sendGameResultNotifications ( ) { parseAllSportsData ( function ( ) { helper . findAllGameResults ( function ( gameResults ) { if ( gameResults ) { gameResults . forEach ( function ( gameResult ) { var gameDate = moment ( gameResult . game_date , 'yyyy.MM.ddTHH:mm:ss.SSSZ' ) ; if ( gameResult . home_score != - 1 && gameResult . opponent_score != - 1 && gameDate . isSame ( moment ( ) , 'd' ) ) { var notificationText = '' ; if ( gameResult . home_score > gameResult . opponent_score ) { notificationText = 'Shorecrest ' + gameResult . sport_name + ' won ' + gameResult . home_score + '-' + gameResult . opponent_score + ' vs. ' + gameResult . opponent_name ; } else if ( gameResult . home_score < gameResult . opponent_score ) { notificationText = 'Shorecrest ' + gameResult . sport_name + ' lost ' + gameResult . opponent_score + '-' + gameResult . home_score + ' vs. ' + gameResult . opponent_name ; } else { notificationText = 'Shorecrest ' + gameResult . sport_name + ' tied ' + gameResult . home_score + '-' + gameResult . opponent_score + ' vs. ' + gameResult . opponent_name ; } helper . findAllClients ( function ( clients ) { if ( clients ) { clients . forEach ( function ( client ) { if ( client . push_token ) { notifications . sendNotification ( [ client . push_token ] , notificationText , false ) ; } } ) ; } } ) ; } } ) ; } } ) ; } ) ; }
Sends notifications about every game result from the current day.
Sends notifications about every game result from the current day .