Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added message view #8

Merged
merged 1 commit into from
Aug 31, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,19 @@ exports.update = function(req, res){
res.redirect('/profile');
});
};

exports.index = function(req, res){
User.findAll(function(err, users){
res.render('users/index', {users:users});
});
};

exports.trader = function(req, res){
User.findOne({email:req.params.email}, function(err, trader){
if(trader){
res.render('users/trader', {trader:trader});
}else{
res.redirect('/users');
}
});
};
8 changes: 8 additions & 0 deletions app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,13 @@ User.prototype.save = function(o, cb){
User.collection.save(self, cb);
};

User.findAll = function(cb){
User.collection.find().toArray(cb);
};

User.findOne = function(filter, cb){
User.collection.findOne(filter, cb);
};

module.exports = User;

2 changes: 2 additions & 0 deletions app/routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ module.exports = function(app, express){
app.get('/profile/edit', users.edit);
app.put('/profile', users.update);
app.get('/profile', users.profile);
app.get('/users', users.index);
app.get('/users/:email', users.trader);
app.post('/items', items.create);
app.get('/marketplace', items.index);
app.put('/items/:itemId', items.markonsale);
Expand Down
1 change: 1 addition & 0 deletions app/views/shared/nav.jade
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
span Messages
span.badge 0
li: a(href='/profile') Profile
li: a(href='/users') Traders
li
form.navbar-form(method='post', action='/logout')
.form-group
Expand Down
18 changes: 18 additions & 0 deletions app/views/users/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
extends ../shared/template
block content
table.table.table-striped.table-hover
thead
tr
th Name
th Photo
th Email
th Phone Number
body
each user in users
tr
td: a(href='/users/#{user.email}')=user.name
td(style='background-image:url(#{user.photo})')
td= user.email
td= user.phone

block scripts
36 changes: 36 additions & 0 deletions app/views/users/trader.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
extends ../shared/template
block content
.row
.col-xs-12
h2= user.name
.row
.col-xs-3
a.thumbnail(href='#')
img(src=user.photo)
.row
.col-xs-6
table.table.table-striped.table-hover.table-bordered
thead
tr
th Name
th Email
th Phone
body
tr
td= trader.name
td= trader.email
td= trader.phone
.col-xs-12
.panel.panel-default
.panel-body
form(role='form', method='post', action='/message/#{trader._id}')
.row
.col-xs-12
.form-group
label(for='message') Message
textarea.form-control#message(name='message', autofocus=true)
.form-group
button.btn.btn-info.btn-sm(type='submit') Send Message
.col-xs-12

block scripts
26 changes: 26 additions & 0 deletions test/acceptance/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,33 @@ describe('users', function(){
});
});
});

describe('get /users', function(){
it('should show all winos', function(done){
request(app)
.get('/users')
.set('cookie', cookie)
.end(function(err, res){
expect(res.status).to.equal(200);
expect(res.text).to.include('nodeapptest+bob@gmail.com');
done();
});
});
});

describe('get /users/nodeapptest+bob@gmail.com', function(){
it('should show a specific wino', function(done){
request(app)
.get('/users/nodeapptest+bob@gmail.com')
.set('cookie', cookie)
.end(function(err, res){
expect(res.status).to.equal(200);
done();
});
});
});
});




17 changes: 17 additions & 0 deletions test/unit/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ describe('User', function(){
});
});

describe('.find', function(){
it('should find users', function(done){
User.findAll(function(err, users){
expect(users).to.have.length(2);
done();
});
});
});

describe('.findOne', function(){
it('should find a specific user', function(done){
User.findOne({email:'nodeapptest+bob@gmail.com'}, function(err, user){
expect(user.email).to.equal('nodeapptest+bob@gmail.com');
done();
});
});
});
});