mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
remove more parseInts
This commit is contained in:
@@ -9,7 +9,7 @@ var privileges = require('../../privileges');
|
|||||||
var privilegesController = module.exports;
|
var privilegesController = module.exports;
|
||||||
|
|
||||||
privilegesController.get = function (req, res, callback) {
|
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([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
async.parallel({
|
async.parallel({
|
||||||
@@ -38,7 +38,7 @@ privilegesController.get = function (req, res, callback) {
|
|||||||
function (data) {
|
function (data) {
|
||||||
data.allCategories.forEach(function (category) {
|
data.allCategories.forEach(function (category) {
|
||||||
if (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);
|
categories.getCategoriesFields(cids, ['cid', 'name', 'slug', 'icon', 'link', 'color', 'bgColor', 'parentCid', 'image', 'imageClass'], next);
|
||||||
},
|
},
|
||||||
function (categoryData, next) {
|
function (categoryData, next) {
|
||||||
categoryData = categoryData.filter(function (category) {
|
categoryData = categoryData.filter(category => category && !category.link);
|
||||||
return category && !category.link;
|
|
||||||
});
|
|
||||||
var selectedCategory = [];
|
var selectedCategory = [];
|
||||||
var selectedCids = [];
|
var selectedCids = [];
|
||||||
categoryData.forEach(function (category) {
|
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;
|
category.parentCid = category.hasOwnProperty('parentCid') && utils.isNumber(category.parentCid) ? category.parentCid : 0;
|
||||||
if (category.selected) {
|
if (category.selected) {
|
||||||
selectedCategory.push(category);
|
selectedCategory.push(category);
|
||||||
selectedCids.push(parseInt(category.cid, 10));
|
selectedCids.push(category.cid);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
selectedCids.sort(function (a, b) {
|
selectedCids.sort((a, b) => a - b);
|
||||||
return a - b;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (selectedCategory.length > 1) {
|
if (selectedCategory.length > 1) {
|
||||||
selectedCategory = {
|
selectedCategory = {
|
||||||
|
|||||||
@@ -86,10 +86,7 @@ events.getEvents = function (filter, start, stop, callback) {
|
|||||||
db.getSortedSetRevRange('events:time' + (filter ? ':' + filter : ''), start, stop, next);
|
db.getSortedSetRevRange('events:time' + (filter ? ':' + filter : ''), start, stop, next);
|
||||||
},
|
},
|
||||||
function (eids, next) {
|
function (eids, next) {
|
||||||
var keys = eids.map(function (eid) {
|
db.getObjects(eids.map(eid => 'event:' + eid), next);
|
||||||
return 'event:' + eid;
|
|
||||||
});
|
|
||||||
db.getObjects(keys, next);
|
|
||||||
},
|
},
|
||||||
function (eventsData, next) {
|
function (eventsData, next) {
|
||||||
eventsData = eventsData.filter(Boolean);
|
eventsData = eventsData.filter(Boolean);
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ module.exports = function (Topics) {
|
|||||||
|
|
||||||
Topics.movePostToTopic = function (callerUid, pid, tid, callback) {
|
Topics.movePostToTopic = function (callerUid, pid, tid, callback) {
|
||||||
var postData;
|
var postData;
|
||||||
|
tid = parseInt(tid, 10);
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
Topics.exists(tid, next);
|
Topics.exists(tid, next);
|
||||||
@@ -94,7 +95,7 @@ module.exports = function (Topics) {
|
|||||||
return next(new Error('[[error:no-post]]'));
|
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]]'));
|
return next(new Error('[[error:cant-move-to-same-topic]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,10 +144,10 @@ module.exports = function (Topics) {
|
|||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
var tasks = [];
|
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));
|
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));
|
tasks.push(async.apply(db.sortedSetIncrBy, 'cid:' + topicData[1].cid + ':tids:posts', 1, toTid));
|
||||||
} else {
|
} else {
|
||||||
next();
|
next();
|
||||||
@@ -156,7 +157,7 @@ module.exports = function (Topics) {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
if (parseInt(topicData[0].cid, 10) === parseInt(topicData[1].cid, 10)) {
|
if (topicData[0].cid === topicData[1].cid) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -202,8 +202,8 @@ module.exports = function (Topics) {
|
|||||||
Topics.getLatestUndeletedReply(tid, next);
|
Topics.getLatestUndeletedReply(tid, next);
|
||||||
},
|
},
|
||||||
function (pid, next) {
|
function (pid, next) {
|
||||||
if (parseInt(pid, 10)) {
|
if (pid) {
|
||||||
return callback(null, pid.toString());
|
return callback(null, pid);
|
||||||
}
|
}
|
||||||
Topics.getTopicField(tid, 'mainPid', next);
|
Topics.getTopicField(tid, 'mainPid', next);
|
||||||
},
|
},
|
||||||
@@ -211,7 +211,7 @@ module.exports = function (Topics) {
|
|||||||
posts.getPostFields(mainPid, ['pid', 'deleted'], next);
|
posts.getPostFields(mainPid, ['pid', 'deleted'], next);
|
||||||
},
|
},
|
||||||
function (mainPost, 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);
|
], callback);
|
||||||
};
|
};
|
||||||
@@ -251,7 +251,7 @@ module.exports = function (Topics) {
|
|||||||
return isDeleted && !done;
|
return isDeleted && !done;
|
||||||
},
|
},
|
||||||
function (err) {
|
function (err) {
|
||||||
callback(err, latestPid);
|
callback(err, parseInt(latestPid, 10));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -59,13 +59,13 @@ module.exports = function (Topics) {
|
|||||||
Topics.getLatestUndeletedPid(tid, next);
|
Topics.getLatestUndeletedPid(tid, next);
|
||||||
},
|
},
|
||||||
function (pid, next) {
|
function (pid, next) {
|
||||||
if (!parseInt(pid, 10)) {
|
if (!pid) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
posts.getPostField(pid, 'timestamp', next);
|
posts.getPostField(pid, 'timestamp', next);
|
||||||
},
|
},
|
||||||
function (timestamp, next) {
|
function (timestamp, next) {
|
||||||
if (!parseInt(timestamp, 10)) {
|
if (!timestamp) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
Topics.updateLastPostTime(tid, timestamp, next);
|
Topics.updateLastPostTime(tid, timestamp, next);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ var search = require('../search');
|
|||||||
module.exports = function (Topics) {
|
module.exports = function (Topics) {
|
||||||
Topics.getSuggestedTopics = function (tid, uid, start, stop, callback) {
|
Topics.getSuggestedTopics = function (tid, uid, start, stop, callback) {
|
||||||
var tids;
|
var tids;
|
||||||
|
tid = parseInt(tid, 10);
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
async.parallel({
|
async.parallel({
|
||||||
@@ -23,9 +24,7 @@ module.exports = function (Topics) {
|
|||||||
},
|
},
|
||||||
function (results, next) {
|
function (results, next) {
|
||||||
tids = results.tagTids.concat(results.searchTids);
|
tids = results.tagTids.concat(results.searchTids);
|
||||||
tids = tids.filter(function (_tid) {
|
tids = tids.filter(_tid => _tid !== tid);
|
||||||
return parseInt(_tid, 10) !== parseInt(tid, 10);
|
|
||||||
});
|
|
||||||
tids = _.shuffle(_.uniq(tids));
|
tids = _.shuffle(_.uniq(tids));
|
||||||
|
|
||||||
if (stop !== -1 && tids.length < stop - start + 1) {
|
if (stop !== -1 && tids.length < stop - start + 1) {
|
||||||
@@ -78,9 +77,7 @@ module.exports = function (Topics) {
|
|||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (data, next) {
|
function (data, next) {
|
||||||
var tids = data.posts.map(function (post) {
|
var tids = data.posts.map(post => post && post.tid);
|
||||||
return post && parseInt(post.tid, 10);
|
|
||||||
});
|
|
||||||
next(null, tids);
|
next(null, tids);
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
@@ -96,10 +93,8 @@ module.exports = function (Topics) {
|
|||||||
},
|
},
|
||||||
function (data, next) {
|
function (data, next) {
|
||||||
var tids = data.topics.filter(function (topic) {
|
var tids = data.topics.filter(function (topic) {
|
||||||
return topic && !topic.deleted && parseInt(tid, 10) !== parseInt(topic.tid, 10);
|
return topic && !topic.deleted && tid !== topic.tid;
|
||||||
}).map(function (topic) {
|
}).map(topic => topic && topic.tid);
|
||||||
return topic && parseInt(topic.tid, 10);
|
|
||||||
});
|
|
||||||
next(null, tids);
|
next(null, tids);
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
|
|||||||
@@ -212,9 +212,7 @@ module.exports = function (Topics) {
|
|||||||
Topics.getTopicsFields(tids, ['cid'], next);
|
Topics.getTopicsFields(tids, ['cid'], next);
|
||||||
},
|
},
|
||||||
function (topicData, next) {
|
function (topicData, next) {
|
||||||
var uniqueCids = _.uniq(topicData.map(function (topicData) {
|
var uniqueCids = _.uniq(topicData.map(topicData => topicData && topicData.cid));
|
||||||
return topicData && parseInt(topicData.cid, 10);
|
|
||||||
}));
|
|
||||||
|
|
||||||
if (uniqueCids.length > 1 || !uniqueCids.length || !uniqueCids[0]) {
|
if (uniqueCids.length > 1 || !uniqueCids.length || !uniqueCids[0]) {
|
||||||
return next(new Error('[[error:invalid-data]]'));
|
return next(new Error('[[error:invalid-data]]'));
|
||||||
|
|||||||
@@ -685,7 +685,7 @@ describe('Topic\'s', function () {
|
|||||||
var topic;
|
var topic;
|
||||||
var i;
|
var i;
|
||||||
for (i = 0; i < topics.length; i += 1) {
|
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');
|
assert.equal(false, topics[i].unread, 'ignored topic was marked as unread in recent list');
|
||||||
return done();
|
return done();
|
||||||
}
|
}
|
||||||
@@ -1384,7 +1384,7 @@ describe('Topic\'s', function () {
|
|||||||
topics.getUnreadTids({ cid: 0, uid: adminUid }, next);
|
topics.getUnreadTids({ cid: 0, uid: adminUid }, next);
|
||||||
},
|
},
|
||||||
function (unreadTids, next) {
|
function (unreadTids, next) {
|
||||||
assert(!unreadTids.includes(parseInt(topic.tid, 10)));
|
assert(!unreadTids.includes(topic.tid));
|
||||||
User.blocks.remove(blockedUid, adminUid, next);
|
User.blocks.remove(blockedUid, adminUid, next);
|
||||||
},
|
},
|
||||||
], done);
|
], done);
|
||||||
|
|||||||
Reference in New Issue
Block a user