From 44a957faca3629cc0b8ec52b49baaff3a50dcf55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 23 Oct 2018 22:28:37 -0400 Subject: [PATCH] remove more parseints --- src/categories/data.js | 2 -- src/categories/index.js | 28 ++++++++++------------------ src/controllers/category.js | 2 +- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/categories/data.js b/src/categories/data.js index a752c16f99..349ef4c788 100644 --- a/src/categories/data.js +++ b/src/categories/data.js @@ -89,12 +89,10 @@ function modifyCategory(category) { } if (category.hasOwnProperty('post_count')) { - category.post_count = category.post_count || 0; category.totalPostCount = category.post_count; } if (category.hasOwnProperty('topic_count')) { - category.topic_count = category.topic_count || 0; category.totalTopicCount = category.topic_count; } diff --git a/src/categories/index.js b/src/categories/index.js index 083a4797e3..062fd2a6bf 100644 --- a/src/categories/index.js +++ b/src/categories/index.js @@ -146,7 +146,7 @@ Categories.getCategories = function (cids, uid, callback) { category.children = results.children[i]; category.parent = results.parents[i] || undefined; category.tagWhitelist = results.tagWhitelist[i]; - category['unread-class'] = (parseInt(category.topic_count, 10) === 0 || (results.hasRead[i] && uid !== 0)) ? '' : 'unread'; + category['unread-class'] = (category.topic_count === 0 || (results.hasRead[i] && uid !== 0)) ? '' : 'unread'; calculateTopicPostCount(category); } }); @@ -168,8 +168,8 @@ function calculateTopicPostCount(category) { return; } - var postCount = parseInt(category.post_count, 10) || 0; - var topicCount = parseInt(category.topic_count, 10) || 0; + var postCount = category.post_count; + var topicCount = category.topic_count; if (!Array.isArray(category.children) || !category.children.length) { category.totalPostCount = postCount; category.totalTopicCount = topicCount; @@ -196,21 +196,17 @@ Categories.getParents = function (cids, callback) { function (_categoriesData, next) { categoriesData = _categoriesData; - parentCids = categoriesData.filter(function (category) { - return category && category.hasOwnProperty('parentCid') && parseInt(category.parentCid, 10); - }).map(function (category) { - return parseInt(category.parentCid, 10); - }); + parentCids = categoriesData.filter(c => c && c.parentCid).map(c => c.parentCid); if (!parentCids.length) { - return callback(null, cids.map(function () { return null; })); + return callback(null, cids.map(() => null)); } Categories.getCategoriesData(parentCids, next); }, function (parentData, next) { parentData = categoriesData.map(function (category) { - return parentData[parentCids.indexOf(parseInt(category.parentCid, 10))]; + return parentData[parentCids.indexOf(category.parentCid)]; }); next(null, parentData); }, @@ -253,16 +249,14 @@ function getChildrenRecursive(category, uid, callback) { children = children.filter(Boolean); category.children = children; - var cids = children.map(function (child) { - return child.cid; - }); + var cids = children.map(child => child.cid); Categories.hasReadCategories(cids, uid, next); }, function (hasRead, next) { hasRead.forEach(function (read, i) { var child = category.children[i]; - child['unread-class'] = (parseInt(child.topic_count, 10) === 0 || (read && uid !== 0)) ? '' : 'unread'; + child['unread-class'] = (child.topic_count === 0 || (read && uid !== 0)) ? '' : 'unread'; }); next(); @@ -304,7 +298,7 @@ Categories.getTree = function (categories, parentCid) { category.parentCid = 0; } - if (parseInt(category.parentCid, 10) === parseInt(parentCid, 10)) { + if (category.parentCid === parentCid) { tree.push(category); category.children = Categories.getTree(categories, category.cid); } @@ -341,9 +335,7 @@ Categories.buildForSelectCategories = function (categories, callback) { var categoriesData = []; - categories = categories.filter(function (category) { - return category && !parseInt(category.parentCid, 10); - }); + categories = categories.filter(category => category && !category.parentCid); categories.forEach(function (category) { recursive(category, categoriesData, '', 0); diff --git a/src/controllers/category.js b/src/controllers/category.js index 2bd1806b8c..bc59b9d8a3 100644 --- a/src/controllers/category.js +++ b/src/controllers/category.js @@ -66,7 +66,7 @@ categoryController.get = function (req, res, callback) { settings = results.userSettings; - var topicCount = parseInt(results.categoryData.topic_count, 10); + var topicCount = results.categoryData.topic_count; pageCount = Math.max(1, Math.ceil(topicCount / settings.topicsPerPage)); if (topicIndex < 0 || topicIndex > Math.max(topicCount - 1, 0)) {