forked from alexpopdev/underscorejs-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clientRetriever.js
48 lines (46 loc) · 1.29 KB
/
clientRetriever.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var clientRetriever = (function() {
"use strict";
var getContacts = function() {
var clientObjects = dataProvider.getClients();
return _.map(clientObjects, function(clientObject) {
if (!clientObject.isActive) {
return new Contact(
clientObject.id,
clientObject.name,
clientObject.gender,
clientObject.company,
clientObject.email,
clientObject.phone,
clientObject.address);
}
return new Client(
clientObject.id,
clientObject.name,
clientObject.gender,
clientObject.company,
clientObject.email,
clientObject.phone,
clientObject.address,
new Date(clientObject.registered),
clientObject.preferredBike,
clientObject.bikePoints,
clientObject.notes
);
});
};
return {
getContacts: getContacts,
getClients: function() {
var contacts = getContacts();
return _.filter(contacts, function(contact) {
return contact instanceof Client;
});
},
getOldestClients: function(count) {
return _.first(_.sortBy(this.getClients(), 'registered'), count);
},
getBestClients: function(count) {
return _.first(_.sortBy(this.getClients(), 'bikePoints'), count);
}
};
}());