2021-06-23 08:13:58 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
class CustomWizard::SubmissionSerializer < ApplicationSerializer
|
|
|
|
attributes :id,
|
|
|
|
:fields,
|
2023-01-18 19:53:36 +01:00
|
|
|
: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
|
2023-03-15 13:33:07 +01:00
|
|
|
::BasicUserSerializer.new(object.wizard.user, root: false).as_json
|
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
|
2021-06-23 08:13:58 +02:00
|
|
|
end
|
2021-06-23 08:15:17 +02:00
|
|
|
end
|