acupoftee / Pachimari

Discord bot for retrieving the latest in Overwatch League news. (Shutdown due to OWL API shutdown)
https://acupoftee.github.io/Pachimari-Dashboard
1 stars 0 forks source link

TeamCommand Schedule Argument cannot read match.competitor.id #3

Closed acupoftee closed 5 years ago

acupoftee commented 5 years ago

!team <team> schedule now throws an error stating the following below. This however was tested the same day earlier with the code unchanged and was able to pass.

(node:26513) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'id' of null
    at week.matches.forEach._match (/Users/deedee/Desktop/Coding/Web Dev/Pachimari/src/commands/TeamCommand.js:122:59)
    at Array.forEach (<anonymous>)
    at _stage.weeks.forEach.week (/Users/deedee/Desktop/Coding/Web Dev/Pachimari/src/commands/TeamCommand.js:121:42)
    at Array.forEach (<anonymous>)
    at body.data.stages.forEach._stage (/Users/deedee/Desktop/Coding/Web Dev/Pachimari/src/commands/TeamCommand.js:119:38)
    at Array.forEach (<anonymous>)
    at TeamCommand.execute (/Users/deedee/Desktop/Coding/Web Dev/Pachimari/src/commands/TeamCommand.js:117:34)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)
(node:26513) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:26513) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
acupoftee commented 5 years ago

Team Schedule is now displayed after wrapping the retrieval code with a promise. Promise now needs to be properly handled to remove the warning.

let promise = new Promise(function (resolve, reject) {
                    let currentTime = new Date().getTime();
                    let slug = null;
                    for (let i = 0; i < stageData.length; i++) {
                        stage = stageData[i];
                        if (currentTime > stage.startDate && currentTime < stage.endDate) {
                            slug = stage.slug;
                        }
                    }
                    // organize data by stage and week
                    body.data.stages.forEach(_stage => {
                        if (_stage.slug === slug) {
                            stage = _stage.name;
                            _stage.weeks.forEach(week => {
                                week.matches.forEach(_match => {
                                    if (_match.competitors[0].id == competitor.id || _match.competitors[1].id == competitor.id) {
                                        let home = CompetitorManager.competitors.get(CompetitorManager.locateTeam(_match.competitors[1].abbreviatedName));
                                        let away = CompetitorManager.competitors.get(CompetitorManager.locateTeam(_match.competitors[0].abbreviatedName));
                                        let match = new Match(_match.id, (_match.state === 'PENDING') ? true : false,
                                            _match.state, _match.startDate, home, away, _match.scores[1].value, _match.scores[0].value);
                                        matches.push(match);
                                    }
                                });

                            });
                        }
                    });
                    resolve(1);
                });
acupoftee commented 5 years ago

The API added the Stage Playoffs as a week but the teams aren't included yet. The code now needs to accommodate Stage Playoffs

acupoftee commented 5 years ago

API has removed the extra week containing null data for the stage week playoffs. API will be followed closely for further updates