mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-28 13:55:37 +00:00
12 lines
459 B
JavaScript
12 lines
459 B
JavaScript
|
|
// require moment, lodash
|
||
|
|
db.users.find(
|
||
|
|
{'purchased.plan.customerId':{$ne:null}},
|
||
|
|
{'purchased.plan':1}
|
||
|
|
).forEach(function(user){
|
||
|
|
var p = user.purchased.plan;
|
||
|
|
var latestMonth = p.dateTerminated || p.dateCreated;
|
||
|
|
// TODO is rounding up what we want?
|
||
|
|
var consecutiveMonths = Math.ceil(moment(p.dateCreated).diff(latestMonth, 'months', true));
|
||
|
|
db.users.update({_id: user._id}, {$set: {'purchased.plan.consecutiveMonths': consecutiveMonths}});
|
||
|
|
});
|