Node.js based forum software built for the modern web
feat: allow exists methods to work with arrays and single id
Barış Soner Uşaklı285aa36556b4
diff --git a/src/categories/index.js b/src/categories/index.jsindex c7a1748507..81f98e2009 100644--- a/src/categories/index.js+++ b/src/categories/index.js@@ -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) {diff --git a/src/posts/index.js b/src/posts/index.jsindex aed0d85c90..43dd6674a6 100644--- a/src/posts/index.js+++ b/src/posts/index.js@@ -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) {diff --git a/src/topics/index.js b/src/topics/index.jsindex 2108eaeb6a..6c49995203 100644--- a/src/topics/index.js+++ b/src/topics/index.js@@ -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) {diff --git a/src/user/index.js b/src/user/index.jsindex 70cbb4fa79..e2c807ed04 100644--- a/src/user/index.js+++ b/src/user/index.js@@ -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) {