Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- server.get('/topScore', async function(req, res){
- const group = req.query.group;
- const leagueid = req.query.leagueid;
- let api_key;
- const items = [];
- let match;
- let row = {};
- let masuk;
- if(group != 'other'){
- api_key = 'wpvzxf6d2wkjdkaqauyf4juk';
- }else{
- api_key = '3kdegdxesfebr8udhnyp5z68';
- }
- if(leagueid == '1015'){
- res.send([]);
- }
- const key = 'topscore_' + leagueid + '_' + group;
- try {
- client.get(key, function(error, result){
- if(result){
- res.send(JSON.parse(result));
- }else{
- const url = config.API_HOST + group + '/en/tournaments/sr:tournament:'+ leagueid +'/leaders.json?api_key=' +api_key ;
- axios.get(url)
- .then(function (response){
- if(_.has(response, 'data.top_points') && _.size(response.data.top_points) > 0){
- for (let i=0; i < 5; i++){
- const player = response.data.top_points[i].player.id;
- const seasonId = response.data.tournament.current_season.id;
- let row = response.data.top_points[i];
- console.log("ini kesatu");
- const url2 = config.API_HOST + group + '/en/players/'+player+'/profile.json?api_key=' +api_key;
- // *biar blok ini bisa diakses*
- axios.get(url2)
- .then(function(responses){
- if(_.size(responses.data.statistics.seasons) > 0){
- for (let j=0; j < responses.data.statistics.seasons.length; j++){
- if(responses.data.statistics.seasons[j].id == seasonId){
- masuk = seasonId;
- }
- }
- }
- row.tambah = masuk;
- })
- //===============================================================================
- console.log(row.tambah); //karena ini undefined
- items.push(row);
- }
- items.sort(function(a, b){
- return b.goals-a.goals;
- })
- res.setHeader('content-type', 'application/json');
- res.send({tournament: response.data.tournament, top_goals: items});
- // client.set(key, JSON.stringify({
- // tournament: response.data.tournament,
- // top_goals: items
- // }), 'NX');
- // res.send({tournament: response.data.tournament, top_goals: items});
- }else {
- throw new Error('Error');
- }
- }).catch(function(response) {
- res.send({
- code: 404,
- message: 'Request failed'
- });
- });
- }
- })
- }catch (error){
- res.send({
- code: 400,
- message: 'There is something wrong!'
- });
- }
- });
Add Comment
Please, Sign In to add comment