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