Skip to content

Node.js based forum software built for the modern web

check if category exists

barisusaklic5e8339abb80
diff --git a/src/socket.io/user/profile.js b/src/socket.io/user/profile.js
index f01bf10426..d966396a30 100644
--- a/src/socket.io/user/profile.js
+++ b/src/socket.io/user/profile.js
@@ -49,7 +49,7 @@ module.exports = function(SocketUser) {
function (_oldUserData, next) {
oldUserData = _oldUserData;
if (!oldUserData || !oldUserData.username) {
- return next(new Error('[[error-invalid-data]]'));
+ return next(new Error('[[error:invalid-data]]'));
}
if (parseInt(meta.config['username:disableEdit'], 10) === 1) {
diff --git a/src/user/categories.js b/src/user/categories.js
index 078d5b761a..612b5ec14e 100644
--- a/src/user/categories.js
+++ b/src/user/categories.js
@@ -3,6 +3,7 @@
var async = require('async');
var db = require('../database');
+var categories = require('../categories');
module.exports = function(User) {
@@ -34,13 +35,35 @@ module.exports = function(User) {
if (!uid) {
return callback();
}
- db.sortedSetAdd('uid:' + uid + ':ignored:cids', Date.now(), cid, callback);
+
+ async.waterfall([
+ function (next) {
+ categories.exists(cid, next);
+ },
+ function (exists, next) {
+ if (!exists) {
+ return next(new Error('[[error:no-category]]'));
+ }
+ db.sortedSetAdd('uid:' + uid + ':ignored:cids', Date.now(), cid, next);
+ }
+ ], callback);
};
User.watchCategory = function(uid, cid, callback) {
if (!uid) {
return callback();
}
- db.sortedSetRemove('uid:' + uid + ':ignored:cids', cid, callback);
+
+ async.waterfall([
+ function (next) {
+ categories.exists(cid, next);
+ },
+ function (exists, next) {
+ if (!exists) {
+ return next(new Error('[[error:no-category]]'));
+ }
+ db.sortedSetRemove('uid:' + uid + ':ignored:cids', cid, next);
+ }
+ ], callback);
};
};
\ No newline at end of file