Skip to content

Commit

Permalink
chore: commit lint fixes for the api
Browse files Browse the repository at this point in the history
  • Loading branch information
Bouncey authored and raisedadead committed Feb 19, 2019
1 parent 010fa63 commit 07266b7
Show file tree
Hide file tree
Showing 17 changed files with 159 additions and 154 deletions.
8 changes: 4 additions & 4 deletions api-server/common/models/User-Identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ export default function(UserIdent) {
return identity
? Observable.of(identity.user())
: User.findOne$({ where: { email } }).flatMap(user => {
return user
? Observable.of(user)
: User.create$({ email }).toPromise();
});
return user
? Observable.of(user)
: User.create$({ email }).toPromise();
});
})
.flatMap(user => {
const createToken = observeQuery(AccessToken, 'create', {
Expand Down
17 changes: 11 additions & 6 deletions api-server/common/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ export function dashify(str) {
return ('' + str)
.toLowerCase()
.replace(/\s/g, '-')
.replace(/[^a-z0-9\-\.]/gi, '')
.replace(/\:/g, '');
.replace(/[^a-z0-9\-.]/gi, '')
.replace(/:/g, '');
}
// todo: unify with server/utils/index.js:dasherize
const dasherize = dashify;
export { dasherize };

export const fixCompletedChallengeItem = obj => pick(
obj,
[ 'id', 'completedDate', 'solution', 'githubLink', 'challengeType', 'files' ]
);
export const fixCompletedChallengeItem = obj =>
pick(obj, [
'id',
'completedDate',
'solution',
'githubLink',
'challengeType',
'files',
]);
64 changes: 32 additions & 32 deletions api-server/server/boot/donate.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export default function donateBoot(app, done) {
name:
'Monthly Donation to freeCodeCamp.org - ' +
`Thank you ($${current / 100})`
},
currency: 'usd',
id: `monthly-donation-${current}`
},
currency: 'usd',
id: `monthly-donation-${current}`
}
}), {}
);
Expand Down Expand Up @@ -59,8 +59,8 @@ export default function donateBoot(app, done) {
throw err;
}
console.log(`${plan.id} created`);
return;
});
return;
});
}

function createStripeDonation(req, res) {
Expand Down Expand Up @@ -104,34 +104,34 @@ export default function donateBoot(app, done) {
email,
card: id
});
})
.then(customer => {
donation.customerId = customer.id;
return stripe.subscriptions.create({
customer: customer.id,
items: [
{
plan: `monthly-donation-${amount}`
}
]
});
})
.then(subscription => {
donation.subscriptionId = subscription.id;
return res.send(subscription);
})
.then(() => {
donatingUser.createDonation(donation).toPromise()
.catch(err => {
throw new Error(err);
})
.then(customer => {
donation.customerId = customer.id;
return stripe.subscriptions.create({
customer: customer.id,
items: [
{
plan: `monthly-donation-${amount}`
}
]
});
})
.catch(err => {
if (err.type === 'StripeCardError') {
return res.status(402).send({ error: err.message });
}
return res.status(500).send({ error: 'Donation Failed' });
});
})
.then(subscription => {
donation.subscriptionId = subscription.id;
return res.send(subscription);
})
.then(() => {
donatingUser.createDonation(donation).toPromise()
.catch(err => {
throw new Error(err);
});
})
.catch(err => {
if (err.type === 'StripeCardError') {
return res.status(402).send({ error: err.message });
}
return res.status(500).send({ error: 'Donation Failed' });
});
}

const pubKey = keys.stripe.public;
Expand Down
8 changes: 4 additions & 4 deletions api-server/server/boot/randomAPIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(
[
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion api-server/server/boot/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function createPostReportUserProfile(app) {
to: 'team@freecodecamp.org',
cc: user.email,
from: 'team@freecodecamp.org',
subject: 'Abuse Report : Reporting ' + username + "'s profile.",
subject: `Abuse Report : Reporting ${username}'s profile.`,
text: dedent(`
Hello Team,\n
This is to report the profile of ${username}.\n
Expand Down
8 changes: 4 additions & 4 deletions api-server/server/middlewares/csp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import helmet from 'helmet';
import { homeLocation } from '../../../config/env';

let trusted = [
"'self'",
'\'self\'',
'https://search.freecodecamp.org',
homeLocation,
'https://' + process.env.AUTH0_DOMAIN
Expand Down Expand Up @@ -31,8 +31,8 @@ export default function csp() {
'https://*.algolia.net'
]),
scriptSrc: [
"'unsafe-eval'",
"'unsafe-inline'",
'\'unsafe-eval\'',
'\'unsafe-inline\'',
'*.google-analytics.com',
'*.gstatic.com',
'https://*.cloudflare.com',
Expand All @@ -48,7 +48,7 @@ export default function csp() {
'*.ytimg.com'
].concat(trusted),
styleSrc: [
"'unsafe-inline'",
'\'unsafe-inline\'',
'*.gstatic.com',
'*.googleapis.com',
'*.bootstrapcdn.com',
Expand Down
18 changes: 9 additions & 9 deletions api-server/server/middlewares/jwt-authorization.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ export default () => function authorizeByJWT(req, res, next) {
if (!req.user) {
const User = loopback.getModelByType('User');
return User.findById(userId)
.then(user => {
if (user) {
user.points = user.progressTimestamps.length;
req.user = user;
}
return;
})
.then(next)
.catch(next);
.then(user => {
if (user) {
user.points = user.progressTimestamps.length;
req.user = user;
}
return;
})
.then(next)
.catch(next);
} else {
return next();
}
Expand Down
54 changes: 27 additions & 27 deletions api-server/server/rss/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,35 @@ class NewsFeed {
const currentFeed = this.state.combinedFeed.slice(0);
log('grabbing feeds');
return Promise.all([
getMediumFeed(),
getLybsynFeed()
]).then(
([mediumFeed, lybsynFeed]) => this.setState(
state => ({
...state,
mediumFeed,
lybsynFeed
getMediumFeed(),
getLybsynFeed()
]).then(
([mediumFeed, lybsynFeed]) => this.setState(
state => ({
...state,
mediumFeed,
lybsynFeed
})
))
.then(() => {
log('crossing the streams');
const { mediumFeed, lybsynFeed} = this.state;
const combinedFeed = [ ...mediumFeed, ...lybsynFeed ].sort((a, b) => {
return compareDesc(a.isoDate, b.isoDate);
});
this.setState(state => ({
...state,
combinedFeed,
readyState: true
}));
})
))
.then(() => {
log('crossing the streams');
const { mediumFeed, lybsynFeed} = this.state;
const combinedFeed = [ ...mediumFeed, ...lybsynFeed ].sort((a, b) => {
return compareDesc(a.isoDate, b.isoDate);
.catch(err => {
console.log(err);
this.setState(state => ({
...state,
combinedFeed: currentFeed
}));
});
this.setState(state => ({
...state,
combinedFeed,
readyState: true
}));
})
.catch(err => {
console.log(err);
this.setState(state => ({
...state,
combinedFeed: currentFeed
}));
});
}


Expand Down
12 changes: 6 additions & 6 deletions api-server/server/rss/lybsyn.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export function getLybsynFeed() {
])
)
/* eslint-disable camelcase */
.map(({ full_item_url, item_title, release_date, item_body_short}) => ({
title: item_title,
extract: item_body_short,
isoDate: new Date(release_date).toISOString(),
link: full_item_url
}));
.map(({ full_item_url, item_title, release_date, item_body_short}) => ({
title: item_title,
extract: item_body_short,
isoDate: new Date(release_date).toISOString(),
link: full_item_url
}));
/* eslint-enable camelcase */
return resolve(items);
});
Expand Down
2 changes: 1 addition & 1 deletion api-server/server/rss/medium.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function getExtract(str) {


function addResponsiveClass(str) {
return str.replace(/\<img/g, '<img class="img-responsive"');
return str.replace(/<img/g, '<img class="img-responsive"');
}

export function getMediumFeed() {
Expand Down
12 changes: 6 additions & 6 deletions api-server/server/services/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export default function getChallengesForBlock(app) {
return {
name: 'challenge',
read: function readChallengesForBlock(
req,
resource,
{ dashedName, blockName} = {},
config,
cb
) {
req,
resource,
{ dashedName, blockName} = {},
config,
cb
) {
const getChallengeBlock$ = challengeMap
.flatMap(({
result: { superBlocks },
Expand Down
3 changes: 1 addition & 2 deletions api-server/server/services/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export default function userServices() {
config,
cb) {
const queryUser = req.user;
console.log(queryUser.completedChallengeCount)
const source = queryUser && Observable.forkJoin(
queryUser.getCompletedChallenges$(),
queryUser.getPoints$(),
Expand Down Expand Up @@ -63,7 +62,7 @@ export default function userServices() {
result: user.username
})
)
)
)
.subscribe(
user => cb(null, user),
cb
Expand Down
2 changes: 1 addition & 1 deletion api-server/server/utils/date-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export function dayCount([head, tail], timezone = 'UTC') {
moment(tail).tz(timezone).startOf('day'),
'days',
true)
);
);
}
Loading

0 comments on commit 07266b7

Please sign in to comment.