2021-02-15 13:42:32 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-02-05 13:59:30 +01:00
|
|
|
class CustomWizard::RealtimeValidationsController < ::ApplicationController
|
2021-02-01 14:58:37 +01:00
|
|
|
def validate
|
2021-02-16 01:43:00 +01:00
|
|
|
klass_str = "CustomWizard::RealtimeValidation::#{validation_params[:type].camelize}"
|
|
|
|
result = klass_str.constantize.new(current_user).perform(validation_params)
|
|
|
|
render_serialized(result.items, "#{klass_str}Serializer".constantize, result.serializer_opts)
|
|
|
|
end
|
2021-02-24 08:50:42 +01:00
|
|
|
|
2021-02-16 01:43:00 +01:00
|
|
|
private
|
2021-02-24 08:50:42 +01:00
|
|
|
|
2021-02-16 01:43:00 +01:00
|
|
|
def validation_params
|
|
|
|
params.require(:type)
|
|
|
|
settings = ::CustomWizard::RealtimeValidation.types[params[:type].to_sym]
|
|
|
|
params.require(settings[:required_params]) if settings[:required_params].present?
|
|
|
|
params
|
2021-02-01 14:58:37 +01:00
|
|
|
end
|
|
|
|
end
|