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) {
|
if (subselector) {
|
||||||
const action = subselector.getAttribute('data-action');
|
const action = subselector.getAttribute('data-action');
|
||||||
const flagIds = Flags.getSelected();
|
const flagIds = Flags.getSelected();
|
||||||
const promises = [];
|
const promises = flagIds.map((flagId) => {
|
||||||
|
const data = {};
|
||||||
// TODO: this can be better done with flagIds.map to return promises
|
if (action === 'bulk-assign') {
|
||||||
flagIds.forEach(function (flagId) {
|
data.assignee = app.user.uid;
|
||||||
promises.push(new Promise(function (resolve, reject) {
|
} else if (action === 'bulk-mark-resolved') {
|
||||||
const handler = function (err) {
|
data.state = 'resolved';
|
||||||
if (err) {
|
}
|
||||||
reject(err);
|
return api.put(`/flags/${flagId}`, data);
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Promise.allSettled(promises).then(function (results) {
|
Promise.allSettled(promises).then(function (results) {
|
||||||
|
|||||||
Reference in New Issue
Block a user