Skip to content

Commit

Permalink
refactor: rewrite renderMap as async fn
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlam committed Mar 1, 2022
1 parent b180dc4 commit 558a1ff
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions library.js
Expand Up @@ -17,29 +17,14 @@ function renderAdmin(req, res) {
res.render('admin/plugins/osm-map', {});
}

function renderMap(req, res, next) {
async.waterfall([
async () => db.getSetMembers('osmMap.users'),
function (uids, next) {
user.getUsersWithFields(uids, [
'username', 'userslug', 'picture', 'locationLon', 'locationLat', 'status',
], req.uid, next);
},
function (users, next) {
async.filter(users, (user, callback) => callback(null, user.locationLon && user.locationLat), (err, results) => {
if (err) {
return next(err);
}
next(null, results);
});
},
], (err, users) => {
if (err) {
return next(err);
}

res.render('map', { settings: osmMap._settings, users: users, title: '[[osm-map:map]]' });
});
async function renderMap(req, res) {
const uids = await db.getSetMembers('osmMap.users');
let users = await user.getUsersWithFields(uids, [
'username', 'userslug', 'picture', 'locationLon', 'locationLat', 'status',
], req.uid);

users = users.filter(user => user.locationLon && user.locationLat);
res.render('map', { settings: osmMap._settings, users, title: '[[osm-map:map]]' });
}


Expand Down

0 comments on commit 558a1ff

Please sign in to comment.