mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 08:25:46 +01:00
feat: allow exists methods to work with arrays and single id
This commit is contained in:
@@ -23,11 +23,10 @@ require('./update')(Categories);
|
||||
require('./watch')(Categories);
|
||||
require('./search')(Categories);
|
||||
|
||||
Categories.exists = async function (cid) {
|
||||
if (Array.isArray(cid)) {
|
||||
return await db.exists(cid.map(cid => `category:${cid}`));
|
||||
}
|
||||
return await db.exists(`category:${cid}`);
|
||||
Categories.exists = async function (cids) {
|
||||
return await db.exists(
|
||||
Array.isArray(cids) ? cids.map(cid => `category:${cid}`) : `category:${cids}`
|
||||
);
|
||||
};
|
||||
|
||||
Categories.getCategoryById = async function (data) {
|
||||
|
||||
@@ -28,10 +28,9 @@ require('./diffs')(Posts);
|
||||
require('./uploads')(Posts);
|
||||
|
||||
Posts.exists = async function (pids) {
|
||||
const isArray = Array.isArray(pids);
|
||||
pids = isArray ? pids : [pids];
|
||||
const exists = await db.exists(pids.map(pid => `post:${pid}`));
|
||||
return isArray ? exists : exists[0];
|
||||
return await db.exists(
|
||||
Array.isArray(pids) ? pids.map(pid => `post:${pid}`) : `post:${pids}`
|
||||
);
|
||||
};
|
||||
|
||||
Posts.getPidsFromSet = async function (set, start, stop, reverse) {
|
||||
|
||||
@@ -35,8 +35,10 @@ require('./bookmarks')(Topics);
|
||||
require('./merge')(Topics);
|
||||
Topics.events = require('./events');
|
||||
|
||||
Topics.exists = async function (tid) {
|
||||
return await db.exists(`topic:${tid}`);
|
||||
Topics.exists = async function (tids) {
|
||||
return await db.exists(
|
||||
Array.isArray(tids) ? tids.map(tid => `topic:${tid}`) : `topic:${tids}`
|
||||
);
|
||||
};
|
||||
|
||||
Topics.getTopicsFromSet = async function (set, uid, start, stop) {
|
||||
|
||||
@@ -40,8 +40,12 @@ require('./online')(User);
|
||||
require('./blocks')(User);
|
||||
require('./uploads')(User);
|
||||
|
||||
User.exists = async function (uid) {
|
||||
return await db.isSortedSetMember('users:joindate', uid);
|
||||
User.exists = async function (uids) {
|
||||
return await (
|
||||
Array.isArray(uids) ?
|
||||
db.isSortedSetMembers('users:joindate', uids) :
|
||||
db.isSortedSetMember('users:joindate', uids)
|
||||
);
|
||||
};
|
||||
|
||||
User.existsBySlug = async function (userslug) {
|
||||
|
||||
Reference in New Issue
Block a user