chore: commit lint fixes for the api

This commit is contained in:
Bouncey
2019-02-06 14:19:58 +00:00
committed by mrugesh mohapatra
parent 010fa63e76
commit 07266b7e43
17 changed files with 159 additions and 154 deletions

View File

@ -7,5 +7,5 @@ export function dayCount([head, tail], timezone = 'UTC') {
moment(tail).tz(timezone).startOf('day'),
'days',
true)
);
);
}

View File

@ -1,4 +1,3 @@
function getCompletedCertCount(user) {
return [
'isApisMicroservicesCert',
@ -7,46 +6,48 @@ function getCompletedCertCount(user) {
'isInfosecQaCert',
'isJsAlgoDataStructCert',
'isRespWebDesignCert'
].reduce((sum, key) => user[key] ? sum + 1 : sum, 0);
].reduce((sum, key) => (user[key] ? sum + 1 : sum), 0);
}
function getLegacyCertCount(user) {
return [
'isFrontEndCert',
'isBackEndCert',
'isDataVisCert'
].reduce((sum, key) => user[key] ? sum + 1 : sum, 0);
return ['isFrontEndCert', 'isBackEndCert', 'isDataVisCert'].reduce(
(sum, key) => (user[key] ? sum + 1 : sum),
0
);
}
export default function populateUser(db, user) {
return new Promise((resolve, reject) => {
let populatedUser = {...user};
let populatedUser = { ...user };
db.collection('user')
.aggregate([
{ $match: { _id: user.id } },
{ $project: { points: { $size: '$progressTimestamps' } } }
]).get(function(err, [{ points = 1 } = {}]) {
if (err) { return reject(err); }
user.points = points;
let completedChallengeCount = 0;
let completedProjectCount = 0;
if ('completedChallenges' in user) {
completedChallengeCount = user.completedChallenges.length;
user.completedChallenges.forEach(item => {
if (
'challengeType' in item &&
(item.challengeType === 3 || item.challengeType === 4)
) {
completedProjectCount++;
}
});
}
populatedUser.completedChallengeCount = completedChallengeCount;
populatedUser.completedProjectCount = completedProjectCount;
populatedUser.completedCertCount = getCompletedCertCount(user);
populatedUser.completedLegacyCertCount = getLegacyCertCount(user);
populatedUser.completedChallenges = [];
return resolve(populatedUser);
});
.aggregate([
{ $match: { _id: user.id } },
{ $project: { points: { $size: '$progressTimestamps' } } },
])
.get(function(err, [{ points = 1 } = {}]) {
if (err) {
return reject(err);
}
user.points = points;
let completedChallengeCount = 0;
let completedProjectCount = 0;
if ('completedChallenges' in user) {
completedChallengeCount = user.completedChallenges.length;
user.completedChallenges.forEach(item => {
if (
'challengeType' in item &&
(item.challengeType === 3 || item.challengeType === 4)
) {
completedProjectCount++;
}
});
}
populatedUser.completedChallengeCount = completedChallengeCount;
populatedUser.completedProjectCount = completedProjectCount;
populatedUser.completedCertCount = getCompletedCertCount(user);
populatedUser.completedLegacyCertCount = getLegacyCertCount(user);
populatedUser.completedChallenges = [];
return resolve(populatedUser);
});
});
}

View File

@ -2,25 +2,25 @@ exports.dasherize = function dasherize(name) {
return ('' + name)
.toLowerCase()
.replace(/\s/g, '-')
.replace(/[^a-z0-9\-\.]/gi, '')
.replace(/\:/g, '');
}
.replace(/[^a-z0-9\-.]/gi, '')
.replace(/:/g, '');
};
exports.nameify = function nameify(str) {
return ('' + str)
.replace(/[^a-zA-Z0-9\s]/g, '')
.replace(/\:/g, '');
}
return ('' + str).replace(/[^a-zA-Z0-9\s]/g, '').replace(/:/g, '');
};
exports.unDasherize = function unDasherize(name) {
return ('' + name)
// replace dash with space
.replace(/\-/g, ' ')
// strip nonalphanumarics chars except whitespace
.replace(/[^a-zA-Z\d\s]/g, '')
.trim();
}
return (
('' + name)
// replace dash with space
.replace(/-/g, ' ')
// strip nonalphanumarics chars except whitespace
.replace(/[^a-zA-Z\d\s]/g, '')
.trim()
);
};
exports.addPlaceholderImage = function addPlaceholderImage(name) {
return `https://identicon.org?t=${name}&s=256`;
}
};

View File

@ -69,7 +69,7 @@ export function getProgress(progressTimestamps, timezone = 'EST') {
.reduce((data, timestamp) => {
data[Math.floor(timestamp / 1000)] = 1;
return data;
}, {});
}, {});
const uniqueHours = prepUniqueDaysByHours(progressTimestamps, timezone);
const streak = {
longest: calcLongestStreak(uniqueHours, timezone),

View File

@ -25,7 +25,7 @@ export function getHost() {
export function getServerFullURL() {
if (!isDev) {
return getProtocol()
return getProtocol()
+ '://'
+ getHost();
}