start upgrading eslint
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
/* eslint-disable no-console */
|
||||
import axios from 'axios';
|
||||
import { model as User } from '../website/server/models/user';
|
||||
import nconf from 'nconf';
|
||||
import { model as User } from '../website/server/models/user';
|
||||
|
||||
const AMPLITUDE_KEY = nconf.get('AMPLITUDE_KEY');
|
||||
const AMPLITUDE_SECRET = nconf.get('AMPLITUDE_SECRET');
|
||||
const BASE_URL = nconf.get('BASE_URL');
|
||||
|
||||
async function _deleteAmplitudeData (userId, email) {
|
||||
async function deleteAmplitudeData (userId, email) {
|
||||
const response = await axios.post(
|
||||
'https://amplitude.com/api/2/deletions/users',
|
||||
{
|
||||
@@ -19,22 +19,24 @@ async function _deleteAmplitudeData (userId, email) {
|
||||
username: AMPLITUDE_KEY,
|
||||
password: AMPLITUDE_SECRET,
|
||||
},
|
||||
}
|
||||
).catch((err) => {
|
||||
},
|
||||
).catch(err => {
|
||||
console.log(err.response.data);
|
||||
});
|
||||
|
||||
if (response) console.log(`${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
async function _deleteHabiticaData (user, email) {
|
||||
async function deleteHabiticaData (user, email) {
|
||||
await User.update(
|
||||
{_id: user._id},
|
||||
{$set: {
|
||||
'auth.local.email': email,
|
||||
'auth.local.hashed_password': '$2a$10$QDnNh1j1yMPnTXDEOV38xOePEWFd4X8DSYwAM8XTmqmacG5X0DKjW',
|
||||
'auth.local.passwordHashMethod': 'bcrypt',
|
||||
}}
|
||||
{ _id: user._id },
|
||||
{
|
||||
$set: {
|
||||
'auth.local.email': email,
|
||||
'auth.local.hashed_password': '$2a$10$QDnNh1j1yMPnTXDEOV38xOePEWFd4X8DSYwAM8XTmqmacG5X0DKjW',
|
||||
'auth.local.passwordHashMethod': 'bcrypt',
|
||||
},
|
||||
},
|
||||
);
|
||||
const response = await axios.delete(
|
||||
`${BASE_URL}/api/v3/user`,
|
||||
@@ -46,8 +48,8 @@ async function _deleteHabiticaData (user, email) {
|
||||
'x-api-user': user._id,
|
||||
'x-api-key': user.apiToken,
|
||||
},
|
||||
}
|
||||
).catch((err) => {
|
||||
},
|
||||
).catch(err => {
|
||||
console.log(err.response.data);
|
||||
});
|
||||
|
||||
@@ -57,14 +59,15 @@ async function _deleteHabiticaData (user, email) {
|
||||
}
|
||||
}
|
||||
|
||||
async function _processEmailAddress (email) {
|
||||
async function processEmailAddress (email) {
|
||||
const emailRegex = new RegExp(`^${email}$`, 'i');
|
||||
const users = await User.find({
|
||||
$or: [
|
||||
{'auth.local.email': emailRegex},
|
||||
{'auth.facebook.emails.value': emailRegex},
|
||||
{'auth.google.emails.value': emailRegex},
|
||||
]},
|
||||
{ 'auth.local.email': emailRegex },
|
||||
{ 'auth.facebook.emails.value': emailRegex },
|
||||
{ 'auth.google.emails.value': emailRegex },
|
||||
],
|
||||
},
|
||||
{
|
||||
_id: 1,
|
||||
apiToken: 1,
|
||||
@@ -75,14 +78,14 @@ async function _processEmailAddress (email) {
|
||||
console.log(`No users found with email address ${email}`);
|
||||
} else {
|
||||
for (const user of users) {
|
||||
await _deleteAmplitudeData(user._id, email); // eslint-disable-line no-await-in-loop
|
||||
await _deleteHabiticaData(user, email); // eslint-disable-line no-await-in-loop
|
||||
await deleteAmplitudeData(user._id, email); // eslint-disable-line no-await-in-loop
|
||||
await deleteHabiticaData(user, email); // eslint-disable-line no-await-in-loop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function deleteUserData (emails) {
|
||||
const emailPromises = emails.map(_processEmailAddress);
|
||||
const emailPromises = emails.map(processEmailAddress);
|
||||
return Promise.all(emailPromises);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,11 +12,12 @@ const nconf = require('nconf');
|
||||
const _ = require('lodash');
|
||||
const paypal = require('paypal-rest-sdk');
|
||||
const blocks = require('../website/common').content.subscriptionBlocks;
|
||||
|
||||
const live = nconf.get('PAYPAL_MODE') === 'live';
|
||||
|
||||
nconf.argv().env().file('user', path.join(path.resolve(__dirname, '../config.json')));
|
||||
|
||||
let OP = 'create'; // list get update create create-webprofile
|
||||
const OP = 'create'; // list get update create create-webprofile
|
||||
|
||||
paypal.configure({
|
||||
mode: nconf.get('PAYPAL_MODE'), // sandbox or live
|
||||
@@ -25,8 +26,8 @@ paypal.configure({
|
||||
});
|
||||
|
||||
// https://developer.paypal.com/docs/api/#billing-plans-and-agreements
|
||||
let billingPlanTitle = 'Habitica Subscription';
|
||||
let billingPlanAttributes = {
|
||||
const billingPlanTitle = 'Habitica Subscription';
|
||||
const billingPlanAttributes = {
|
||||
description: billingPlanTitle,
|
||||
type: 'INFINITE',
|
||||
merchant_preferences: {
|
||||
@@ -41,7 +42,7 @@ let billingPlanAttributes = {
|
||||
}],
|
||||
};
|
||||
|
||||
_.each(blocks, (block) => {
|
||||
_.each(blocks, block => {
|
||||
block.definition = _.cloneDeep(billingPlanAttributes);
|
||||
_.merge(block.definition.payment_definitions[0], {
|
||||
name: `${billingPlanTitle} ($${block.price} every ${block.months} months, recurring)`,
|
||||
@@ -57,17 +58,17 @@ _.each(blocks, (block) => {
|
||||
|
||||
switch (OP) {
|
||||
case 'list':
|
||||
paypal.billingPlan.list({status: 'ACTIVE'}, (err, plans) => {
|
||||
console.log({err, plans});
|
||||
paypal.billingPlan.list({ status: 'ACTIVE' }, (err, plans) => {
|
||||
console.log({ err, plans });
|
||||
});
|
||||
break;
|
||||
case 'get':
|
||||
paypal.billingPlan.get(nconf.get('PAYPAL_BILLING_PLANS_basic_12mo'), (err, plan) => {
|
||||
console.log({err, plan});
|
||||
console.log({ err, plan });
|
||||
});
|
||||
break;
|
||||
case 'update':
|
||||
let updatePayload = {
|
||||
const updatePayload = {
|
||||
op: 'replace',
|
||||
path: '/merchant_preferences',
|
||||
value: {
|
||||
@@ -75,7 +76,7 @@ switch (OP) {
|
||||
},
|
||||
};
|
||||
paypal.billingPlan.update(nconf.get('PAYPAL_BILLING_PLANS_basic_12mo'), updatePayload, (err, res) => {
|
||||
console.log({err, plan: res});
|
||||
console.log({ err, plan: res });
|
||||
});
|
||||
break;
|
||||
case 'create':
|
||||
@@ -83,10 +84,10 @@ switch (OP) {
|
||||
if (err) return console.log(err);
|
||||
|
||||
if (plan.state === 'ACTIVE') {
|
||||
return console.log({err, plan});
|
||||
return console.log({ err, plan });
|
||||
}
|
||||
|
||||
let billingPlanUpdateAttributes = [{
|
||||
const billingPlanUpdateAttributes = [{
|
||||
op: 'replace',
|
||||
path: '/',
|
||||
value: {
|
||||
@@ -96,12 +97,12 @@ switch (OP) {
|
||||
|
||||
// Activate the plan by changing status to Active
|
||||
paypal.billingPlan.update(plan.id, billingPlanUpdateAttributes, (err2, response) => {
|
||||
console.log({err: err2, response, id: plan.id});
|
||||
console.log({ err: err2, response, id: plan.id });
|
||||
});
|
||||
});
|
||||
break;
|
||||
case 'create-webprofile':
|
||||
let webexpinfo = {
|
||||
const webexpinfo = {
|
||||
name: 'HabiticaProfile',
|
||||
input_fields: {
|
||||
no_shipping: 1,
|
||||
|
||||
Reference in New Issue
Block a user