Created
June 29, 2017 18:03
-
-
Save Michaela-Davis/f35fcd7cb292d59efaacf4758ca3decf to your computer and use it in GitHub Desktop.
using .reduce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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