mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
remove some more parseInts
This commit is contained in:
@@ -16,7 +16,7 @@ module.exports = function (Categories) {
|
||||
posts.getPostsFields(pids, ['uid'], next);
|
||||
},
|
||||
function (posts, next) {
|
||||
var uids = _.uniq(posts.map(post => post.uid).filter(uid => parseInt(uid, 10)));
|
||||
var uids = _.uniq(posts.map(post => post.uid).filter(uid => uid));
|
||||
|
||||
next(null, uids);
|
||||
},
|
||||
|
||||
@@ -82,26 +82,21 @@ module.exports = function (Categories) {
|
||||
], next);
|
||||
},
|
||||
function (results, next) {
|
||||
async.series([
|
||||
function (next) {
|
||||
if (data.cloneFromCid && parseInt(data.cloneFromCid, 10)) {
|
||||
return Categories.copySettingsFrom(data.cloneFromCid, category.cid, !data.parentCid, next);
|
||||
}
|
||||
if (data.cloneFromCid && parseInt(data.cloneFromCid, 10)) {
|
||||
return Categories.copySettingsFrom(data.cloneFromCid, category.cid, !data.parentCid, next);
|
||||
}
|
||||
|
||||
next();
|
||||
},
|
||||
function (next) {
|
||||
if (data.cloneChildren) {
|
||||
return duplicateCategoriesChildren(category.cid, data.cloneFromCid, data.uid, next);
|
||||
}
|
||||
|
||||
next();
|
||||
},
|
||||
], function (err) {
|
||||
next(err, category);
|
||||
});
|
||||
next(null, category);
|
||||
},
|
||||
function (category, next) {
|
||||
function (_category, next) {
|
||||
category = _category;
|
||||
if (data.cloneChildren) {
|
||||
return duplicateCategoriesChildren(category.cid, data.cloneFromCid, data.uid, next);
|
||||
}
|
||||
|
||||
next();
|
||||
},
|
||||
function (next) {
|
||||
plugins.fireHook('action:category.create', { category: category });
|
||||
next(null, category);
|
||||
},
|
||||
|
||||
@@ -58,9 +58,7 @@ module.exports = function (Categories) {
|
||||
], next);
|
||||
},
|
||||
function (next) {
|
||||
groups.destroy(privileges.privilegeList.map(function (privilege) {
|
||||
return 'cid:' + cid + ':privileges:' + privilege;
|
||||
}), next);
|
||||
groups.destroy(privileges.privilegeList.map(privilege => 'cid:' + cid + ':privileges:' + privilege), next);
|
||||
},
|
||||
], function (err) {
|
||||
callback(err);
|
||||
@@ -82,7 +80,6 @@ module.exports = function (Categories) {
|
||||
function (results, next) {
|
||||
async.parallel([
|
||||
function (next) {
|
||||
results.parentCid = parseInt(results.parentCid, 10) || 0;
|
||||
db.sortedSetRemove('cid:' + results.parentCid + ':children', cid, next);
|
||||
},
|
||||
function (next) {
|
||||
|
||||
@@ -69,7 +69,7 @@ module.exports = function (Categories) {
|
||||
posts.getPostField(pid, 'tid', next);
|
||||
},
|
||||
function (tid, next) {
|
||||
if (!parseInt(tid, 10)) {
|
||||
if (!tid) {
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -85,9 +85,7 @@ module.exports = function (Categories) {
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
var keys = categoryData.map(function (category) {
|
||||
return 'cid:' + category.cid + ':recent_tids';
|
||||
});
|
||||
var keys = categoryData.map(category => 'cid:' + category.cid + ':recent_tids');
|
||||
db.getSortedSetsMembers(keys, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -154,12 +152,9 @@ module.exports = function (Categories) {
|
||||
|
||||
function assignTopicsToCategories(categories, topics) {
|
||||
categories.forEach(function (category) {
|
||||
category.posts = topics.filter(function (topic) {
|
||||
return topic.cid && (parseInt(topic.cid, 10) === parseInt(category.cid, 10) ||
|
||||
parseInt(topic.parentCid, 10) === parseInt(category.cid, 10));
|
||||
}).sort(function (a, b) {
|
||||
return b.pid - a.pid;
|
||||
}).slice(0, parseInt(category.numRecentReplies, 10));
|
||||
category.posts = topics.filter(topic => topic.cid && (topic.cid === category.cid || topic.parentCid === category.cid))
|
||||
.sort((a, b) => b.pid - a.pid)
|
||||
.slice(0, parseInt(category.numRecentReplies, 10));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -101,9 +101,7 @@ module.exports = function (Categories) {
|
||||
}
|
||||
},
|
||||
function (normalTids, next) {
|
||||
normalTids = normalTids.filter(function (tid) {
|
||||
return !pinnedTids.includes(tid);
|
||||
});
|
||||
normalTids = normalTids.filter(tid => !pinnedTids.includes(tid));
|
||||
|
||||
next(null, pinnedTids.concat(normalTids));
|
||||
},
|
||||
@@ -150,9 +148,7 @@ module.exports = function (Categories) {
|
||||
|
||||
if (data.tag) {
|
||||
if (Array.isArray(data.tag)) {
|
||||
set = [set].concat(data.tag.map(function (tag) {
|
||||
return 'tag:' + tag + ':topics';
|
||||
}));
|
||||
set = [set].concat(data.tag.map(tag => 'tag:' + tag + ':topics'));
|
||||
} else {
|
||||
set = [set, 'tag:' + data.tag + ':topics'];
|
||||
}
|
||||
@@ -225,7 +221,7 @@ module.exports = function (Categories) {
|
||||
db.incrObjectField('category:' + cid, 'post_count', next);
|
||||
},
|
||||
function (next) {
|
||||
if (parseInt(pinned, 10) === 1) {
|
||||
if (pinned) {
|
||||
return setImmediate(next);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,22 +10,14 @@ module.exports = function (Categories) {
|
||||
if (!Array.isArray(cids) || !cids.length) {
|
||||
return callback();
|
||||
}
|
||||
var keys = cids.map(function (cid) {
|
||||
return 'cid:' + cid + ':read_by_uid';
|
||||
});
|
||||
var keys = cids.map(cid => 'cid:' + cid + ':read_by_uid');
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.isMemberOfSets(keys, uid, next);
|
||||
},
|
||||
function (hasRead, next) {
|
||||
keys = keys.filter(function (key, index) {
|
||||
return !hasRead[index];
|
||||
});
|
||||
|
||||
if (!keys.length) {
|
||||
return callback();
|
||||
}
|
||||
keys = keys.filter((key, index) => !hasRead[index]);
|
||||
|
||||
db.setsAdd(keys, uid, next);
|
||||
},
|
||||
@@ -41,9 +33,7 @@ module.exports = function (Categories) {
|
||||
};
|
||||
|
||||
Categories.hasReadCategories = function (cids, uid, callback) {
|
||||
var sets = cids.map(function (cid) {
|
||||
return 'cid:' + cid + ':read_by_uid';
|
||||
});
|
||||
var sets = cids.map(cid => 'cid:' + cid + ':read_by_uid');
|
||||
|
||||
db.isMemberOfSets(sets, uid, callback);
|
||||
};
|
||||
|
||||
@@ -97,7 +97,6 @@ module.exports = function (Categories) {
|
||||
function (oldParent, next) {
|
||||
async.series([
|
||||
function (next) {
|
||||
oldParent = parseInt(oldParent, 10) || 0;
|
||||
db.sortedSetRemove('cid:' + oldParent + ':children', cid, next);
|
||||
},
|
||||
function (next) {
|
||||
@@ -125,9 +124,7 @@ module.exports = function (Categories) {
|
||||
db.delete('cid:' + cid + ':tag:whitelist', next);
|
||||
},
|
||||
function (next) {
|
||||
var scores = tags.map(function (tag, index) {
|
||||
return index;
|
||||
});
|
||||
var scores = tags.map((tag, index) => index);
|
||||
db.sortedSetAdd('cid:' + cid + ':tag:whitelist', scores, tags, next);
|
||||
},
|
||||
], callback);
|
||||
@@ -144,7 +141,6 @@ module.exports = function (Categories) {
|
||||
db.sortedSetAdd('categories:cid', order, cid, next);
|
||||
},
|
||||
function (next) {
|
||||
parentCid = parseInt(parentCid, 10) || 0;
|
||||
db.sortedSetAdd('cid:' + parentCid + ':children', order, cid, next);
|
||||
},
|
||||
], next);
|
||||
|
||||
@@ -461,6 +461,25 @@ describe('Categories', function () {
|
||||
], done);
|
||||
});
|
||||
|
||||
it('should create category with settings from', function (done) {
|
||||
var child1Cid;
|
||||
var parentCid;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
Categories.create({ name: 'copy from', description: 'copy me' }, next);
|
||||
},
|
||||
function (category, next) {
|
||||
parentCid = category.cid;
|
||||
Categories.create({ name: 'child1', description: 'will be gone', cloneFromCid: parentCid }, next);
|
||||
},
|
||||
function (category, next) {
|
||||
child1Cid = category.cid;
|
||||
assert.equal(category.description, 'copy me');
|
||||
next();
|
||||
},
|
||||
], done);
|
||||
});
|
||||
|
||||
it('should copy settings from', function (done) {
|
||||
var child1Cid;
|
||||
var parentCid;
|
||||
@@ -476,7 +495,7 @@ describe('Categories', function () {
|
||||
child1Cid = category.cid;
|
||||
socketCategories.copySettingsFrom({ uid: adminUid }, { fromCid: parentCid, toCid: child1Cid }, next);
|
||||
},
|
||||
function (canDelete, next) {
|
||||
function (destinationCategory, next) {
|
||||
Categories.getCategoryField(child1Cid, 'description', next);
|
||||
},
|
||||
function (description, next) {
|
||||
|
||||
@@ -60,6 +60,13 @@ describe('Set methods', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not error if keys is empty array', function (done) {
|
||||
db.setsAdd([], 'value', function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSetsMembers()', function () {
|
||||
|
||||
Reference in New Issue
Block a user