From 2bfaaa226c4271613bec14d4cffbe9d14b5d0afd Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Thu, 14 Jul 2016 19:24:53 +0200 Subject: [PATCH] donor to patron DB script --- bin/mongodb/donor-patron.js | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 bin/mongodb/donor-patron.js diff --git a/bin/mongodb/donor-patron.js b/bin/mongodb/donor-patron.js new file mode 100644 index 0000000000..c7e6425104 --- /dev/null +++ b/bin/mongodb/donor-patron.js @@ -0,0 +1,40 @@ +var now = new Date(); +var inOneMonth = new Date(ISODate().getTime() + 1000 * 60 * 60 * 24 * 31); + +db.plan_patron.remove({}); +db.user4.update({plan:{$exists:true}},{$unset:{plan:true}},{multi:true}); + +var userIds = []; +function donationToPatron(donation) { + if (userIds.indexOf(donation.userId) !== -1) return; + userIds.push(donation.userId); + var patron = { + _id: donation.userId, + payPal: { + lastCharge: donation.date + }, + lastLevelUp: now, + expiresAt: inOneMonth + } + if (donation.payPalSub) patron.payPal.subId = donation.payPalSub; + if (donation.email) patron.payPal.email = donation.email; + db.plan_patron.insert(patron); + db.user4.update({ + _id: donation.userId + }, { + $set: { + plan: { + active: true, + months: NumberInt(1) + } + } + }); +} + +db.donation.find({userId:{'$exists':true}}).sort({date:-1}).forEach(donationToPatron); + +donationToPatron({ + userId: 'thibault', + date: new Date(ISODate().getTime() - 1000 * 60 * 60 * 24 * 31 * 3), + email: 'lichess.contact@gmail.com' +});