Monday, 15 May 2017

Asynchronous angular service

I want to create a angular service function that combines the three following endpoints and with the result returns an object with my data sorted in it. I'm using Node.js and just started angular.

My idea is to get the rankings then make an asynchronous loop for each item with the endpoint user and then sort my data. Or I could call my endpoint Users and then sort my data from this (Less http calls)

Is this a good idea?

Theses are my routes and what they return :

/ranking/:id 

returns a ranking from results in a video game

[
  { 
    position: 1,
    user: 1234,
    score: 150
  }, {
    position: 2,
    user: 5678,
    score: 100
  }
 ...
]

then

/users?ids=id1,id2,id3

returns an array of users

[
 {
  id: 1234,
  firstName: 'John',
  lastName: 'Doe'
 },
 ...
]

This is what I'm trying to get from my objects :

 [
  {
   position: 1,
   score: 150,
   firstName: 'John',
   lastName: 'Doe'
  },
  ...
 ]

Thanks for any help !



via pkerckho

No comments:

Post a Comment