A few cleanup steps

This commit is contained in:
Josh Pigford
2024-10-29 19:42:39 -04:00
parent d58e2e7913
commit 46a859324b
6 changed files with 13 additions and 11 deletions

View File

@@ -39,8 +39,6 @@ class Account::TradesController < ApplicationController
synth_client = Provider::Synth.new(ENV["SYNTH_API_KEY"])
@securities = synth_client.search_securities(query:, dataset: "limited", country_code: Current.family.country).securities
Rails.logger.info("SECURITIES: #{@securities.inspect}")
end
private

View File

@@ -31,8 +31,10 @@ class Account::TradeBuilder < Account::EntryBuilder
end
def security
return Security.find(ticker) if ticker.match?(/\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/i)
Security.find_or_create_by(ticker: ticker)
exchange_mic = ticker.match(/\((.*?)\)/)&.captures&.first
ticker_symbol = ticker.gsub(/\s*\(.*?\)\s*/, '')
Security.find_or_create_by(ticker: ticker_symbol, exchange_mic: exchange_mic)
end
def amount

View File

@@ -8,7 +8,7 @@
<%= form.select :type, options_for_select([%w[Buy buy], %w[Sell sell], %w[Deposit transfer_in], %w[Withdrawal transfer_out], %w[Interest interest]], "buy"), { label: t(".type") }, { data: { "trade-form-target": "typeInput" } } %>
<div data-trade-form-target="tickerInput">
<div class="form-field combobox">
<%= form.combobox :ticker, securities_account_trades_path(entry.account), label: t(".holding"), placeholder: t(".ticker_placeholder"), autocomplete: :list, free_text: true %>
<%= form.combobox :ticker, securities_account_trades_path(entry.account), label: t(".holding"), placeholder: t(".ticker_placeholder") %>
</div>
</div>

View File

@@ -1,6 +1,5 @@
<div class="flex items-center">
<%= image_tag(tickers[:logo_url],
class: "rounded-full h-8 w-8 inline-block mr-2" ) %>
<%= image_tag(tickers[:logo_url], class: "rounded-full h-8 w-8 inline-block mr-2" ) %>
<div class="flex flex-col">
<span class="text-sm font-medium">
<%= tickers[:name].presence || tickers[:symbol] %>

View File

@@ -0,0 +1,5 @@
class RemoveSearchVector < ActiveRecord::Migration[7.2]
def change
remove_column :securities, :search_vector
end
end

6
db/schema.rb generated
View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.2].define(version: 2024_10_29_184115) do
ActiveRecord::Schema[7.2].define(version: 2024_10_29_234028) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
@@ -119,7 +119,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_10_29_184115) do
t.boolean "is_active", default: true, null: false
t.date "last_sync_date"
t.uuid "institution_id"
t.virtual "classification", type: :string, as: "\nCASE\n WHEN ((accountable_type)::text = ANY ((ARRAY['Loan'::character varying, 'CreditCard'::character varying, 'OtherLiability'::character varying])::text[])) THEN 'liability'::text\n ELSE 'asset'::text\nEND", stored: true
t.virtual "classification", type: :string, as: "\nCASE\n WHEN ((accountable_type)::text = ANY (ARRAY[('Loan'::character varying)::text, ('CreditCard'::character varying)::text, ('OtherLiability'::character varying)::text])) THEN 'liability'::text\n ELSE 'asset'::text\nEND", stored: true
t.uuid "import_id"
t.string "mode"
t.index ["accountable_id", "accountable_type"], name: "index_accounts_on_accountable_id_and_accountable_type"
@@ -481,9 +481,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_10_29_184115) do
t.string "country_code"
t.string "exchange_mic"
t.string "exchange_acronym"
t.virtual "search_vector", type: :tsvector, as: "(setweight(to_tsvector('simple'::regconfig, (COALESCE(ticker, ''::character varying))::text), 'B'::\"char\") || to_tsvector('simple'::regconfig, (COALESCE(name, ''::character varying))::text))", stored: true
t.index ["country_code"], name: "index_securities_on_country_code"
t.index ["search_vector"], name: "index_securities_on_search_vector", using: :gin
t.index ["ticker", "exchange_mic"], name: "index_securities_on_ticker_and_exchange_mic", unique: true
end