2019-10-05 22:01:58 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
2019-11-03 17:49:58 +00:00
|
|
|
const Jax = use('Jax')
|
|
|
|
|
const DetailedMatch = use('App/Models/DetailedMatch')
|
|
|
|
|
const DetailedMatchTransformer = use('App/Transformers/DetailedMatchTransformer')
|
2019-10-05 22:01:58 +00:00
|
|
|
const MatchHelper = use('App/Helpers/MatchHelper')
|
2019-11-12 18:47:23 +00:00
|
|
|
const StatsHelper = use('App/Helpers/StatsHelper')
|
2019-10-25 21:09:33 +00:00
|
|
|
const Summoner = use('App/Models/Summoner')
|
2019-10-05 22:01:58 +00:00
|
|
|
|
|
|
|
|
class MatchController {
|
|
|
|
|
/**
|
|
|
|
|
* POST - Return data from matches searched by gameIds
|
|
|
|
|
*/
|
|
|
|
|
async index({ request, response }) {
|
|
|
|
|
console.log('More Matches Request')
|
|
|
|
|
const account = request.input('account')
|
|
|
|
|
const gameIds = request.input('gameIds')
|
|
|
|
|
|
2019-10-25 21:09:33 +00:00
|
|
|
const summonerDB = await Summoner.where({ puuid: account.puuid }).first()
|
|
|
|
|
const matches = await MatchHelper.getMatches(account, gameIds, summonerDB)
|
|
|
|
|
|
|
|
|
|
await summonerDB.save()
|
|
|
|
|
|
2019-11-12 18:47:23 +00:00
|
|
|
const stats = await StatsHelper.getSummonerStats(account)
|
2019-11-11 20:51:40 +00:00
|
|
|
|
2019-10-25 21:09:33 +00:00
|
|
|
return response.json({
|
|
|
|
|
matches,
|
2019-11-11 20:51:40 +00:00
|
|
|
stats,
|
2019-10-25 21:09:33 +00:00
|
|
|
})
|
2019-10-05 22:01:58 +00:00
|
|
|
}
|
2019-11-03 17:49:58 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* POST - Return details data for one specific match
|
|
|
|
|
*/
|
|
|
|
|
async show({ request, response }) {
|
|
|
|
|
console.log('Match details request')
|
|
|
|
|
const gameId = request.input('gameId')
|
|
|
|
|
const region = request.input('region')
|
|
|
|
|
console.log(gameId, region)
|
|
|
|
|
|
|
|
|
|
let matchFromRiot = await Jax.Match.get(gameId)
|
|
|
|
|
|
2019-11-16 16:43:55 +00:00
|
|
|
matchFromRiot = await DetailedMatchTransformer.transform(matchFromRiot)
|
2019-11-03 17:49:58 +00:00
|
|
|
|
|
|
|
|
// DetailedMatch.save(matchFromRiot)
|
|
|
|
|
|
|
|
|
|
return response.json({
|
|
|
|
|
matchDetails: matchFromRiot
|
|
|
|
|
})
|
|
|
|
|
}
|
2019-10-05 22:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = MatchController
|