Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.getTestUsers = function(request, response){
- var data = [
- {
- "id": 1,
- "name": "Nissim",
- "age": 41,
- "money": 454,
- email: "dev.adonovan@gmail.com"
- },
- {
- "id": 2,
- "name": "Mariko",
- "age": 10,
- email: "dev.adonovan@gmail.com",
- "money": -100
- },
- {
- "id": 3,
- "name": "Mark",
- "age": 39,
- "money": 291,
- email: "dev.adonovan@gmail.com"
- },
- {
- "id": 4,
- "name": "Allen",
- "age": 85,
- "money": 871,
- email: "dev.adonovan@gmail.com"
- },
- {
- "id": 5,
- "name": "Dustin",
- "age": 10,
- "money": 378,
- email: "dev.adonovan@gmail.com"
- },
- {
- "id": 6,
- "name": "Macon",
- "age": 9,
- "money": 128,
- email: "dev.adonovan@gmail.com"
- },
- {
- "id": 7,
- "name": "Ezra",
- "age": 78,
- "money": 11,
- email: "dev.adonovan@gmail.com"
- },
- {
- "id": 8,
- "name": "Fiona",
- "age": 87,
- "money": 285,
- email: "dev.adonovan@gmail.com"
- },
- {
- "id": 9,
- "name": "Ira",
- "age": 7,
- "money": 816,
- email: "dev.adonovan@gmail.com"
- },
- {
- "id": 10,
- "name": "Barbara",
- "age": 46,
- "money": 44,
- email: "dev.adonovan@gmail.com"
- },
- {
- "id": 11,
- "name": "Lydia",
- "age": 56,
- "money": 494,
- email: "dev.adonovan@gmail.com"
- },
- {
- "id": 12,
- "name": "Carlos",
- "age": 80,
- "money": 193,
- email: "dev.adonovan@gmail.com"
- }
- ];
- for (var i = 0; i < 1000; i++) {
- data.push({
- "id": 12 + i,
- "name": "Carlos" + i,
- "age": 80+ i,
- "money": 193+ i,
- email: "dev.adonovan@gmail.com"+ i
- })
- }
- var count = request.query.count;
- var page = request.query.page;
- var total = data.length;
- if (typeof request.query.sorting !== "undefined") {
- // console.log(request.query.sorting)
- var fieldToSort = Object.keys(request.query.sorting)[0];
- data.sort(function (a, b) {
- if (a[fieldToSort] < b[fieldToSort]) {
- return -1;
- } else {
- if (a[fieldToSort] > b[fieldToSort]) {
- return 1;
- } else {
- return 0;
- }
- }
- });
- }
- data = data.slice((count * (page - 1)),(count * page));
- // setTimeout(function() {
- response.setHeader("Content-Type", "application/json");
- response.json({data: data, total: total});
- // }, 1000);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement