From 12f7be255ae45521dd400bf151cf34dfb5c5d794 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Thu, 21 Apr 2022 14:20:59 +0200 Subject: [PATCH] Stuff --- src/lib/db_models.rb | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/lib/db_models.rb b/src/lib/db_models.rb index 2a15a66..c1a8213 100644 --- a/src/lib/db_models.rb +++ b/src/lib/db_models.rb @@ -338,6 +338,11 @@ class Auction < EntityModel self.query q end + def self.expired?(id) + ah = self.find_by_id id + ah && ah.expired? + end + def images Image.get_relation @id end @@ -347,6 +352,10 @@ class Auction < EntityModel data && data.map! { |category| Category.find_by_id category["category_id"]} end + def expired? + Time.now.to_i > @end_time + end + def bids return [] end @@ -358,8 +367,22 @@ class Bid < EntityModel def initialize(data) super data @amount = data["amount"].to_f - # stuff + @auction_id = data["auction_id"].to_i + @user_id = data["user_id"].to_i + @message = data["message"] + end + + def self.place(ahid, uid, amount, message) + # TODO: check if bid is greater than prev + payload = { + auction_id: ahid, + user_id: uid, + amount: amount, + message: message + } + self.insert(payload) end + end