Advertisement
Guest User

Untitled

a guest
May 25th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. exports.getTestUsers = function(request, response){
  2. var data = [
  3. {
  4. "id": 1,
  5. "name": "Nissim",
  6. "age": 41,
  7. "money": 454,
  8. email: "dev.adonovan@gmail.com"
  9. },
  10. {
  11. "id": 2,
  12. "name": "Mariko",
  13. "age": 10,
  14. email: "dev.adonovan@gmail.com",
  15. "money": -100
  16. },
  17. {
  18. "id": 3,
  19. "name": "Mark",
  20. "age": 39,
  21. "money": 291,
  22. email: "dev.adonovan@gmail.com"
  23. },
  24. {
  25. "id": 4,
  26. "name": "Allen",
  27. "age": 85,
  28. "money": 871,
  29. email: "dev.adonovan@gmail.com"
  30. },
  31. {
  32. "id": 5,
  33. "name": "Dustin",
  34. "age": 10,
  35. "money": 378,
  36. email: "dev.adonovan@gmail.com"
  37. },
  38. {
  39. "id": 6,
  40. "name": "Macon",
  41. "age": 9,
  42. "money": 128,
  43. email: "dev.adonovan@gmail.com"
  44. },
  45. {
  46. "id": 7,
  47. "name": "Ezra",
  48. "age": 78,
  49. "money": 11,
  50. email: "dev.adonovan@gmail.com"
  51. },
  52. {
  53. "id": 8,
  54. "name": "Fiona",
  55. "age": 87,
  56. "money": 285,
  57. email: "dev.adonovan@gmail.com"
  58. },
  59. {
  60. "id": 9,
  61. "name": "Ira",
  62. "age": 7,
  63. "money": 816,
  64. email: "dev.adonovan@gmail.com"
  65. },
  66. {
  67. "id": 10,
  68. "name": "Barbara",
  69. "age": 46,
  70. "money": 44,
  71. email: "dev.adonovan@gmail.com"
  72. },
  73. {
  74. "id": 11,
  75. "name": "Lydia",
  76. "age": 56,
  77. "money": 494,
  78. email: "dev.adonovan@gmail.com"
  79. },
  80. {
  81. "id": 12,
  82. "name": "Carlos",
  83. "age": 80,
  84. "money": 193,
  85. email: "dev.adonovan@gmail.com"
  86. }
  87. ];
  88. for (var i = 0; i < 1000; i++) {
  89. data.push({
  90. "id": 12 + i,
  91. "name": "Carlos" + i,
  92. "age": 80+ i,
  93. "money": 193+ i,
  94. email: "dev.adonovan@gmail.com"+ i
  95. })
  96. }
  97. var count = request.query.count;
  98. var page = request.query.page;
  99. var total = data.length;
  100. if (typeof request.query.sorting !== "undefined") {
  101. // console.log(request.query.sorting)
  102. var fieldToSort = Object.keys(request.query.sorting)[0];
  103. data.sort(function (a, b) {
  104. if (a[fieldToSort] < b[fieldToSort]) {
  105. return -1;
  106. } else {
  107. if (a[fieldToSort] > b[fieldToSort]) {
  108. return 1;
  109. } else {
  110. return 0;
  111. }
  112. }
  113. });
  114. }
  115. data = data.slice((count * (page - 1)),(count * page));
  116. // setTimeout(function() {
  117. response.setHeader("Content-Type", "application/json");
  118. response.json({data: data, total: total});
  119. // }, 1000);
  120. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement