updateUser method

Future<Response<UpdateUserResponse>> updateUser({
  1. required UpdateUserRequest updateUserRequest,
  2. String? id,
  3. CancelToken? cancelToken,
  4. Map<String, dynamic>? headers,
  5. Map<String, dynamic>? extra,
  6. ValidateStatus? validateStatus,
  7. ProgressCallback? onSendProgress,
  8. ProgressCallback? onReceiveProgress,
})

Update User Update a user record.

Parameters:

  • updateUserRequest - The user to update.
  • id - The user's id.
  • cancelToken - A CancelToken that can be used to cancel the operation
  • headers - Can be used to add additional headers to the request
  • extras - Can be used to add flags to the request
  • validateStatus - A ValidateStatus callback that can be used to determine request success based on the HTTP status of the response
  • onSendProgress - A ProgressCallback that can be used to get the send progress
  • onReceiveProgress - A ProgressCallback that can be used to get the receive progress

Returns a Future containing a Response with a UpdateUserResponse as data Throws DioException if API call or serialization fails

Implementation

Future<Response<UpdateUserResponse>> updateUser({
  required UpdateUserRequest updateUserRequest,
  String? id,
  CancelToken? cancelToken,
  Map<String, dynamic>? headers,
  Map<String, dynamic>? extra,
  ValidateStatus? validateStatus,
  ProgressCallback? onSendProgress,
  ProgressCallback? onReceiveProgress,
}) async {
  const path = r'/api/v1/user';
  final options = Options(
    method: r'PATCH',
    headers: <String, dynamic>{
      ...?headers,
    },
    extra: <String, dynamic>{
      'secure': <Map<String, String>>[
        {
          'type': 'http',
          'scheme': 'bearer',
          'name': 'kindeBearerAuth',
        },
      ],
      ...?extra,
    },
    contentType: 'application/json',
    validateStatus: validateStatus,
  );

  final queryParameters = <String, dynamic>{
    if (id != null) r'id': encodeQueryParameter(_serializers, id, const FullType(String)),
  };

  dynamic bodyData;

  try {
    const type = FullType(UpdateUserRequest);
    bodyData = _serializers.serialize(updateUserRequest, specifiedType: type);

  } catch(error, stackTrace) {
    throw DioException(
       requestOptions: options.compose(
        _dio.options,
        path,
        queryParameters: queryParameters,
      ),
      type: DioExceptionType.unknown,
      error: error,
      stackTrace: stackTrace,
    );
  }

  final response = await _dio.request<Object>(
    path,
    data: bodyData,
    options: options,
    queryParameters: queryParameters,
    cancelToken: cancelToken,
    onSendProgress: onSendProgress,
    onReceiveProgress: onReceiveProgress,
  );

  UpdateUserResponse? responseData;

  try {
    final rawResponse = response.data;
    responseData = rawResponse == null ? null : _serializers.deserialize(
      rawResponse,
      specifiedType: const FullType(UpdateUserResponse),
    ) as UpdateUserResponse;

  } catch (error, stackTrace) {
    throw DioException(
      requestOptions: response.requestOptions,
      response: response,
      type: DioExceptionType.unknown,
      error: error,
      stackTrace: stackTrace,
    );
  }

  return Response<UpdateUserResponse>(
    data: responseData,
    headers: response.headers,
    isRedirect: response.isRedirect,
    requestOptions: response.requestOptions,
    redirects: response.redirects,
    statusCode: response.statusCode,
    statusMessage: response.statusMessage,
    extra: response.extra,
  );
}