You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
702 B

  1. # frozen_string_literal: true
  2. class REST::PollSerializer < ActiveModel::Serializer
  3. attributes :id, :expires_at, :expired,
  4. :multiple, :votes_count
  5. has_many :dynamic_options, key: :options
  6. attribute :voted, if: :current_user?
  7. def id
  8. object.id.to_s
  9. end
  10. def dynamic_options
  11. if !object.expired? && object.hide_totals?
  12. object.unloaded_options
  13. else
  14. object.loaded_options
  15. end
  16. end
  17. def expired
  18. object.expired?
  19. end
  20. def voted
  21. object.votes.where(account: current_user.account).exists?
  22. end
  23. def current_user?
  24. !current_user.nil?
  25. end
  26. class OptionSerializer < ActiveModel::Serializer
  27. attributes :title, :votes_count
  28. end
  29. end