check if category exists

v1.18.x
barisusakli 9 years ago
parent 872080d832
commit c5e8339abb

@ -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) {

@ -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);
};
};
Loading…
Cancel
Save