Add display on user profile when user commits

This commit is contained in:
Berkeley Martinez
2015-10-06 14:54:59 -07:00
parent c8da944caf
commit 362efd4365
3 changed files with 39 additions and 17 deletions

View File

@ -19,6 +19,18 @@ import {
const sendNonUserToFront = ifNoUserRedirectTo('/'); const sendNonUserToFront = ifNoUserRedirectTo('/');
const debug = debugFactory('freecc:commit'); const debug = debugFactory('freecc:commit');
function findNonprofit(name) {
let nonprofit;
if (name) {
nonprofit = _.find(nonprofits, (nonprofit) => {
return name === nonprofit.name;
});
}
nonprofit = nonprofit || nonprofits[0];
return nonprofit;
}
export default function commit(app) { export default function commit(app) {
const router = app.loopback.Router(); const router = app.loopback.Router();
const { Pledge } = app.models; const { Pledge } = app.models;
@ -38,16 +50,9 @@ export default function commit(app) {
function commitToNonprofit(req, res) { function commitToNonprofit(req, res) {
let nonprofitName = unDasherize(req.query.nonprofit); let nonprofitName = unDasherize(req.query.nonprofit);
let nonprofit; const nonprofit = findNonprofit(nonprofitName);
debug('looking for nonprofit', nonprofitName); debug('looking for nonprofit', nonprofitName);
if (nonprofitName) {
nonprofit = _.find(nonprofits, (nonprofit) => {
return nonprofitName === nonprofit.name;
});
}
nonprofit = nonprofit || nonprofits[0];
res.render( res.render(
'commit/', 'commit/',
@ -61,20 +66,26 @@ export default function commit(app) {
function pledge(req, res, next) { function pledge(req, res, next) {
const { user } = req; const { user } = req;
const { const {
nonprofit = 'girl develop it', nonprofit: nonprofitName = 'girl develop it',
amount = '5', amount = '5',
goal = 'Front End Development Certification' goal = 'Front End Development Certification'
} = req.query; } = req.query;
const nonprofit = findNonprofit(nonprofitName);
observeQuery(user, 'pledge') observeQuery(user, 'pledge')
.flatMap(oldPledge => { .flatMap(oldPledge => {
// create new pledge for user // create new pledge for user
const pledge = Pledge({ const pledge = Pledge(
nonprofit, Object.assign(
amount, {
goal, amount,
userId: user.id goal,
}); userId: user.id
},
nonprofit
)
);
if (oldPledge) { if (oldPledge) {
debug('user already has pledge, creating a new one'); debug('user already has pledge, creating a new one');

View File

@ -164,7 +164,10 @@ module.exports = function(app) {
const username = req.params.username.toLowerCase(); const username = req.params.username.toLowerCase();
const { path } = req; const { path } = req;
User.findOne( User.findOne(
{ where: { username } }, {
where: { username },
include: 'pledge'
},
function(err, profileUser) { function(err, profileUser) {
if (err) { if (err) {
return next(err); return next(err);
@ -175,6 +178,7 @@ module.exports = function(app) {
}); });
return res.redirect('/'); return res.redirect('/');
} }
profileUser = profileUser.toJSON();
var cals = profileUser var cals = profileUser
.progressTimestamps .progressTimestamps
@ -217,7 +221,6 @@ module.exports = function(app) {
return (obj.name || '').match(/^Waypoint/i); return (obj.name || '').match(/^Waypoint/i);
}); });
debug('user is fec', profileUser.isFrontEndCert);
res.render('account/show', { res.render('account/show', {
title: 'Camper ' + profileUser.username + '\'s portfolio', title: 'Camper ' + profileUser.username + '\'s portfolio',
username: profileUser.username, username: profileUser.username,
@ -227,6 +230,8 @@ module.exports = function(app) {
isGithubCool: profileUser.isGithubCool, isGithubCool: profileUser.isGithubCool,
isLocked: !!profileUser.isLocked, isLocked: !!profileUser.isLocked,
pledge: profileUser.pledge,
isFrontEndCert: profileUser.isFrontEndCert, isFrontEndCert: profileUser.isFrontEndCert,
isFullStackCert: profileUser.isFullStackCert, isFullStackCert: profileUser.isFullStackCert,
isHonest: profileUser.isHonest, isHonest: profileUser.isHonest,

View File

@ -58,6 +58,12 @@ block content
h1.flat-top.wrappable= name h1.flat-top.wrappable= name
h1.flat-top.wrappable= location h1.flat-top.wrappable= location
h1.flat-top.text-primary= "[ " + (progressTimestamps.length) + " ]" h1.flat-top.text-primary= "[ " + (progressTimestamps.length) + " ]"
if pledge
.spacer
h4 I am commited to giving $#{pledge.amount} to
a(href='#{pledge.donate}') #{pledge.displayName}
| each month until I have complete the #{pledge.goal}
.spacer
if isFrontEndCert if isFrontEndCert
a.btn.btn-primary(href='/' + username + '/front-end-certification') View My Front End Development Certification a.btn.btn-primary(href='/' + username + '/front-end-certification') View My Front End Development Certification
if isFullStackCert if isFullStackCert