generated_annual_report.rb 880 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: generated_annual_reports
  5. #
  6. # id :bigint(8) not null, primary key
  7. # account_id :bigint(8) not null
  8. # year :integer not null
  9. # data :jsonb not null
  10. # schema_version :integer not null
  11. # viewed_at :datetime
  12. # created_at :datetime not null
  13. # updated_at :datetime not null
  14. #
  15. class GeneratedAnnualReport < ApplicationRecord
  16. belongs_to :account
  17. scope :pending, -> { where(viewed_at: nil) }
  18. def viewed?
  19. viewed_at.present?
  20. end
  21. def view!
  22. update!(viewed_at: Time.now.utc)
  23. end
  24. def account_ids
  25. data['most_reblogged_accounts'].pluck('account_id') + data['commonly_interacted_with_accounts'].pluck('account_id')
  26. end
  27. def status_ids
  28. data['top_statuses'].values
  29. end
  30. end