Skip to content

Commit

Permalink
Extracts logic for code climate score
Browse files Browse the repository at this point in the history
  • Loading branch information
fewieden committed Dec 16, 2023
1 parent 9ad0b20 commit 760250b
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions node_helper.js
Expand Up @@ -89,6 +89,8 @@ module.exports = NodeHelper.create({
nextGame: null,
/** @member {Game[]} liveGames - List of all ongoing games. */
liveGames: [],
/** @member {Game[]} liveStates - List of all live game states. */
liveStates: ['LIVE', 'CRIT'],

/**
* @function socketNotificationReceived
Expand Down Expand Up @@ -143,7 +145,7 @@ module.exports = NodeHelper.create({
},

/**
* @function getDates
* @function getScheduleDates
* @description Helper function to retrieve dates in the past and future based on config options.
* @async
*
Expand Down Expand Up @@ -171,6 +173,26 @@ module.exports = NodeHelper.create({
};
},

/**

Check warning on line 176 in node_helper.js

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc for parameter 'game'

Check warning on line 176 in node_helper.js

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc for parameter 'scores'
* @function getRemainingGameTime
* @description Helper function to retrieve remaining game time.
* @async
*
* @returns {string?} Remaining game time.
*/
getRemainingGameTime(game, scores) {
if (!this.liveStates.includes(game.gameState)) {
return;
}

const score = scores.find(score => score.id === game.id);
if (!score) {
return;
}

return score?.clock?.inIntermission ? '00:00' : score?.clock?.timeRemaining;
},

/**

Check warning on line 196 in node_helper.js

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc for parameter 'schedule'
* @function hydrateRemainingTime
* @description Hydrates remaining time on the games in the schedule from the scores API endpoint.
Expand All @@ -191,12 +213,7 @@ module.exports = NodeHelper.create({
const { games } = await scoresResponse.json();

for (const game of schedule) {
if (game.gameState !== 'LIVE' && game.gameState !== 'CRIT') {
continue;
}

const score = games.find(score => score.id === game.id);
game.timeRemaining = score?.clock?.inIntermission ? '00:00' : score?.clock?.timeRemaining;
game.timeRemaining = this.getRemainingGameTime(game, games);
}

return schedule;
Expand Down Expand Up @@ -472,7 +489,7 @@ module.exports = NodeHelper.create({
*/
setNextandLiveGames(games) {
this.nextGame = games.find(game => game.status === 'FUT');
this.liveGames = games.filter(game => ['LIVE', 'CRIT'].includes(game.status));
this.liveGames = games.filter(game => this.liveStates.includes(game.status));
},

/**
Expand Down

0 comments on commit 760250b

Please sign in to comment.