Send an object instead of array for the JSON response

This commit is contained in:
Valentin Kaelin 2019-08-27 22:17:16 +02:00
parent 3683776e24
commit b552c5ccee
2 changed files with 14 additions and 16 deletions

View file

@ -176,10 +176,9 @@ export default {
console.log('--- ALL INFOS ---') console.log('--- ALL INFOS ---')
console.log(JSONData) console.log(JSONData)
const userStats = JSONData[0] const userStats = JSONData.account
const rankedStats = JSONData[1] const soloQStats = JSONData.soloQ
const soloQStats = rankedStats !== null ? (rankedStats.queueType == 'RANKED_SOLO_5x5' ? rankedStats : JSONData[2]) : false const matches = JSONData.matchesDetails
const matches = JSONData[3]
const matchesInfos = [] const matchesInfos = []
// Loop on all matches // Loop on all matches
@ -242,7 +241,7 @@ export default {
this.localInfos = { this.localInfos = {
accountId: userStats.accountId, accountId: userStats.accountId,
allMatches: JSONData[4].matches, allMatches: JSONData.allMatches,
matches: matchesInfos, matches: matchesInfos,
profileIconId: userStats.profileIconId, profileIconId: userStats.profileIconId,
name: userStats.name, name: userStats.name,

View file

@ -17,7 +17,7 @@ const data = {
accountID: '', accountID: '',
username: '', username: '',
JSONMatches: [], JSONMatches: [],
finalJSON: [] finalJSON: {}
} }
/* Setup Riot API Wrapper */ /* Setup Riot API Wrapper */
@ -77,7 +77,7 @@ app.post('/api', function (req, res) {
jax.regionName = req.body.region jax.regionName = req.body.region
newVersion() newVersion()
data.finalJSON = []; data.finalJSON = {};
getAccountInfos(res); getAccountInfos(res);
}); });
@ -95,7 +95,7 @@ const getAccountInfos = function (res) {
let JSONBody = JSON.parse(body); let JSONBody = JSON.parse(body);
data.summonerID = JSONBody.id; data.summonerID = JSONBody.id;
data.accountID = JSONBody.accountId; data.accountID = JSONBody.accountId;
data.finalJSON.push(JSONBody) data.finalJSON.account = JSONBody
getRanked(res); getRanked(res);
} }
else { else {
@ -110,13 +110,12 @@ const getAccountInfos = function (res) {
const getRanked = function (res) { const getRanked = function (res) {
request(`https://${data.region}.api.riotgames.com/lol/league/v4/entries/by-summoner/${data.summonerID}?api_key=${data.key}`, function (error, response, body) { request(`https://${data.region}.api.riotgames.com/lol/league/v4/entries/by-summoner/${data.summonerID}?api_key=${data.key}`, function (error, response, body) {
if (!error && response.statusCode == 200) { if (!error && response.statusCode == 200) {
let JSONBody = JSON.parse(body).filter(e => e.queueType !== 'RANKED_TFT' && e.queueType !== 'RANKED_FLEX_TT'); const JSONBody = JSON.parse(body).filter(e => e.queueType === 'RANKED_SOLO_5x5');
if (JSONBody.length > 0) { if (JSONBody.length === 1) {
data.finalJSON.push(...JSONBody); data.finalJSON.soloQ = JSONBody[0];
if (JSONBody.length === 1) data.finalJSON.push(null);
} else { } else {
console.log('empty rank stats') console.log('empty rank stats');
data.finalJSON.push(null, null); data.finalJSON.soloQ = null;
} }
getMatches(res); getMatches(res);
} }
@ -138,8 +137,8 @@ const getMatches = function (res) {
}).then(() => { }).then(() => {
console.timeEnd('getMatches'); console.timeEnd('getMatches');
console.log('Finished - Data sent to front'); console.log('Finished - Data sent to front');
data.finalJSON.push(data.JSONMatches) data.finalJSON.matchesDetails = data.JSONMatches
data.finalJSON.push(allMatches) data.finalJSON.allMatches = allMatches.matches
res.send(data.finalJSON); res.send(data.finalJSON);
console.timeEnd('all') console.timeEnd('all')
}).catch(err => { }).catch(err => {