class Admin::TimeCard::ConfigsController < Admin::Controller
  def show
    render_success :ok, json: config_props
  end

  def update
    if config.update(config_params)
      render_success :ok, json: config_props
    else
      render_error :unprocessable_entity, errors: config
    end
  end

  private
    def config
      @config ||= current_school.find_or_build_time_card_config
    end

    def config_params
      params.permit(:time_period, :editable)
    end

    def config_props
      {
        time_period: config.time_period,
        editable: config.editable
      }
    end
end
