-
Notifications
You must be signed in to change notification settings - Fork 27
/
contributions.js
61 lines (51 loc) · 1.33 KB
/
contributions.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
49
50
51
52
53
54
55
56
57
58
59
60
61
//contributions.js
//Contributions API
const db = require('./campaignFinanceDb')();
const q = require('q');
const logger = require('./utils/logger');
module.exports = {
getTopIndividualDonors: getTopIndividualDonors,
getTopCorporateDonors: getTopCorporateDonors,
getDonorsForCandidate: getDonorsForCandidate,
getAllDonors: getAllDonors
};
function getTopIndividualDonors(year) {
const deferred = q.defer();
db.contributions
.aggregate(
{ $match: { type: 'Individual' } },
{ $group: { _id: '$contributor', amount: { $sum: '$amount' } } },
{ $sort: { amount: -1 } },
{ $limit: 10 }
)
.then(
function(data) {
deferred.resolve(data);
},
function(err) {
deferred.reject(err);
}
);
return deferred.promise;
}
function getTopCorporateDonors(year) {
const deferred = q.defer();
db.contributions
.aggregate(
{ $match: { type: { $in: ['Other', 'Corporation'] } } },
{ $group: { _id: '$contributor', amount: { $sum: '$amount' } } },
{ $sort: { amount: -1 } },
{ $limit: 10 }
)
.then(
function(data) {
deferred.resolve(data);
},
function(err) {
deferred.reject(err);
}
);
return deferred.promise;
}
function getDonorsForCandidate(candidate, skip) {}
function getAllDonors(skip) {}