mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
refactor: use .map to return promises
This commit is contained in:
@@ -136,33 +136,14 @@ define('forum/flags/list', [
|
||||
if (subselector) {
|
||||
const action = subselector.getAttribute('data-action');
|
||||
const flagIds = Flags.getSelected();
|
||||
const promises = [];
|
||||
|
||||
// TODO: this can be better done with flagIds.map to return promises
|
||||
flagIds.forEach(function (flagId) {
|
||||
promises.push(new Promise(function (resolve, reject) {
|
||||
const handler = function (err) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
const promises = flagIds.map((flagId) => {
|
||||
const data = {};
|
||||
if (action === 'bulk-assign') {
|
||||
data.assignee = app.user.uid;
|
||||
} else if (action === 'bulk-mark-resolved') {
|
||||
data.state = 'resolved';
|
||||
}
|
||||
|
||||
resolve(arguments[1]);
|
||||
};
|
||||
|
||||
switch (action) {
|
||||
case 'bulk-assign':
|
||||
api.put(`/flags/${flagId}`, {
|
||||
assignee: app.user.uid,
|
||||
}, handler);
|
||||
break;
|
||||
|
||||
case 'bulk-mark-resolved':
|
||||
api.put(`/flags/${flagId}`, {
|
||||
state: 'resolved',
|
||||
}, handler);
|
||||
break;
|
||||
}
|
||||
}));
|
||||
return api.put(`/flags/${flagId}`, data);
|
||||
});
|
||||
|
||||
Promise.allSettled(promises).then(function (results) {
|
||||
|
||||
Reference in New Issue
Block a user