File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed
reporting-app/app/controllers Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,27 @@ def create
4242 # PATCH/PUT /certifications/1
4343 # PATCH/PUT /certifications/1.json
4444 def update
45- if @certification . update ( certification_params )
45+ requirement_params = certification_params . fetch ( :certification_requirements , { } )
46+
47+ # Only rebuild certification_requirements if they're being updated
48+ if requirement_params . fetch ( :params , { } ) . present?
49+ begin
50+ # Try to build Requirements directly first (if already valid output format)
51+ requirements = Certifications ::Requirements . new_filtered ( requirement_params )
52+ if requirements . valid?
53+ @certification . certification_requirements = requirements
54+ else
55+ # Otherwise build from input params (needs lookback_period, etc.)
56+ @certification . certification_requirements = certification_service . certification_requirements_from_input ( requirement_params )
57+ end
58+ rescue ActiveModel ::ValidationError => e
59+ render json : { certification_requirements : e . model . errors } , status : :unprocessable_content
60+ return
61+ end
62+ end
63+
64+ # Update other attributes (excluding requirements since we handled them above)
65+ if @certification . update ( certification_params . except ( :certification_requirements ) )
4666 render :show , status : :ok , location : @certification
4767 else
4868 render json : @certification . errors , status : :unprocessable_content
You can’t perform that action at this time.
0 commit comments