2024-07-25 12:51:50 -04:00
|
|
|
module AutoSync
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
2024-11-15 13:49:37 -05:00
|
|
|
before_action :sync_family, if: :family_needs_auto_sync?
|
2024-07-25 12:51:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def sync_family
|
2024-11-15 13:49:37 -05:00
|
|
|
Current.family.update!(last_synced_at: Time.current)
|
|
|
|
Current.family.sync_later
|
|
|
|
end
|
|
|
|
|
|
|
|
def family_needs_auto_sync?
|
|
|
|
return false unless Current.family.present?
|
|
|
|
return false unless Current.family.accounts.any?
|
|
|
|
|
|
|
|
Current.family.last_synced_at.blank? ||
|
|
|
|
Current.family.last_synced_at.to_date < Date.current
|
2024-07-25 12:51:50 -04:00
|
|
|
end
|
|
|
|
end
|