-
-
-
-
-
-
-
+
diff --git a/server/app/Controllers/Http/SummonerController.js b/server/app/Controllers/Http/SummonerController.js
index ea6665d..b5003a5 100644
--- a/server/app/Controllers/Http/SummonerController.js
+++ b/server/app/Controllers/Http/SummonerController.js
@@ -9,9 +9,9 @@ const Summoner = use('App/Models/Summoner')
class SummonerController {
/**
- * POST Endpoint : get summoner data
+ * POST: get basic summoner data
*/
- async api({ request, response }) {
+ async basic({ request, response }) {
console.time('all')
const summoner = request.input('summoner')
const region = request.input('region')
@@ -38,6 +38,11 @@ class SummonerController {
{ puuid: account.puuid }
)
+ // MATCH LIST
+ await MatchService.updateMatchList(account, summonerDB)
+ const matchList = summonerDB.matchList
+ finalJSON.allMatches = matchList
+
// CURRENT GAME
const currentGame = await Jax.Spectator.summonerID(account.id, region)
finalJSON.playing = !!currentGame
@@ -45,23 +50,6 @@ class SummonerController {
// RANKED STATS
finalJSON.ranked = await SummonerService.getRanked(account, region)
- // MATCH LIST
- await MatchService.updateMatchList(account, summonerDB)
- const matchList = summonerDB.matchList
- finalJSON.allMatches = matchList
-
- // MATCHES BASIC
- const gameIds = matchList.slice(0, 10).map(({ gameId }) => gameId)
- finalJSON.matchesDetails = await MatchService.getMatches(account, gameIds, summonerDB)
-
- // PATCH VERSION
- finalJSON.version = Jax.DDragon.Version
-
- // STATS
- console.time('STATS')
- finalJSON.stats = await StatsService.getSummonerStats(account)
- console.timeEnd('STATS')
-
// SAVE IN DB
await summonerDB.save()
} catch (error) {
@@ -74,6 +62,39 @@ class SummonerController {
return response.json(finalJSON)
}
+ /**
+ * POST: get overview view summoner data
+ */
+ async overview({ request, response }) {
+ console.time('overview')
+ const account = request.input('account')
+ const finalJSON = {}
+
+ // Summoner in DB
+ const summonerDB = await Summoner.findOrCreate(
+ { puuid: account.puuid },
+ { puuid: account.puuid }
+ )
+
+ // MATCHES BASIC
+ const gameIds = summonerDB.matchList.slice(0, 10).map(({ gameId }) => gameId)
+ finalJSON.matchesDetails = await MatchService.getMatches(account, gameIds, summonerDB)
+
+ // STATS
+ console.time('STATS')
+ finalJSON.stats = await StatsService.getSummonerStats(account)
+ console.timeEnd('STATS')
+
+ // SAVE IN DB
+ await summonerDB.save()
+
+ console.timeEnd('overview')
+ return response.json(finalJSON)
+ }
+
+ /**
+ * POST: get champions view summoner data
+ */
async champions({ request, response }) {
const puuid = request.input('puuid')
const queue = request.input('queue')
diff --git a/server/app/Services/MatchService.js b/server/app/Services/MatchService.js
index 7e9a375..e4f6cdf 100644
--- a/server/app/Services/MatchService.js
+++ b/server/app/Services/MatchService.js
@@ -15,7 +15,12 @@ class MatchService {
let alreadyIn = false
let index = 0
do {
- let newMatchList = (await Jax.Matchlist.accountID(account.accountId, account.region, index)).matches
+ let newMatchList = await Jax.Matchlist.accountID(account.accountId, account.region, index)
+ // Error while fetching Riot API
+ if (!newMatchList) {
+ return matchList
+ }
+ newMatchList = newMatchList.matches
matchList = [...matchList, ...newMatchList]
alreadyIn = newMatchList.length === 0 || stopFetching(newMatchList)
// If the match is made in another region : we stop fetching
diff --git a/server/start/routes.js b/server/start/routes.js
index 4692636..d02471b 100644
--- a/server/start/routes.js
+++ b/server/start/routes.js
@@ -25,8 +25,9 @@ Route.get('/', async () => {
}
})
-Route.post('/api', 'SummonerController.api')
-Route.post('/champions', 'SummonerController.champions')
+Route.post('/summoner-basic', 'SummonerController.basic')
+Route.post('/summoner-overview', 'SummonerController.overview')
+Route.post('/summoner-champions', 'SummonerController.champions')
Route.post('/ddragon', 'DDragonController.index')
Route.post('/match', 'MatchController.index')
Route.post('/match-details', 'MatchController.show')