refactor: api module returns promise, error-first cb if cb passed in

no more separate onSuccess onError callbacks

/cc @baris
This commit is contained in:
Julian Lam
2020-10-14 10:02:02 -04:00
parent d52992de1b
commit a784d10fff
16 changed files with 103 additions and 133 deletions

View File

@@ -106,13 +106,14 @@ define('forum/groups/details', [
break;
case 'join': // intentional fall-throughs!
api.put('/groups/' + ajaxify.data.group.slug + '/membership/' + (uid || app.user.uid), undefined, () => ajaxify.refresh(), 'default');
api.put('/groups/' + ajaxify.data.group.slug + '/membership/' + (uid || app.user.uid), undefined).then(() => ajaxify.refresh());
break;
case 'leave':
api.del('/groups/' + ajaxify.data.group.slug + '/membership/' + (uid || app.user.uid), undefined, () => ajaxify.refresh(), 'default');
api.del('/groups/' + ajaxify.data.group.slug + '/membership/' + (uid || app.user.uid), undefined).then(() => ajaxify.refresh());
break;
// TODO (14/10/2020): rewrite these to use api module and merge with above 2 case blocks
case 'accept': // intentional fall-throughs!
case 'reject':
case 'issueInvite':

View File

@@ -14,9 +14,9 @@ define('forum/groups/list', [
if (name && name.length) {
api.post('/groups', {
name: name,
}, (res) => {
}).then((res) => {
ajaxify.go('groups/' + res.slug);
}, 'default');
});
}
});
});

View File

@@ -82,13 +82,7 @@ define('forum/groups/memberlist', ['api'], function (api) {
if (groupName === 'administrators') {
socket.emit('admin.user.makeAdmins', uids, done);
} else {
var requests = uids.map(function (uid) {
return api.put('/groups/' + ajaxify.data.group.slug + '/membership/' + uid);
});
$.when(requests)
.done(done)
.fail('default');
Promise.all(uids.map(uid => api.put('/groups/' + ajaxify.data.group.slug + '/membership/' + uid))).then(done);
}
}