|
|
|
@ -1,3 +1,6 @@
|
|
|
|
|
(function () {
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
var async = require('async'),
|
|
|
|
|
User = require('./user'),
|
|
|
|
|
RDB = RDB || require('./redis'),
|
|
|
|
@ -11,11 +14,16 @@ var async = require('async'),
|
|
|
|
|
}, next);
|
|
|
|
|
}, function (err, groups) {
|
|
|
|
|
callback(err, groups.filter(function (group) {
|
|
|
|
|
if (group.deleted === '1') return false;
|
|
|
|
|
else return true;
|
|
|
|
|
if (group.deleted === '1') {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
});
|
|
|
|
|
} else callback(null, []);
|
|
|
|
|
} else {
|
|
|
|
|
callback(null, []);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
get: function (gid, options, callback) {
|
|
|
|
@ -26,18 +34,24 @@ var async = require('async'),
|
|
|
|
|
users: function (next) {
|
|
|
|
|
RDB.smembers('gid:' + gid + ':members', function (err, uids) {
|
|
|
|
|
if (options.expand) {
|
|
|
|
|
if (err) return next(err);
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async.map(uids, function (uid, next) {
|
|
|
|
|
User.getUserData(uid, next);
|
|
|
|
|
}, function (err, users) {
|
|
|
|
|
next(err, users);
|
|
|
|
|
});
|
|
|
|
|
} else next(err, uids);
|
|
|
|
|
} else {
|
|
|
|
|
next(err, uids);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, function (err, results) {
|
|
|
|
|
if (err) return callback(err);
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
results.base.count = results.users.length;
|
|
|
|
|
results.base.members = results.users;
|
|
|
|
@ -55,7 +69,9 @@ var async = require('async'),
|
|
|
|
|
RDB.hexists('group:gid', name, callback);
|
|
|
|
|
},
|
|
|
|
|
create: function (name, description, callback) {
|
|
|
|
|
if (name.length === 0) return callback(new Error('name-too-short'));
|
|
|
|
|
if (name.length === 0) {
|
|
|
|
|
return callback(new Error('name-too-short'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Groups.exists(name, function (err, exists) {
|
|
|
|
|
if (!exists) {
|
|
|
|
@ -72,13 +88,18 @@ var async = require('async'),
|
|
|
|
|
Groups.get(gid, {}, callback);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else callback(new Error('group-exists'))
|
|
|
|
|
} else {
|
|
|
|
|
callback(new Error('group-exists'));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
update: function (gid, values, callback) {
|
|
|
|
|
RDB.exists('gid:' + gid, function (err, exists) {
|
|
|
|
|
if (!err && exists) RDB.hmset('gid:' + gid, values, callback);
|
|
|
|
|
else calback(new Error('gid-not-found'));
|
|
|
|
|
if (!err && exists) {
|
|
|
|
|
RDB.hmset('gid:' + gid, values, callback);
|
|
|
|
|
} else {
|
|
|
|
|
callback(new Error('gid-not-found'));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
destroy: function (gid, callback) {
|
|
|
|
@ -93,3 +114,4 @@ var async = require('async'),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = Groups;
|
|
|
|
|
}());
|