remove more parseInts

v1.18.x
Barış Soner Uşaklı 7 years ago
parent a228dc2de9
commit 537b7ff7e8

@ -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;
}
});

@ -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 = {

@ -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);

@ -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();
}

@ -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));
}
);
};

@ -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);

@ -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);

@ -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]]'));

@ -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);

Loading…
Cancel
Save