feat: Use prettier-eslint to format code

This commit is contained in:
Bouncey
2019-02-18 19:32:49 +00:00
committed by mrugesh mohapatra
parent 1ba67c4e2b
commit b13e5fb41a
82 changed files with 1767 additions and 1017 deletions

View File

@ -350,9 +350,8 @@ function createShowCert(app) {
messages: [
{
type: 'info',
message: `We could not find a user with the username "${
username
}"`
message:
'We could not find a user with the username "' + username + '"'
}
]
});

View File

@ -321,7 +321,7 @@ export default async function bootChallenge(app, done) {
) {
req.flash(
'danger',
'You haven\'t supplied the necessary URLs for us to inspect your work.'
"You haven't supplied the necessary URLs for us to inspect your work."
);
return res.sendStatus(403);
}

View File

@ -6,23 +6,13 @@ import dedent from 'dedent';
import { homeLocation } from '../../../config/env';
import nonprofits from '../utils/commit.json';
import {
commitGoals,
completeCommitment$
} from '../utils/commit';
import { commitGoals, completeCommitment$ } from '../utils/commit';
import {
unDasherize
} from '../utils';
import { unDasherize } from '../utils';
import {
observeQuery,
saveInstance
} from '../utils/rx';
import { observeQuery, saveInstance } from '../utils/rx';
import {
ifNoUserRedirectTo
} from '../utils/middleware';
import { ifNoUserRedirectTo } from '../utils/middleware';
const sendNonUserToSignIn = ifNoUserRedirectTo(
`${homeLocation}/signin`,
@ -41,12 +31,12 @@ const debug = debugFactory('fcc:commit');
function findNonprofit(name) {
let nonprofit;
if (name) {
nonprofit = _.find(nonprofits, (nonprofit) => {
nonprofit = _.find(nonprofits, nonprofit => {
return name === nonprofit.name;
});
}
nonprofit = nonprofit || nonprofits[ _.random(0, nonprofits.length - 1) ];
nonprofit = nonprofit || nonprofits[_.random(0, nonprofits.length - 1)];
return nonprofit;
}
@ -55,33 +45,15 @@ export default function commit(app) {
const api = app.loopback.Router();
const { Pledge } = app.models;
router.get(
'/commit',
commitToNonprofit
);
router.get('/commit', commitToNonprofit);
router.get(
'/commit/pledge',
sendNonUserToSignIn,
pledge
);
router.get('/commit/pledge', sendNonUserToSignIn, pledge);
router.get(
'/commit/directory',
renderDirectory
);
router.get('/commit/directory', renderDirectory);
api.post(
'/commit/stop-commitment',
sendNonUserToCommit,
stopCommit
);
api.post('/commit/stop-commitment', sendNonUserToCommit, stopCommit);
api.post(
'/commit/complete-goal',
sendNonUserToCommit,
completeCommitment
);
api.post('/commit/complete-goal', sendNonUserToCommit, completeCommitment);
app.use(api);
app.use(router);
@ -101,33 +73,26 @@ export default function commit(app) {
}
return Observable.just();
})
.subscribe(
pledge => {
if (pledge) {
debug('found previous pledge');
req.flash(
'info',
dedent`
.subscribe(pledge => {
if (pledge) {
debug('found previous pledge');
req.flash(
'info',
dedent`
Looks like you already have a pledge to ${pledge.displayName}.
Clicking "Commit" here will replace your old commitment. If you
do change your commitment, please remember to cancel your
previous recurring donation directly with ${pledge.displayName}.
`
);
}
res.render(
'commit/',
{
title: 'Commit to a nonprofit. Commit to your goal.',
pledge,
...commitGoals,
...nonprofit
}
);
},
next
);
}
res.render('commit/', {
title: 'Commit to a nonprofit. Commit to your goal.',
pledge,
...commitGoals,
...nonprofit
});
}, next);
}
function pledge(req, res, next) {
@ -143,14 +108,12 @@ export default function commit(app) {
observeQuery(user, 'pledge')
.flatMap(oldPledge => {
// create new pledge for user
const pledge = Pledge(
{
amount,
goal,
userId: user.id,
...nonprofit
}
);
const pledge = Pledge({
amount,
goal,
userId: user.id,
...nonprofit
});
if (oldPledge) {
debug('user already has pledge, creating a new one');
@ -159,28 +122,24 @@ export default function commit(app) {
oldPledge.formerUser = user.id;
oldPledge.endDate = new Date();
oldPledge.isOrphaned = true;
return saveInstance(oldPledge)
.flatMap(() => {
return saveInstance(pledge);
});
return saveInstance(oldPledge).flatMap(() => {
return saveInstance(pledge);
});
}
return saveInstance(pledge);
})
.subscribe(
({ displayName, goal, amount }) => {
req.flash(
'success',
dedent`
.subscribe(({ displayName, goal, amount }) => {
req.flash(
'success',
dedent`
Congratulations, you have committed to giving
${displayName} $${amount} each month until you have completed
your ${goal}. Please remember to cancel your pledge directly
with ${displayName} once you finish.
`
);
res.redirect('/' + user.username);
},
next
);
);
res.redirect('/' + user.username);
}, next);
}
function renderDirectory(req, res) {
@ -193,16 +152,12 @@ export default function commit(app) {
function completeCommitment(req, res, next) {
const { user } = req;
return completeCommitment$(user)
.subscribe(
msgOrPledge => {
if (typeof msgOrPledge === 'string') {
return res.send(msgOrPledge);
}
return res.send(true);
},
next
);
return completeCommitment$(user).subscribe(msgOrPledge => {
if (typeof msgOrPledge === 'string') {
return res.send(msgOrPledge);
}
return res.send(true);
}, next);
}
function stopCommit(req, res, next) {
@ -220,23 +175,20 @@ export default function commit(app) {
pledge.dateEnded = new Date();
return saveInstance(pledge);
})
.subscribe(
pledge => {
let msg = dedent`
.subscribe(pledge => {
let msg = dedent`
You have successfully stopped your pledge. Please
remember to cancel your recurring donation directly
with the nonprofit if you haven't already done so.
`;
if (!pledge) {
msg = dedent`
if (!pledge) {
msg = dedent`
It doesn't look like you had an active pledge, so
there's no pledge to stop.
`;
}
req.flash('info', msg);
return res.redirect(`/${user.username}`);
},
next
);
}
req.flash('info', msg);
return res.redirect(`/${user.username}`);
}, next);
}
}

View File

@ -6,7 +6,6 @@ import keys from '../../../config/secrets';
const log = debug('fcc:boot:donate');
export default function donateBoot(app, done) {
let stripe = false;
const { User } = app.models;
const api = app.loopback.Router();
@ -25,7 +24,8 @@ export default function donateBoot(app, done) {
currency: 'usd',
id: `monthly-donation-${current}`
}
}), {}
}),
{}
);
function connectToStripe() {
@ -70,23 +70,26 @@ export default function donateBoot(app, done) {
return res.status(400).send({ error: 'Amount Required' });
}
const { amount, token: {email, id} } = body;
const {
amount,
token: { email, id }
} = body;
const fccUser = user ?
Promise.resolve(user) :
new Promise((resolve, reject) =>
User.findOrCreate(
{ where: { email }},
{ email },
(err, instance, isNew) => {
log('is new user instance: ', isNew);
if (err) {
return reject(err);
}
return resolve(instance);
}
)
);
const fccUser = user
? Promise.resolve(user)
: new Promise((resolve, reject) =>
User.findOrCreate(
{ where: { email } },
{ email },
(err, instance, isNew) => {
log('is new user instance: ', isNew);
if (err) {
return reject(err);
}
return resolve(instance);
}
)
);
let donatingUser = {};
let donation = {
@ -96,14 +99,13 @@ export default function donateBoot(app, done) {
startDate: new Date(Date.now()).toISOString()
};
return fccUser.then(
user => {
return fccUser
.then(user => {
donatingUser = user;
return stripe.customers
.create({
email,
card: id
});
return stripe.customers.create({
email,
card: id
});
})
.then(customer => {
donation.customerId = customer.id;
@ -121,7 +123,9 @@ export default function donateBoot(app, done) {
return res.send(subscription);
})
.then(() => {
donatingUser.createDonation(donation).toPromise()
donatingUser
.createDonation(donation)
.toPromise()
.catch(err => {
throw new Error(err);
});

View File

@ -15,7 +15,7 @@ module.exports = function mountLoopBackExplorer(app) {
app.once('started', function() {
log(
'Run `npm install loopback-component-explorer` to enable ' +
'the LoopBack explorer'
'the LoopBack explorer'
);
});
return;

View File

@ -32,9 +32,7 @@ function createShortLinkHandler(app) {
if (!article) {
return res.redirect('/news');
}
const {
slugPart
} = article;
const { slugPart } = article;
const slug = `/news/${slugPart}`;
return res.redirect(slug);
}

View File

@ -88,7 +88,7 @@ module.exports = function(app) {
.then(() => {
req.flash(
'success',
'We\'ve successfully updated your email preferences.'
"We've successfully updated your email preferences."
);
return res.redirectWithFlash(
`${homeLocation}/unsubscribed/${unsubscribeId}`
@ -144,7 +144,7 @@ module.exports = function(app) {
.then(() => {
req.flash(
'success',
'We\'ve successfully updated your email preferences. Thank you ' +
"We've successfully updated your email preferences. Thank you " +
'for resubscribing.'
);
return res.redirectWithFlash(homeLocation);
@ -175,7 +175,7 @@ module.exports = function(app) {
}
pulls = pulls
? Object.keys(JSON.parse(pulls)).length
: 'Can\'t connect to github';
: "Can't connect to github";
return request(
[
@ -193,7 +193,7 @@ module.exports = function(app) {
issues =
pulls === parseInt(pulls, 10) && issues
? Object.keys(JSON.parse(issues)).length - pulls
: 'Can\'t connect to GitHub';
: "Can't connect to GitHub";
return res.send({
issues: issues,
pulls: pulls

View File

@ -1,6 +1,6 @@
export default function bootStatus(app) {
const api = app.loopback.Router();
api.get('/status/ping', (req, res) => res.json({msg: 'pong'}));
api.get('/status/ping', (req, res) => res.json({ msg: 'pong' }));
app.use(api);
}

View File

@ -5,8 +5,6 @@ module.exports = function(app) {
app.use(router);
function showForum(req, res) {
res.redirect(
'http://forum.freecodecamp.org/'
);
res.redirect('http://forum.freecodecamp.org/');
}
};

View File

@ -219,8 +219,7 @@ function createPostReportUserProfile(app) {
if (!username || !report || report === '') {
return res.json({
type: 'danger',
message:
'Oops, something is not right please re-check your submission.'
message: 'Oops, something is not right please re-check your submission.'
});
}
return Email.send$(