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('./watch')(Categories);
|
||||||
require('./search')(Categories);
|
require('./search')(Categories);
|
||||||
|
|
||||||
Categories.exists = async function (cid) {
|
Categories.exists = async function (cids) {
|
||||||
if (Array.isArray(cid)) {
|
return await db.exists(
|
||||||
return await db.exists(cid.map(cid => `category:${cid}`));
|
Array.isArray(cids) ? cids.map(cid => `category:${cid}`) : `category:${cids}`
|
||||||
}
|
);
|
||||||
return await db.exists(`category:${cid}`);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Categories.getCategoryById = async function (data) {
|
Categories.getCategoryById = async function (data) {
|
||||||
|
|||||||
@@ -28,10 +28,9 @@ require('./diffs')(Posts);
|
|||||||
require('./uploads')(Posts);
|
require('./uploads')(Posts);
|
||||||
|
|
||||||
Posts.exists = async function (pids) {
|
Posts.exists = async function (pids) {
|
||||||
const isArray = Array.isArray(pids);
|
return await db.exists(
|
||||||
pids = isArray ? pids : [pids];
|
Array.isArray(pids) ? pids.map(pid => `post:${pid}`) : `post:${pids}`
|
||||||
const exists = await db.exists(pids.map(pid => `post:${pid}`));
|
);
|
||||||
return isArray ? exists : exists[0];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Posts.getPidsFromSet = async function (set, start, stop, reverse) {
|
Posts.getPidsFromSet = async function (set, start, stop, reverse) {
|
||||||
|
|||||||
@@ -35,8 +35,10 @@ require('./bookmarks')(Topics);
|
|||||||
require('./merge')(Topics);
|
require('./merge')(Topics);
|
||||||
Topics.events = require('./events');
|
Topics.events = require('./events');
|
||||||
|
|
||||||
Topics.exists = async function (tid) {
|
Topics.exists = async function (tids) {
|
||||||
return await db.exists(`topic:${tid}`);
|
return await db.exists(
|
||||||
|
Array.isArray(tids) ? tids.map(tid => `topic:${tid}`) : `topic:${tids}`
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.getTopicsFromSet = async function (set, uid, start, stop) {
|
Topics.getTopicsFromSet = async function (set, uid, start, stop) {
|
||||||
|
|||||||
@@ -40,8 +40,12 @@ require('./online')(User);
|
|||||||
require('./blocks')(User);
|
require('./blocks')(User);
|
||||||
require('./uploads')(User);
|
require('./uploads')(User);
|
||||||
|
|
||||||
User.exists = async function (uid) {
|
User.exists = async function (uids) {
|
||||||
return await db.isSortedSetMember('users:joindate', uid);
|
return await (
|
||||||
|
Array.isArray(uids) ?
|
||||||
|
db.isSortedSetMembers('users:joindate', uids) :
|
||||||
|
db.isSortedSetMember('users:joindate', uids)
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
User.existsBySlug = async function (userslug) {
|
User.existsBySlug = async function (userslug) {
|
||||||
|
|||||||
Reference in New Issue
Block a user