add groupIds to user object

This commit is contained in:
girish@cloudron.io
2016-02-08 20:38:50 -08:00
parent 14fab0992f
commit 0d4f113d7d
3 changed files with 32 additions and 1 deletions

View File

@@ -11,6 +11,8 @@ exports = module.exports = {
removeMember: removeMember,
isMember: isMember,
getGroups: getGroups,
_clear: clear
};
@@ -91,6 +93,15 @@ function getMembers(groupId, callback) {
});
}
function getGroups(userId, callback) {
database.query('SELECT userId FROM groupMembers WHERE userId=?', [ userId ], function (error, result) {
if (error) return callback(new DatabaseError(DatabaseError.INTERNAL_ERROR, error));
// if (result.length === 0) return callback(new DatabaseError(DatabaseError.NOT_FOUND)); // need to differentiate group with no members and invalid groupId
callback(error, result.map(function (r) { return r.groupId; }));
});
}
function addMember(groupId, userId, callback) {
assert.strictEqual(typeof groupId, 'string');
assert.strictEqual(typeof userId, 'string');