0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-27 11:20:28 +01:00
discourse-custom-wizard/app/serializers/custom_wizard/submission_serializer.rb

30 Zeilen
675 B
Ruby

# frozen_string_literal: true
class CustomWizard::SubmissionSerializer < ApplicationSerializer
2024-10-16 13:52:03 +02:00
attributes :id, :fields, :submitted_at, :user
2022-03-12 15:20:54 +01:00
def include_user?
2023-01-18 19:53:36 +01:00
object.wizard.user.present?
end
def user
::BasicUserSerializer.new(object.wizard.user, root: false).as_json
2022-03-12 15:20:54 +01:00
end
def fields
2024-10-16 13:52:03 +02:00
@fields ||=
begin
result = {}
2022-03-12 15:20:54 +01:00
2024-10-16 13:52:03 +02:00
object.wizard.template["steps"].each do |step|
step["fields"].each do |field|
if value = object.fields[field["id"]]
result[field["id"]] = { value: value, type: field["type"], label: field["label"] }
end
end
end
2022-03-12 15:20:54 +01:00
2024-10-16 13:52:03 +02:00
result
end
end
2021-06-23 08:15:17 +02:00
end