-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauctions.js
More file actions
executable file
·37 lines (29 loc) · 1.07 KB
/
auctions.js
File metadata and controls
executable file
·37 lines (29 loc) · 1.07 KB
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
30
31
32
33
34
35
36
37
const db = require('./db');
const Bids = require('./bids');
function Auction(productName, productDescription, minimumBidAmount, userId) {
this.productName = productName;
this.productDescription = productDescription;
this.minimumBidAmount = minimumBidAmount;
this.userId = userId;
//Saving product for auction into the auction db
let length = db.auctions.length;
let id = length === 0 ? 1 : db.auctions[length - 1].id + 1;
this.id = id;
db.auctions.push({
id,
productName: this.productName,
productDescription: this.productDescription,
minimumBidAmount: this.minimumBidAmount,
userId: this.userId,
});
return db.auctions[id - 1];
}
Auction.prototype = Object.create(Bids.prototype);
Auction.prototype.constructor = Auction;
Auction.prototype.createAuction = function (productName, productDescription, minimumBidAmount) {
return new Auction(productName, productDescription, minimumBidAmount, this.id);
}
Auction.prototype.viewAllAuctions = function () {
return db.auctions;
}
module.exports = Auction;