2019-11-12 18:47:23 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
2019-12-01 14:20:49 +00:00
|
|
|
const Helpers = use('App/helpers')
|
2019-11-12 18:47:23 +00:00
|
|
|
const MatchRepository = make('App/Repositories/MatchRepository')
|
|
|
|
|
|
2019-12-01 14:20:49 +00:00
|
|
|
class StatsService {
|
2019-11-12 18:47:23 +00:00
|
|
|
constructor() {
|
|
|
|
|
this.matchRepository = MatchRepository
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getSummonerStats(account) {
|
|
|
|
|
const globalStats = await this.matchRepository.globalStats(account.puuid)
|
|
|
|
|
const gamemodeStats = await this.matchRepository.gamemodeStats(account.puuid)
|
|
|
|
|
const roleStats = await this.matchRepository.roleStats(account.puuid)
|
|
|
|
|
// Check if all roles are in the array
|
|
|
|
|
const roles = ['TOP', 'JUNGLE', 'MIDDLE', 'BOTTOM', 'SUPPORT']
|
|
|
|
|
for (const role of roles) {
|
|
|
|
|
if (!roleStats.find(r => r.role === role)) {
|
|
|
|
|
roleStats.push({
|
|
|
|
|
count: 0,
|
|
|
|
|
losses: 0,
|
|
|
|
|
role,
|
|
|
|
|
wins: 0
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-03 21:23:19 +00:00
|
|
|
const championStats = await this.matchRepository.championStats(account.puuid, 5)
|
2019-11-12 18:47:23 +00:00
|
|
|
const championClassStats = await this.matchRepository.championClassStats(account.puuid)
|
2020-01-08 20:16:21 +00:00
|
|
|
const mates = await this.matchRepository.mates(account.puuid)
|
2019-11-12 18:47:23 +00:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
global: globalStats[0],
|
|
|
|
|
league: gamemodeStats,
|
2019-12-01 14:20:49 +00:00
|
|
|
role: roleStats.sort(Helpers.sortTeamByRole),
|
2019-11-12 18:47:23 +00:00
|
|
|
class: championClassStats,
|
|
|
|
|
mates,
|
2019-11-24 13:26:27 +00:00
|
|
|
champion: championStats,
|
2019-11-12 18:47:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-01 14:20:49 +00:00
|
|
|
module.exports = new StatsService()
|