|
|
@ -427,21 +427,27 @@ class Bid < EntityModel |
|
|
|
data && data.map! {|dat| self.new(dat)} |
|
|
|
data && data.map! {|dat| self.new(dat)} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def self.place(ahid, uid, amount, message) |
|
|
|
private def self.validate_bid(ahid, uid, amount, message) |
|
|
|
ah = Auction.find_by_id ahid |
|
|
|
ah = Auction.find_by_id ahid |
|
|
|
if not ah then return false, "Invalid auction" end |
|
|
|
return false, "Invalid auction" unless ah.is_a? Auction |
|
|
|
|
|
|
|
return false, AUCTION_ERRORS[:expired] unless not ah.expired? |
|
|
|
|
|
|
|
return false, AUCTION_ERRORS[:cantafford] unless User.find_by_id(uid).balance - amount >= 0 |
|
|
|
|
|
|
|
return false, AUCTION_ERRORS[:bidamount] unless amount >= ah.min_new_bid |
|
|
|
|
|
|
|
return true, "" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
if amount >= ah.min_new_bid then |
|
|
|
def self.place(ahid, uid, amount, message) |
|
|
|
|
|
|
|
check, resp = self.validate_bid(ahid, uid, amount, message) |
|
|
|
|
|
|
|
if check then |
|
|
|
payload = { |
|
|
|
payload = { |
|
|
|
auction_id: ahid, |
|
|
|
auction_id: ahid, |
|
|
|
user_id: uid, |
|
|
|
user_id: uid, |
|
|
|
amount: amount, |
|
|
|
amount: amount, |
|
|
|
message: message |
|
|
|
message: message |
|
|
|
} |
|
|
|
} |
|
|
|
self.insert(payload) |
|
|
|
resp = self.insert(payload) |
|
|
|
else |
|
|
|
|
|
|
|
return false, AUCTION_ERRORS[:bidamount] |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
return check, resp |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|