2019-09-11 07:06:21 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
2019-09-11 18:19:15 +00:00
|
|
|
const Jax = use('Jax')
|
2019-10-01 19:39:26 +00:00
|
|
|
const MatchHelper = use('App/Helpers/MatchHelper')
|
2019-09-11 07:06:21 +00:00
|
|
|
|
|
|
|
|
class SummonerController {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* POST Endpoint : get summoner data
|
|
|
|
|
*/
|
2019-10-05 18:01:01 +00:00
|
|
|
async api({ request, response }) {
|
|
|
|
|
console.time('all')
|
2019-09-11 07:06:21 +00:00
|
|
|
const summoner = request.input('summoner')
|
|
|
|
|
const region = request.input('region')
|
|
|
|
|
console.log(summoner, region)
|
|
|
|
|
|
|
|
|
|
const regexSummonerName = new RegExp('^[0-9\\p{L} _\\.]+$', 'u')
|
|
|
|
|
if (!regexSummonerName.exec(summoner)) {
|
2019-10-05 18:01:01 +00:00
|
|
|
return response.json(null)
|
2019-09-11 07:06:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const finalJSON = {}
|
|
|
|
|
Jax.regionName = region
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const account = await Jax.Summoner.summonerName(summoner)
|
|
|
|
|
// Check if the summoner is found
|
2019-10-05 18:01:01 +00:00
|
|
|
if (!account) return response.json(null)
|
2019-09-11 07:06:21 +00:00
|
|
|
finalJSON.account = account
|
|
|
|
|
|
2019-10-05 18:01:01 +00:00
|
|
|
// RANKED STATS
|
2019-09-11 07:06:21 +00:00
|
|
|
const ranked = await Jax.League.summonerID(account.id)
|
|
|
|
|
const soloQ = ranked.filter(e => e.queueType === 'RANKED_SOLO_5x5')
|
|
|
|
|
finalJSON.soloQ = soloQ.length ? soloQ[0] : null;
|
|
|
|
|
|
2019-10-01 19:39:26 +00:00
|
|
|
// MATCH LIST
|
|
|
|
|
const matchList = await MatchHelper.getFullMatchList(account)
|
2019-10-05 18:01:01 +00:00
|
|
|
finalJSON.allMatches = matchList
|
2019-10-01 19:39:26 +00:00
|
|
|
|
|
|
|
|
// MATCHES DETAILS
|
|
|
|
|
const gameIds = matchList.slice(0, 10).map(({ gameId }) => gameId)
|
2019-10-05 18:01:01 +00:00
|
|
|
finalJSON.matchesDetails = await MatchHelper.getMatches(account, gameIds)
|
2019-09-11 07:06:21 +00:00
|
|
|
} catch (error) {
|
|
|
|
|
console.log('username not found')
|
|
|
|
|
console.log(error)
|
2019-10-05 18:01:01 +00:00
|
|
|
return response.json(null)
|
2019-09-11 07:06:21 +00:00
|
|
|
}
|
2019-10-05 18:01:01 +00:00
|
|
|
|
|
|
|
|
console.timeEnd('all')
|
|
|
|
|
return response.json(finalJSON)
|
2019-09-11 07:06:21 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = SummonerController
|