refactor: admin groups.join socket async/await

v1.18.x
Julian Lam 6 years ago
parent 7c0cfc33ea
commit 4588a4fdcf

@ -19,22 +19,17 @@ Groups.create = function (socket, data, callback) {
}, callback); }, callback);
}; };
Groups.join = function (socket, data, callback) { Groups.join = async (socket, data) => {
if (!data) { if (!data) {
return callback(new Error('[[error:invalid-data]]')); throw new Error('[[error:invalid-data]]');
} }
async.waterfall([ const isMember = await groups.isMember(data.uid, data.groupName);
function (next) { if (isMember) {
groups.isMember(data.uid, data.groupName, next); throw new Error('[[error:group-already-member]]');
}, }
function (isMember, next) {
if (isMember) { return await groups.join(data.groupName, data.uid);
return next(new Error('[[error:group-already-member]]'));
}
groups.join(data.groupName, data.uid, next);
},
], callback);
}; };
Groups.leave = function (socket, data, callback) { Groups.leave = function (socket, data, callback) {

Loading…
Cancel
Save