-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathstats-total-pending.js
47 lines (40 loc) · 1.21 KB
/
stats-total-pending.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
import Post from './server/models/post.model';
import Stats from './server/models/stats.model';
import { calculatePayout } from './server/steemitHelpers';
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';
const query = {
cashout_time:
{
$gt: paidRewardsDate
},
};
Post
.countAll({ query })
.then(count => {
Post
.list({ skip: 0, limit: count, query })
.then(posts => {
if(posts.length > 0) {
Stats.get().then(stats => {
let total_pending_rewards = 0;
posts.forEach((post, index) => {
const payoutDetails = calculatePayout(post);
total_pending_rewards = total_pending_rewards + payoutDetails.potentialPayout;
});
stats.total_pending_rewards = total_pending_rewards;
stats.save().then(savedStats => {
conn.close();
process.exit(0);
});
});
}
})
})
});