Skip to content

Instantly share code, notes, and snippets.

@Michaela-Davis
Created June 29, 2017 18:03
Show Gist options
  • Save Michaela-Davis/f35fcd7cb292d59efaacf4758ca3decf to your computer and use it in GitHub Desktop.
Save Michaela-Davis/f35fcd7cb292d59efaacf4758ca3decf to your computer and use it in GitHub Desktop.
using .reduce
'use strict';
const https = require('https');
const superagent = require('superagent');
module.exports = {
index
}
function index(req, res, next) {
let users = [];
superagent.get(`https://git.soliddigital.com/api/v3/users?per_page=200&active=true`)
.set('PRIVATE-TOKEN', 'their API that I took out for safety')
.then(usersResponse => {
let users = usersResponse.body;
let vals = users.reduce((obj, user) => {
user.avatar_url ?
obj.avatars.push(user.avatar_url) :
console.log("user.avatar_url not found");
user.name ?
obj.names.push(user.name) :
console.log("user.name not found");
return obj;
}, {
names: [],
avatars: []
});
res.render('users/users.index.pug', {
title: 'Merge Requests Project',
numberOfUsers: users.length,
users: vals.users,
avatars: vals.avatars
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment