class Api::UsersController < Api::BaseController
  load_permissions_and_authorize_resource

  def update
    @user = current_user

    if @user.update(user_params)
      render json: {}, status: :ok
    else
      render json: { errors: @user.errors.full_messages }, status: 422
    end
  end

  def accept_terms
    current_user.update!(terms_version: Versions.get(:terms))
  end

  private

  def user_params
    params.require(:user).permit(:firstname, :lastname, :program, :start_year,
                                 :avatar, :student_id, :phone, :display_phone,
                                 :remove_avatar, :food_custom, :notify_messages,
                                 :notify_event_users, :notify_event_closing, food_preferences: [])
  end
end

class Api::UsersController < Api::BaseController
  load_permissions_and_authorize_resource

  def update
    @user = current_user

    if @user.update(user_params)
      render json: {}, status: :ok
    else
      render json: { errors: @user.errors.full_messages }, status: 422
    end
  end

  def accept_terms
    current_user.update!(terms_version: Versions.get(:terms))
  end

  private

  def user_params
    params.require(:user).permit(:firstname, :lastname, :program, :start_year,
                                 :avatar, :student_id, :phone, :display_phone,
                                 :remove_avatar, :food_custom, :notify_messages,
                                 :notify_event_users, :notify_event_closing,
                                 :notify_event_open, food_preferences: [])
  end
end

Fix bug where notification setting could not be updated via the API
Fix bug where notification setting could not be updated via the API
