-
Notifications
You must be signed in to change notification settings - Fork 10
/
clientRetriever.js
47 lines (45 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
var _ = require("underscore");
var dataProvider = require("./dataProvider");
var Contact = require("./contact");
var Client = require("./client");
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
);
});
};
exports.getContacts = getContacts;
exports.getClients = function() {
var contacts = getContacts();
return _.filter(contacts, function(contact) {
return contact instanceof Client;
});
};
exports.getOldestClients = function(count) {
return _.first(_.sortBy(this.getClients(), 'registered'), count);
};
exports.getBestClients = function(count) {
return _.first(_.sortBy(this.getClients(), 'bikePoints'), count);
};