updateUserCallCover method
- MultipartFile? file,
- CropAreaInput? crop, {
- void onSendProgress()?,
Updates or resets the MyUser.callCover field with the provided image
file.
HTTP request for this mutation must be Content-Type: multipart/form-data
containing the uploaded file and the file argument itself must be null,
otherwise this mutation will fail.
Authentication
Mandatory.
Result
One of the following MyUserEvents may be produced on success:
- EventUserCallCoverUpdated (if image
fileis provided); - EventUserCallCoverRemoved (if image
fileis not provided).
Idempotent
Succeeds as no-op (and returns no MyUserEvent) if the authenticated
MyUser uses the specified image file already as his callCover with the
same crop area.
Implementation
Future<MyUserEventsVersionedMixin?> updateUserCallCover(
dio.MultipartFile? file,
CropAreaInput? crop, {
void Function(int count, int total)? onSendProgress,
}) async {
Log.debug(
'updateUserCallCover($file, $crop, onSendProgress)',
'$runtimeType',
);
final variables = UpdateUserCallCoverArguments(file: null, crop: crop);
final query = MutationOptions(
operationName: 'UpdateUserCallCover',
document: UpdateUserCallCoverMutation(variables: variables).document,
variables: variables.toJson(),
);
final request = query.asRequest;
final body = const RequestSerializer().serializeRequest(request);
final encodedBody = json.encode(body);
try {
var response = await client.post(
file == null
? encodedBody
: dio.FormData.fromMap({
'operations': encodedBody,
'map': '{ "file": ["variables.upload"] }',
'file': file,
}),
options: file == null
? null
: dio.Options(contentType: 'multipart/form-data'),
operationName: query.operationName,
onSendProgress: onSendProgress,
onException: (data) => UpdateUserCallCoverException(
(UpdateUserCallCover$Mutation.fromJson(data).updateUserCallCover
as UpdateUserCallCover$Mutation$UpdateUserCallCover$UpdateUserCallCoverError)
.code,
),
);
if (response.data['data'] == null) {
throw GraphQlException([
GraphQLError(message: response.data.toString()),
]);
}
return (UpdateUserCallCover$Mutation.fromJson(
response.data['data'],
).updateUserCallCover
as MyUserEventsVersionedMixin?);
} on dio.DioException catch (e) {
if (e.response?.statusCode == 413) {
throw const UpdateUserCallCoverException(
UpdateUserCallCoverErrorCode.invalidSize,
);
}
rethrow;
}
}