updateUserData method

  1. @override
FutureOr<PassedHttpEntity> updateUserData(
  1. RequestHolder request,
  2. ResponseHolder response,
  3. Map<String, dynamic> pathArgs
)
override

Implementation

@override
FutureOr<PassedHttpEntity> updateUserData(
  RequestHolder request,
  ResponseHolder response,
  Map<String, dynamic> pathArgs,
) {
  return _wrapper(request, response, pathArgs, () async {
    var body = await request.readAsJson();
    String? id = request.context[ContextFields.userId];
    Map<String, dynamic> updateDoc;
    try {
      updateDoc = json.decode(body[BodyFields.updateDoc]);
    } catch (e) {
      throw RequestBodyError(
          'you must provided updateDoc with the user data needed to be updated at the form of Map<String, dynamic>');
    }

    if (id == null) {
      throw RequestBodyError('id can\'t be null');
    }
    try {
      await authService.updateUserData(id, updateDoc);
    } catch (e) {
      throw Exception('can\'t update user data id=$id');
    }
    return SendResponse.sendDataToUser(
        response, 'user data updated successfully');
  });
}