mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 03:54:08 +00:00
Refactor family generator templates for streamlined labels, error handling, and account setup logic.
This commit is contained in:
@@ -70,7 +70,11 @@ class <%= class_name %>ActivitiesFetchJob < ApplicationJob
|
||||
# **credentials
|
||||
# )
|
||||
[]
|
||||
rescue Provider::<%= class_name %>::AuthenticationError
|
||||
# Re-raise auth errors - they need immediate attention
|
||||
raise
|
||||
rescue => e
|
||||
# Transient errors trigger retry via blank response
|
||||
Rails.logger.error("<%= class_name %>ActivitiesFetchJob - API error: #{e.message}")
|
||||
[]
|
||||
end
|
||||
|
||||
@@ -160,7 +160,8 @@ class <%= class_name %>Account::ActivitiesProcessor
|
||||
# TODO: Customize amount field names
|
||||
amount = parse_decimal(data[:amount]) ||
|
||||
parse_decimal(data[:net_amount])
|
||||
return if amount.nil? || amount.zero?
|
||||
return if amount.nil?
|
||||
# Note: Zero-amount transactions (splits, free shares) are allowed
|
||||
|
||||
# Get the activity date
|
||||
# TODO: Customize date field names
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class <%= class_name %>ItemsController < ApplicationController
|
||||
ALLOWED_ACCOUNTABLE_TYPES = %w[Depository CreditCard Investment Loan OtherAsset OtherLiability Crypto Property Vehicle].freeze
|
||||
|
||||
before_action :set_<%= file_name %>_item, only: [ :show, :edit, :update, :destroy, :sync, :setup_accounts, :complete_account_setup ]
|
||||
|
||||
def index
|
||||
@@ -277,11 +279,13 @@ class <%= class_name %>ItemsController < ApplicationController
|
||||
end
|
||||
|
||||
def link_<%= file_name %>_account(<%= file_name %>_account, accountable_type)
|
||||
accountable_class = validated_accountable_class(accountable_type)
|
||||
|
||||
account = Current.family.accounts.create!(
|
||||
name: <%= file_name %>_account.name,
|
||||
balance: <%= file_name %>_account.current_balance || 0,
|
||||
currency: <%= file_name %>_account.currency || "USD",
|
||||
accountable: accountable_type.constantize.new
|
||||
accountable: accountable_class.new
|
||||
)
|
||||
|
||||
<%= file_name %>_account.ensure_account_provider!(account)
|
||||
@@ -289,7 +293,7 @@ class <%= class_name %>ItemsController < ApplicationController
|
||||
end
|
||||
|
||||
def create_account_from_<%= file_name %>(<%= file_name %>_account, accountable_type, config)
|
||||
accountable_class = accountable_type.constantize
|
||||
accountable_class = validated_accountable_class(accountable_type)
|
||||
accountable_attrs = {}
|
||||
|
||||
# Set subtype if the accountable supports it
|
||||
@@ -321,4 +325,12 @@ class <%= class_name %>ItemsController < ApplicationController
|
||||
"Depository"
|
||||
end
|
||||
end
|
||||
|
||||
def validated_accountable_class(accountable_type)
|
||||
unless ALLOWED_ACCOUNTABLE_TYPES.include?(accountable_type)
|
||||
raise ArgumentError, "Invalid accountable type: #{accountable_type}"
|
||||
end
|
||||
|
||||
accountable_type.constantize
|
||||
end
|
||||
end
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
) <%%= "%" + ">" %>
|
||||
|
||||
<%%= "<" + "%# Compute unlinked accounts (no AccountProvider link) %" + ">" %>
|
||||
<%%= "<" + "% unlinked_count = #{file_name}_item.unlinked_#{file_name}_accounts.count rescue 0 %" + ">" %>
|
||||
<%%= "<" + "% unlinked_count = #{file_name}_item.unlinked_#{file_name}_accounts&.count || 0 %" + ">" %>
|
||||
|
||||
<%%= "<" + "% if unlinked_count.to_i > 0 && #{file_name}_item.accounts.empty? %" + ">" %>
|
||||
<%%= "<" + "%# No accounts imported yet - show prominent setup prompt %" + ">" %>
|
||||
|
||||
@@ -7,13 +7,14 @@ module <%= class_name %>Item::Provided
|
||||
return nil unless credentials_configured?
|
||||
|
||||
Provider::<%= class_name %>.new(
|
||||
<% parsed_fields.select { |f| f[:secret] }.each_with_index do |field, index| -%>
|
||||
<%= field[:name] %>: <%= field[:name] %><%= index < parsed_fields.select { |f| f[:secret] }.size - 1 ? ',' : '' %>
|
||||
<% end -%>
|
||||
<% if parsed_fields.select { |f| f[:default] }.any? -%>
|
||||
<% parsed_fields.select { |f| f[:default] }.each_with_index do |field, index| -%>
|
||||
<%= field[:name] %>: effective_<%= field[:name] %><%= index < parsed_fields.select { |f| f[:default] }.size - 1 ? ',' : '' %>
|
||||
<% secret_fields = parsed_fields.select { |f| f[:secret] } -%>
|
||||
<% default_fields = parsed_fields.select { |f| f[:default] } -%>
|
||||
<% secret_fields.each_with_index do |field, index| -%>
|
||||
<% needs_comma = index < secret_fields.size - 1 || default_fields.any? -%>
|
||||
<%= field[:name] %>: <%= field[:name] %><%= needs_comma ? ',' : '' %>
|
||||
<% end -%>
|
||||
<% default_fields.each_with_index do |field, index| -%>
|
||||
<%= field[:name] %>: effective_<%= field[:name] %><%= index < default_fields.size - 1 ? ',' : '' %>
|
||||
<% end -%>
|
||||
)
|
||||
end
|
||||
|
||||
@@ -55,13 +55,8 @@
|
||||
|
||||
<div class="space-y-2 max-h-96 overflow-y-auto">
|
||||
<%%= "<" + "% @unlinked_accounts.each do |#{file_name}_account| %" + ">" %>
|
||||
<label for="acc_<%%= "<" + "%= #{file_name}_account.id %" + ">" %>" class="flex items-center gap-3 p-3 border border-primary rounded-lg hover:bg-surface transition-colors cursor-pointer">
|
||||
<%%= "<" + "%= check_box_tag \"selected_accounts[]\"," %>
|
||||
<%%= "<" + "%= #{file_name}_account.id," %>
|
||||
false,
|
||||
id: "acc_#{<%%= "<" + "%= #{file_name}_account.id %" + ">" %>}",
|
||||
class: "checkbox checkbox--dark",
|
||||
data: { select_all_target: "checkbox" } <%%= "%" + ">" %>
|
||||
<%%= "<" + "%= tag.label for: dom_id(#{file_name}_account, :acc), class: \"flex items-center gap-3 p-3 border border-primary rounded-lg hover:bg-surface transition-colors cursor-pointer\" do %" + ">" %>
|
||||
<%%= "<" + "%= check_box_tag \"selected_accounts[]\", #{file_name}_account.id, false, id: dom_id(#{file_name}_account, :acc), class: \"checkbox checkbox--dark\", data: { select_all_target: \"checkbox\" } %" + ">" %>
|
||||
<div class="flex-1 min-w-0">
|
||||
<p class="font-medium text-primary truncate">
|
||||
<%%= "<" + "%= #{file_name}_account.name %" + ">" %>
|
||||
@@ -80,7 +75,7 @@
|
||||
<%%= "<" + "%= #{file_name}_account.currency || \"USD\" %" + ">" %>
|
||||
</p>
|
||||
</div>
|
||||
</label>
|
||||
<%%= "<" + "% end %" + ">" %>
|
||||
<%%= "<" + "% end %" + ">" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user