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 bid page/need to finish bid post #9

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 7 additions & 1 deletion app/controllers/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ exports.index = function(req, res){
});
};

exports.markonsale = function(req, res){
exports.markOnSale = function(req, res){
Item.markOnSale(req.params.itemId, function(){
res.redirect('/profile');
});
};

exports.itemBidPage= function(req, res){
Item.findTradeAndBiddableItems(req.params.itemId, res.locals.user._id, function(err,item, biddableItems){
res.render('items/show-bid', {item:item, biddableItems:biddableItems});
});
}

10 changes: 9 additions & 1 deletion app/models/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function Item(o){
this.tags = o.tags.split(',').map(function(s){return s.trim();});
this.photo = o.photo;
this.ownerId = o.ownerId;
this.isBiddable = false;
this.isBiddable = true;
this.onSale = false;
this.datePosted = new Date();
}
Expand Down Expand Up @@ -50,6 +50,14 @@ Item.markOnSale = function(itemId, cb){
Item.collection.update({_id:_id}, {$set: {onSale: true}}, cb);
};

Item.findTradeAndBiddableItems = function(itemId, userId, cb){
Item.findById(itemId, function(err, itemForTrade){
Item.collection.find({ownerId:userId, isBiddable: true}).toArray(function(err, bidItems){
cb(null, itemForTrade, bidItems);
});
});
};

module.exports = Item;

function getNumberOfBids(item, 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 @@ -36,7 +36,8 @@ module.exports = function(app, express){
app.get('/profile', users.profile);
app.post('/items', items.create);
app.get('/marketplace', items.index);
app.put('/items/:itemId', items.markonsale);
app.put('/items/:itemId', items.markOnSale);
app.get('/bid/:itemId', items.itemBidPage);

console.log('Express: Routes Loaded');
};
Expand Down
10 changes: 10 additions & 0 deletions db/bids.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@
"offerOwnerId" : {"$oid":"000000000000000000000002"},
"isOpen" : true
}
{
"_id" : {"$oid":"b00000000000000000000002"},
"itemUpForBidId" : {"$oid":"a00000000000000000000002"},
"itemOfferedId" : {"$oid":"a00000000000000000000004"},
"upForBidOwnerId" : {"$oid":"000000000000000000000001"},
"offerOwnerId" : {"$oid":"000000000000000000000002"},
"isOpen" : true
}


45 changes: 45 additions & 0 deletions db/items.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,54 @@
"description" : "Wine that is kinda red, kinda white",
"tags" : ["rose", "wine"],
"ownerId" : {"$oid":"000000000000000000000002"},
"isBiddable" : false,
"onSale" : false,
"photo" : "http://www.calliopewines.com/img/wines/2010-rose-bottle-large.jpg",
"datePosted" : {"$date":477295200000}
}
{
"_id" : {"$oid":"a00000000000000000000004"},
"name" : "Green Wine",
"location" : "Nashville, TN, USA",
"lat" : 36.166667,
"lng" : -85.78333299999997,
"description" : "Wine that is green",
"tags" : ["green", "wine"],
"ownerId" : {"$oid":"000000000000000000000002"},
"isBiddable" : false,
"onSale" : false,
"photo" : "http://www.calliopewines.com/img/wines/2010-rose-bottle-large.jpg",
"datePosted" : {"$date":477295200000}
}
{
"_id" : {"$oid":"a00000000000000000000005"},
"name" : "Blue Wine",
"location" : "Nashville, TN, USA",
"lat" : 36.166667,
"lng" : -85.78333299999997,
"description" : "Wine that is blue",
"tags" : ["blue", "wine"],
"ownerId" : {"$oid":"000000000000000000000002"},
"isBiddable" : true,
"onSale" : false,
"photo" : "http://www.calliopewines.com/img/wines/2010-rose-bottle-large.jpg",
"datePosted" : {"$date":477295200000}
}
{
"_id" : {"$oid":"a00000000000000000000006"},
"name" : "Orange Wine",
"location" : "Nashville, TN, USA",
"lat" : 36.166667,
"lng" : -85.78333299999997,
"description" : "Wine that is orange",
"tags" : ["blue", "wine"],
"ownerId" : {"$oid":"000000000000000000000002"},
"isBiddable" : false,
"onSale" : true,
"photo" : "http://www.calliopewines.com/img/wines/2010-rose-bottle-large.jpg",
"datePosted" : {"$date":477295200000}
}




13 changes: 13 additions & 0 deletions test/acceptance/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,18 @@ describe('users', function(){
});
});

describe('get /bid/:itemId', function(){
it('should display the bid page for a specific item', function(done){
request(app)
.get('/bid/a00000000000000000000006')
.set('cookie', cookie)
.end(function(err, res){
expect(res.status).to.equal(200);
expect(res.text).to.include('Orange Wine');
done();
});
});
});

});

16 changes: 14 additions & 2 deletions test/unit/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('Item', function(){
var id = Mongo.ObjectID('000000000000000000000001');
Item.findAllForUser(id, function(err, items){
expect(items).to.have.length(2);
expect(items[1].numBids).to.equal(1);
expect(items[1].numBids).to.equal(2);
done();
});
});
Expand All @@ -65,7 +65,7 @@ describe('Item', function(){
describe('.findForSale', function(){
it('should find items in database that are for sale based on query parameters', function(done){
Item.findForSale({}, function(err, items){
expect(items).to.have.length(1);
expect(items).to.have.length(2);
expect(items[0].name).to.equal('White Wine');
done();
});
Expand All @@ -83,5 +83,17 @@ describe('Item', function(){
});
});

describe('.findTradeAndBiddableItems', function(){
it('should find an item up for trade and also all biddable items of current user', function(done){
var userId = Mongo.ObjectID('000000000000000000000002');
Item.findTradeAndBiddableItems('a00000000000000000000002',userId, function(err, item, biddableItems){
expect(item.onSale).to.be.true;
expect(item.name).to.equal('White Wine');
expect(biddableItems).to.have.length(1);
done();
});
});
});

});