diff --git a/lib/bandwidth_tn_repo.rb b/lib/bandwidth_tn_repo.rb index 10e2fd3d590e487dda3befc7aed8f48d69379208..8deeb0d451416e7a524a6ac11d6427b0deac4093 100644 --- a/lib/bandwidth_tn_repo.rb +++ b/lib/bandwidth_tn_repo.rb @@ -8,7 +8,7 @@ class BandwidthTnRepo tel, region, locality, - bandwidth_account_id, + source, available_after ) VALUES ( $1, diff --git a/lib/tel_selections.rb b/lib/tel_selections.rb index aec0d6b96e9c812da6a4c84940533254580fbf6f..55550c2ea739b05e69b778ba87fc918b0aa20d4d 100644 --- a/lib/tel_selections.rb +++ b/lib/tel_selections.rb @@ -182,7 +182,7 @@ class TelSelections full_number: row["tel"].sub(/\A\+1/, ""), city: row["locality"], state: row["region"] - ), row["bandwidth_account_id"], price: row["premium_price"]) + ), row["source"], price: row["premium_price"]) } } end @@ -242,9 +242,9 @@ class TelSelections def self.for_pending_value(value) if value.start_with?("LocalInventory/") - tel, account, price = + tel, source, price = value.sub(/\ALocalInventory\//, "").split("/", 3) - LocalInventory.new(Tn.new(tel), account, price: price.to_d) + LocalInventory.new(Tn.new(tel), source, price: price.to_d) else Bandwidth.new(Tn.new(value)) end @@ -327,9 +327,9 @@ class TelSelections attr_reader :price - def initialize(tn, bandwidth_account_id, price: 0) + def initialize(tn, source, price: 0) super(tn) - @bandwidth_account_id = bandwidth_account_id + @source = source @price = price || 0 end @@ -372,20 +372,20 @@ class TelSelections full_number: row["tel"].sub(/\A\+1/, ""), city: row["locality"], state: row["region"] - ), row["bandwidth_account_id"], price: row["premium_price"]) + ), row["source"], price: row["premium_price"]) } } end def pending_value - "LocalInventory/#{tel}/#{@bandwidth_account_id}/#{price}" + "LocalInventory/#{tel}/#{@source}/#{price}" end def order(db, _customer) # Move always moves to wrong account, oops # Also probably can't move from/to same account # BandwidthTnRepo.new.move( - # tel, customer.customer_id, @bandwidth_account_id + # tel, customer.customer_id, @source # ) db.exec_defer("DELETE FROM tel_inventory WHERE tel = $1", [tel]) .then { |r| raise unless r.cmd_tuples.positive? } @@ -444,7 +444,8 @@ class TelSelections define_method(:sql_query) do [ "SELECT * FROM tel_inventory " \ - "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1", + "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1 " \ + "AND source NOT LIKE 'xmpp:%'", "+1#{@q}%" ] end @@ -478,7 +479,8 @@ class TelSelections def sql_query [ "SELECT * FROM tel_inventory " \ - "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1", + "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1 " \ + "AND source NOT LIKE 'xmpp:%'", "%#{q_digits}%" ] end @@ -518,7 +520,8 @@ class TelSelections def sql_query [ "SELECT * FROM tel_inventory " \ - "WHERE available_after < LOCALTIMESTAMP AND region = $1", + "WHERE available_after < LOCALTIMESTAMP AND region = $1 " \ + "AND source NOT LIKE 'xmpp:%'", @state ] end @@ -570,7 +573,8 @@ class TelSelections [ "SELECT * FROM tel_inventory " \ "WHERE available_after < LOCALTIMESTAMP " \ - "AND region = $1 AND locality = $2", + "AND region = $1 AND locality = $2 " \ + "AND source NOT LIKE 'xmpp:%'", @state.to_s, @city ] end diff --git a/test/test_tel_selections.rb b/test/test_tel_selections.rb index 1b6b1a622df18a97c81a49fa2587378c22e1017f..d5abd1470bfdc851f8fe944a6f8b99878d2c6328 100644 --- a/test/test_tel_selections.rb +++ b/test/test_tel_selections.rb @@ -227,7 +227,8 @@ class TelSelectionsTest < Minitest::Test assert_equal( [ "SELECT * FROM tel_inventory " \ - "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1", + "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1 " \ + "AND source NOT LIKE 'xmpp:%'", "+1226%" ], q.sql_query @@ -244,7 +245,8 @@ class TelSelectionsTest < Minitest::Test assert_equal( [ "SELECT * FROM tel_inventory " \ - "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1", + "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1 " \ + "AND source NOT LIKE 'xmpp:%'", "+1226666%" ], q.sql_query @@ -261,7 +263,8 @@ class TelSelectionsTest < Minitest::Test assert_equal( [ "SELECT * FROM tel_inventory " \ - "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1", + "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1 "\ + "AND source NOT LIKE 'xmpp:%'", "+12266667%" ], q.sql_query @@ -288,7 +291,8 @@ class TelSelectionsTest < Minitest::Test assert_equal( [ "SELECT * FROM tel_inventory " \ - "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1", + "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1 " \ + "AND source NOT LIKE 'xmpp:%'", "%6262%" ], q.sql_query @@ -305,7 +309,8 @@ class TelSelectionsTest < Minitest::Test assert_equal( [ "SELECT * FROM tel_inventory " \ - "WHERE available_after < LOCALTIMESTAMP AND region = $1", + "WHERE available_after < LOCALTIMESTAMP AND region = $1 " \ + "AND source NOT LIKE 'xmpp:%'", "ON" ], q.sql_query @@ -322,7 +327,8 @@ class TelSelectionsTest < Minitest::Test assert_equal( [ "SELECT * FROM tel_inventory " \ - "WHERE available_after < LOCALTIMESTAMP AND region = $1", + "WHERE available_after < LOCALTIMESTAMP AND region = $1 " \ + "AND source NOT LIKE 'xmpp:%'", "ON" ], q.sql_query @@ -339,7 +345,8 @@ class TelSelectionsTest < Minitest::Test assert_equal( [ "SELECT * FROM tel_inventory " \ - "WHERE available_after < LOCALTIMESTAMP AND region = $1", + "WHERE available_after < LOCALTIMESTAMP AND region = $1 " \ + "AND source NOT LIKE 'xmpp:%'", "NY" ], q.sql_query @@ -365,7 +372,8 @@ class TelSelectionsTest < Minitest::Test [ "SELECT * FROM tel_inventory " \ "WHERE available_after < LOCALTIMESTAMP " \ - "AND region = $1 AND locality = $2", + "AND region = $1 AND locality = $2 " \ + "AND source NOT LIKE 'xmpp:%'", "NY", "New York City" ], q.sql_query @@ -391,7 +399,8 @@ class TelSelectionsTest < Minitest::Test [ "SELECT * FROM tel_inventory " \ "WHERE available_after < LOCALTIMESTAMP " \ - "AND region = $1 AND locality = $2", + "AND region = $1 AND locality = $2 " \ + "AND source NOT LIKE 'xmpp:%'", "NY", "New York City" ], q.sql_query @@ -417,7 +426,8 @@ class TelSelectionsTest < Minitest::Test [ "SELECT * FROM tel_inventory " \ "WHERE available_after < LOCALTIMESTAMP " \ - "AND region = $1 AND locality = $2", + "AND region = $1 AND locality = $2 " \ + "AND source NOT LIKE 'xmpp:%'", "ON", "Toronto" ], q.sql_query @@ -443,7 +453,8 @@ class TelSelectionsTest < Minitest::Test [ "SELECT * FROM tel_inventory " \ "WHERE available_after < LOCALTIMESTAMP " \ - "AND region = $1 AND locality = $2", + "AND region = $1 AND locality = $2 " \ + "AND source NOT LIKE 'xmpp:%'", "ON", "Toronto" ], q.sql_query