-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequests.js
27 lines (25 loc) · 993 Bytes
/
requests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const apiUrl = 'https://apigateway.test.lifeworks.com/rescue-shelter-api';
const request = require('request-promise');
const _ = require('lodash/collection');
const getColourOrder = (colour) => {
let result = 3;
if (colour === 'ginger') result = 1;
if (colour === 'black') result = 2;
return result;
};
const cats = () => request(`${apiUrl}/cats`)
.then(value =>
_.orderBy(JSON.parse(value).body
.map(cat => ({
forename: cat.forename,
surname: cat.surname,
dateOfBirth: cat.dateOfBirth,
image: cat.image,
colour: cat.colour,
colourOrder: getColourOrder(cat.colour),
})), ['colourOrder', 'dateOfBirth'], ['asc', 'asc']));
const dogs = () => request(`${apiUrl}/dogs`)
.then(value => _.orderBy(JSON.parse(value).body, ['dateOfBirth'], 'asc'));
const hamsters = () => request(`${apiUrl}/hamsters`)
.then(value => _.orderBy(JSON.parse(value).body, ['dateOfBirth'], 'desc'));
module.exports = { cats, dogs, hamsters };