diff --git a/src/controllers/admin/privileges.js b/src/controllers/admin/privileges.js index 08bfe3183a..90b50a54f7 100644 --- a/src/controllers/admin/privileges.js +++ b/src/controllers/admin/privileges.js @@ -9,7 +9,7 @@ var privileges = require('../../privileges'); var privilegesController = module.exports; privilegesController.get = function (req, res, callback) { - var cid = req.params.cid ? req.params.cid : 0; + var cid = req.params.cid ? parseInt(req.params.cid, 10) : 0; async.waterfall([ function (next) { async.parallel({ @@ -38,7 +38,7 @@ privilegesController.get = function (req, res, callback) { function (data) { data.allCategories.forEach(function (category) { if (category) { - category.selected = parseInt(category.cid, 10) === parseInt(cid, 10); + category.selected = category.cid === cid; } }); diff --git a/src/controllers/helpers.js b/src/controllers/helpers.js index f482f98b15..71a5fdd9b0 100644 --- a/src/controllers/helpers.js +++ b/src/controllers/helpers.js @@ -262,9 +262,7 @@ function getCategoryData(cids, uid, selectedCid, callback) { categories.getCategoriesFields(cids, ['cid', 'name', 'slug', 'icon', 'link', 'color', 'bgColor', 'parentCid', 'image', 'imageClass'], next); }, function (categoryData, next) { - categoryData = categoryData.filter(function (category) { - return category && !category.link; - }); + categoryData = categoryData.filter(category => category && !category.link); var selectedCategory = []; var selectedCids = []; categoryData.forEach(function (category) { @@ -272,12 +270,10 @@ function getCategoryData(cids, uid, selectedCid, callback) { category.parentCid = category.hasOwnProperty('parentCid') && utils.isNumber(category.parentCid) ? category.parentCid : 0; if (category.selected) { selectedCategory.push(category); - selectedCids.push(parseInt(category.cid, 10)); + selectedCids.push(category.cid); } }); - selectedCids.sort(function (a, b) { - return a - b; - }); + selectedCids.sort((a, b) => a - b); if (selectedCategory.length > 1) { selectedCategory = { diff --git a/src/events.js b/src/events.js index 17c20f6cd1..9d727e8451 100644 --- a/src/events.js +++ b/src/events.js @@ -86,10 +86,7 @@ events.getEvents = function (filter, start, stop, callback) { db.getSortedSetRevRange('events:time' + (filter ? ':' + filter : ''), start, stop, next); }, function (eids, next) { - var keys = eids.map(function (eid) { - return 'event:' + eid; - }); - db.getObjects(keys, next); + db.getObjects(eids.map(eid => 'event:' + eid), next); }, function (eventsData, next) { eventsData = eventsData.filter(Boolean); diff --git a/src/topics/fork.js b/src/topics/fork.js index 5ea1ca1f87..7de56cd789 100644 --- a/src/topics/fork.js +++ b/src/topics/fork.js @@ -79,6 +79,7 @@ module.exports = function (Topics) { Topics.movePostToTopic = function (callerUid, pid, tid, callback) { var postData; + tid = parseInt(tid, 10); async.waterfall([ function (next) { Topics.exists(tid, next); @@ -94,7 +95,7 @@ module.exports = function (Topics) { return next(new Error('[[error:no-post]]')); } - if (parseInt(post.tid, 10) === parseInt(tid, 10)) { + if (post.tid === tid) { return next(new Error('[[error:cant-move-to-same-topic]]')); } @@ -143,10 +144,10 @@ module.exports = function (Topics) { return callback(); } var tasks = []; - if (parseInt(topicData[0].pinned, 10) !== 1) { + if (!topicData[0].pinned) { tasks.push(async.apply(db.sortedSetIncrBy, 'cid:' + topicData[0].cid + ':tids:posts', -1, postData.tid)); } - if (parseInt(topicData[1].pinned, 10) !== 1) { + if (!topicData[1].pinned) { tasks.push(async.apply(db.sortedSetIncrBy, 'cid:' + topicData[1].cid + ':tids:posts', 1, toTid)); } else { next(); @@ -156,7 +157,7 @@ module.exports = function (Topics) { }); }, function (next) { - if (parseInt(topicData[0].cid, 10) === parseInt(topicData[1].cid, 10)) { + if (topicData[0].cid === topicData[1].cid) { return callback(); } diff --git a/src/topics/posts.js b/src/topics/posts.js index de62b79450..aca0cc3516 100644 --- a/src/topics/posts.js +++ b/src/topics/posts.js @@ -202,8 +202,8 @@ module.exports = function (Topics) { Topics.getLatestUndeletedReply(tid, next); }, function (pid, next) { - if (parseInt(pid, 10)) { - return callback(null, pid.toString()); + if (pid) { + return callback(null, pid); } Topics.getTopicField(tid, 'mainPid', next); }, @@ -211,7 +211,7 @@ module.exports = function (Topics) { posts.getPostFields(mainPid, ['pid', 'deleted'], next); }, function (mainPost, next) { - next(null, parseInt(mainPost.pid, 10) && parseInt(mainPost.deleted, 10) !== 1 ? mainPost.pid.toString() : null); + next(null, mainPost.pid && !mainPost.deleted ? mainPost.pid : null); }, ], callback); }; @@ -251,7 +251,7 @@ module.exports = function (Topics) { return isDeleted && !done; }, function (err) { - callback(err, latestPid); + callback(err, parseInt(latestPid, 10)); } ); }; diff --git a/src/topics/recent.js b/src/topics/recent.js index 433a25b1b6..8b62e788a7 100644 --- a/src/topics/recent.js +++ b/src/topics/recent.js @@ -59,13 +59,13 @@ module.exports = function (Topics) { Topics.getLatestUndeletedPid(tid, next); }, function (pid, next) { - if (!parseInt(pid, 10)) { + if (!pid) { return callback(); } posts.getPostField(pid, 'timestamp', next); }, function (timestamp, next) { - if (!parseInt(timestamp, 10)) { + if (!timestamp) { return callback(); } Topics.updateLastPostTime(tid, timestamp, next); diff --git a/src/topics/suggested.js b/src/topics/suggested.js index bb450a759d..29f651346d 100644 --- a/src/topics/suggested.js +++ b/src/topics/suggested.js @@ -10,6 +10,7 @@ var search = require('../search'); module.exports = function (Topics) { Topics.getSuggestedTopics = function (tid, uid, start, stop, callback) { var tids; + tid = parseInt(tid, 10); async.waterfall([ function (next) { async.parallel({ @@ -23,9 +24,7 @@ module.exports = function (Topics) { }, function (results, next) { tids = results.tagTids.concat(results.searchTids); - tids = tids.filter(function (_tid) { - return parseInt(_tid, 10) !== parseInt(tid, 10); - }); + tids = tids.filter(_tid => _tid !== tid); tids = _.shuffle(_.uniq(tids)); if (stop !== -1 && tids.length < stop - start + 1) { @@ -78,9 +77,7 @@ module.exports = function (Topics) { }, next); }, function (data, next) { - var tids = data.posts.map(function (post) { - return post && parseInt(post.tid, 10); - }); + var tids = data.posts.map(post => post && post.tid); next(null, tids); }, ], callback); @@ -96,10 +93,8 @@ module.exports = function (Topics) { }, function (data, next) { var tids = data.topics.filter(function (topic) { - return topic && !topic.deleted && parseInt(tid, 10) !== parseInt(topic.tid, 10); - }).map(function (topic) { - return topic && parseInt(topic.tid, 10); - }); + return topic && !topic.deleted && tid !== topic.tid; + }).map(topic => topic && topic.tid); next(null, tids); }, ], callback); diff --git a/src/topics/tools.js b/src/topics/tools.js index b28b8d12d4..ae727602c8 100644 --- a/src/topics/tools.js +++ b/src/topics/tools.js @@ -212,9 +212,7 @@ module.exports = function (Topics) { Topics.getTopicsFields(tids, ['cid'], next); }, function (topicData, next) { - var uniqueCids = _.uniq(topicData.map(function (topicData) { - return topicData && parseInt(topicData.cid, 10); - })); + var uniqueCids = _.uniq(topicData.map(topicData => topicData && topicData.cid)); if (uniqueCids.length > 1 || !uniqueCids.length || !uniqueCids[0]) { return next(new Error('[[error:invalid-data]]')); diff --git a/test/topics.js b/test/topics.js index 06153cf192..a108415c40 100644 --- a/test/topics.js +++ b/test/topics.js @@ -685,7 +685,7 @@ describe('Topic\'s', function () { var topic; var i; for (i = 0; i < topics.length; i += 1) { - if (parseInt(topics[i].tid, 10) === parseInt(newTid, 10)) { + if (topics[i].tid === parseInt(newTid, 10)) { assert.equal(false, topics[i].unread, 'ignored topic was marked as unread in recent list'); return done(); } @@ -1384,7 +1384,7 @@ describe('Topic\'s', function () { topics.getUnreadTids({ cid: 0, uid: adminUid }, next); }, function (unreadTids, next) { - assert(!unreadTids.includes(parseInt(topic.tid, 10))); + assert(!unreadTids.includes(topic.tid)); User.blocks.remove(blockedUid, adminUid, next); }, ], done);