Skip to content

Commit

Permalink
accept/deny bids
Browse files Browse the repository at this point in the history
  • Loading branch information
Melanie Fryman committed Sep 2, 2014
1 parent 70a5ec1 commit fb0859d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/controllers/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ exports.accept = function(req, res){
});
});
};

exports.deny = function(req, res){
Bid.destroy(req.params.bidId, function(){
res.redirect('/dashboard');
});
};
7 changes: 6 additions & 1 deletion app/models/bid.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ Bid.findById = function(id, cb){
Bid.collection.findOne({_id:_id}, cb);
};

Bid.destroy = function(id, cb){
var _id = Mongo.ObjectID(id);
Bid.collection.findAndRemove({_id:_id}, cb);
};

Bid.getBids = function(itemForBidId, cb){
Bid.collection.find({itemForBidId:itemForBidId, isOpen:true}).toArray(function(err, bids){
if(bids.length){
Expand All @@ -58,7 +63,7 @@ Bid.getBids = function(itemForBidId, cb){
};

Bid.accept = function(bid, cb){
require('./item').collection.findAndModify({_id:bid.bItem}, {}, {$set: {ownerId:bid.seller}}, function(err1, sItem){
require('./item').collection.findAndModify({_id:bid.bItem}, {}, {$set: {ownerId:bid.seller, isAvailable:true}}, function(err1, sItem){
require('./item').collection.findAndModify({_id:bid.sItem}, {}, {$set: {ownerId:bid.bidder}}, function(err2, bItem){
Bid.collection.findAndRemove({_id:bid._id}, cb);
});
Expand Down
3 changes: 2 additions & 1 deletion app/routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ module.exports = function(app, express){
app.get('/messages', users.displayMessages);

// Items
app.get('/items/new', items.new);
app.get('/items/:itemId', items.show);
app.delete('/items/:itemId', items.delete);
app.get('/items/new', items.new);
app.post('/items', items.save);
app.get('/browse', items.browse);
app.post('/items/bid', items.bid);
app.post('/accept/:bidId', items.accept);
app.post('/deny/:bidId', items.deny);
console.log('Express: Routes Loaded');
};

10 changes: 8 additions & 2 deletions app/views/users/dashboard.jade
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ block content
td
form(action='/items/#{item._id}', method='POST', onsubmit="return confirm('Are you sure you want to delete item?')")
input(type='hidden', name='_method', value='delete')
button.alert.del-but x
button.alert.btn-danger.btn-mini(type='submit')
span.glyphicon.glyphicon-trash
.row
h3 Dibs
.col-xs-12.user-item-list
Expand Down Expand Up @@ -93,5 +94,10 @@ block content
td= moment(bid.date).format('MM/DD/YYYY')
td
form(action='/accept/#{bid._id}', method='POST')
button.btn.btn-success(type='submit') Accept
button.btn.btn-default.btn-mini(type='submit')
span.glyphicon.glyphicon-thumbs-up
td
form(action='/deny/#{bid._id}', method='POST')
button.btn.btn-default.btn-mini(type='submit')
span.glyphicon.glyphicon-thumbs-down
block scripts

0 comments on commit fb0859d

Please sign in to comment.