-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbids.js
More file actions
29 lines (25 loc) · 795 Bytes
/
bids.js
File metadata and controls
29 lines (25 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const db = require('./db');
function Bid(auctionId, productName, userId, bidderName, bidAmount) {
this.auctionId = auctionId;
this.bidAmount = bidAmount;
this.userId = userId;
this.productName = productName;
this.bidderName = bidderName;
//Saving bids for into the db
let length = db.bids.length;
let id = length === 0 ? 1 : db.bids[length - 1].id + 1;
this.id = id;
db.bids.push({
id,
auctionId: this.auctionId,
productName: this.productName,
bidderName: this.bidderName,
bidAmount: this.bidAmount,
userId: this.userId,
});
return db.bids[id - 1];
}
Bid.prototype.viewBidsOnAuction = function (auctionId) {
return db.bids.filter((bid) => bid.auctionId == auctionId);
}
module.exports = Bid;