2023-08-03 22:03:40 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ResultSerializer < ActiveModel::Serializer
|
|
|
|
include Canaid::Helpers::PermissionsHelper
|
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
include ApplicationHelper
|
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
include InputSanitizeHelper
|
|
|
|
|
2023-08-10 22:48:08 +08:00
|
|
|
attributes :name, :id, :urls, :updated_at, :created_at_formatted, :updated_at_formatted, :user, :my_module_id
|
2023-08-03 22:03:40 +08:00
|
|
|
|
|
|
|
def updated_at
|
|
|
|
object.updated_at.to_i
|
|
|
|
end
|
|
|
|
|
|
|
|
def user
|
|
|
|
{
|
|
|
|
avatar: object.user&.avatar_url(:icon_small),
|
|
|
|
name: object.user&.full_name
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def created_at_formatted
|
|
|
|
I18n.l(object.created_at, format: :full)
|
|
|
|
end
|
|
|
|
|
|
|
|
def updated_at_formatted
|
|
|
|
I18n.l(object.updated_at, format: :full)
|
|
|
|
end
|
|
|
|
|
|
|
|
def urls
|
|
|
|
{
|
2023-08-10 22:48:08 +08:00
|
|
|
elements_url: elements_my_module_result_path(object.my_module, object),
|
|
|
|
attachments_url: assets_my_module_result_path(object.my_module, object)
|
2023-08-03 22:03:40 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|