class ApiDiagnosticsController < ApiController

  before_filter :api_signed_in_user
  respond_to :json

  def create
    data = params[:data].to_json if params[:data]
    @diagnostic = Diagnostic.new
    @diagnostic.type = params[:type]
    @diagnostic.data = data
    @diagnostic.user = current_user
    @diagnostic.creator = Diagnostic::CLIENT
    @diagnostic.save

    # update last jam info if network test attempted
    if @diagnostic.type == 'NETWORK_TEST_RESULT' && params[:data] && params[:data]['client_id']
        connection = Connection.find_by_client_id(params[:data]['client_id'])
        current_user.update_addr_loc(connection, User::JAM_REASON_NETWORK_TEST)
    end

    respond_with_model(@diagnostic, new: true)
  end
end
