-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathstats-total-paid-moderators.js
73 lines (62 loc) · 2.26 KB
/
stats-total-paid-moderators.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
62
63
64
65
66
67
68
69
70
71
72
73
import Post from './server/models/post.model';
import Moderator from './server/models/moderator.model';
import Sponsor from './server/models/sponsor.model';
import { calculatePayout } from './server/steemitHelpers';
import * as R from 'ramda';
import config from './config/config';
const mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
mongoose.connect(`${config.mongo.host}`);
const conn = mongoose.connection;
conn.once('open', function ()
{
const paidRewardsDate = '1969-12-31T23:59:59';
Moderator.list()
.then(moderators => {
if (moderators.length > 0) {
moderators.forEach((moderator, index) => {
let total_paid_rewards = 0;
const query = {
beneficiaries: {
$elemMatch: {
account: moderator.account
}
},
cashout_time:
{
$eq: paidRewardsDate
},
};
Post
.countAll({ query })
.then(count => {
Post
.list({ skip: 0, limit: count, query })
.then(posts => {
if(posts.length > 0) {
posts.forEach(post => {
const beneficiary = R.find(R.propEq('account', moderator.account))(post.beneficiaries);
const payoutDetails = calculatePayout(post);
const payoutModerator = (payoutDetails.authorPayouts * (beneficiary.weight / 100)) / 100;
total_paid_rewards = total_paid_rewards + payoutModerator;
});
}
Sponsor.get(moderator.account).then(sponsor => {
if (sponsor) {
moderator.total_paid_rewards = total_paid_rewards - sponsor.total_paid_rewards;
} else {
moderator.total_paid_rewards = total_paid_rewards;
}
moderator.save().then(savedModerator => {
if ((index + 1) === moderators.length) {
conn.close();
process.exit(0);
}
});
});
})
});
});
}
});
});