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

33 Zeilen
683 B
Ruby

# frozen_string_literal: true
class CustomWizard::SubmissionSerializer < ApplicationSerializer
attributes :id,
:fields,
2022-03-12 15:20:54 +01:00
:submitted_at
2022-03-12 15:20:54 +01:00
has_one :user, serializer: ::BasicUserSerializer, embed: :objects
def include_user?
2022-03-16 14:12:13 +01:00
object.user.present?
2022-03-12 15:20:54 +01:00
end
def fields
@fields ||= begin
2022-03-16 14:12:13 +01:00
result = {}
2022-03-12 15:20:54 +01: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
result
end
end
2021-06-23 08:15:17 +02:00
end