Skip to content

Node.js based forum software built for the modern web

refactor: use .map to return promises

Barış Soner Uşaklıd4f3ee67fa26
diff --git a/public/src/client/flags/list.js b/public/src/client/flags/list.js
index dc942a578d..f2e15cedab 100644
--- a/public/src/client/flags/list.js
+++ b/public/src/client/flags/list.js
@@ -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);
- }
-
- 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;
- }
- }));
+ 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';
+ }
+ return api.put(`/flags/${flagId}`, data);
});
Promise.allSettled(promises).then(function (results) {