From c5e8339abb80a3f4e23d3bd11384b4767e2f365a Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 2 Oct 2015 17:01:07 -0400 Subject: [PATCH] check if category exists --- src/socket.io/user/profile.js | 2 +- src/user/categories.js | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) 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