Untitled
unknown
plain_text
a year ago
2.0 kB
6
Indexable
import MatchesModel from '../database/models/MatchesModel'; import TeamModel from '../database/models/TeamModel'; import { IMatches } from '../Interfaces/Matches/IMatches'; export default class ConstructorLeaderBoard { constructor( private modelTeam = TeamModel, private modelMatches = MatchesModel, ) {} static totalGames(teamMatches: IMatches[]) { return teamMatches.length; } static totalPoints(teamMatches: IMatches[]) { const victory = teamMatches .filter((match) => match.homeTeamGoals > match.awayTeamGoals).length * 3; const draw = teamMatches.filter((match) => match.homeTeamGoals === match.awayTeamGoals).length; return victory + draw; } async teamsAndMatches() { const teams = await this.modelTeam.findAll(); const teamData = teams.map((team) => team.dataValues); const matches = await this.modelMatches.findAll({ where: { inProgress: false } }); const matchesData = matches.map((match) => match.dataValues); return { teamData, matchesData }; } static victories(teamMatches: IMatches[]) { return teamMatches.filter((match) => match.homeTeamGoals > match.awayTeamGoals).length; } static draws(teamMatches: IMatches[]) { return teamMatches.filter((match) => match.homeTeamGoals === match.awayTeamGoals).length; } static losses(teamMatches: IMatches[]) { return teamMatches.filter((match) => match.homeTeamGoals < match.awayTeamGoals).length; } static goalsFavor(teamMatches: IMatches[]) { return teamMatches.reduce((acc, match) => acc + match.homeTeamGoals, 0); } static goalsOwn(teamMatches: IMatches[]) { return teamMatches.reduce((acc, match) => acc + match.awayTeamGoals, 0); } static goalsBalance(teamMatches: IMatches[]) { const balanceGoalsFavor = teamMatches.reduce((acc, match) => acc + match.homeTeamGoals, 0); const balanceGoalsOwn = teamMatches.reduce((acc, match) => acc + match.awayTeamGoals, 0); return balanceGoalsFavor - balanceGoalsOwn; }
Editor is loading...
Leave a Comment