Guest User

Untitled

a guest
Feb 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. const getUserObject = user_id => {
  2. let userInfo = {};
  3. let ops = [
  4. getUser(user_id),
  5. getUserDetails(user_id),
  6. getOrders(user_id),
  7. getWishlist(user_id),
  8. ];
  9.  
  10. return Promise.all(ops)
  11. .then(results => {
  12. userInfo = {
  13. "id": user_id,
  14. "username" : results[0].name,
  15. "email" : results[0].email,
  16. "gender" : results[1].gender,
  17. "age" : results[1].age,
  18. "state" : results[1].state,
  19. "orders" : [],
  20. "wishlist" : []
  21. }
  22. results[2].map(order => { userInfo.orders.push({ "product_id": order.product_id }) })
  23. results[3].map(wish => { userInfo.wishlist.push({ "product_id": wish.product_id }) })
  24. return userInfo
  25. }).catch(error => error);
  26. }
Add Comment
Please, Sign In to add comment