updateOrg method
Future<Org>
updateOrg({
- required String orgId,
- Key? orgKey,
- List<
ContactInput> ? contacts, - List<
AddressInput> ? addresses, - String? config,
override
Update the org with the given org id. The org name and business reference cannot be updated as they are immutable once an org has been created and verified.
Implementation
@override
Future<Org> updateOrg({
required String orgId,
Key? orgKey,
List<ContactInput>? contacts,
List<AddressInput>? addresses,
String? config,
}) async {
final operation = _amplifyApi.query<String>(
request: GraphQLRequest(
document: '''
mutation UpdateOrg(\$orgID: ID!, \$orgKey: Key, \$contacts: [ContactInput], \$addresses: [AddressInput], \$config: String) {
updateOrg(orgID: \$orgID, orgKey: \$orgKey, contacts: \$contacts, addresses: \$addresses, config: \$config) {
orgID
orgName
businessRef
publicKey
certificate
verified
config
contacts {
type
description
emailAddress
phoneNumber
}
addresses {
type
description
number
street
other
municipality
county
province
postalCode
countryCode
}
quotas {
quotaName
description
period
softLimit
limit
used
}
}
}
''',
variables: {
'orgID': orgId,
'orgKey': orgKey,
'contacts': contacts,
'addresses': addresses,
'config': config,
},
),
);
final response = await operation.response.onError((e, stackTrace) {
_logger.severe(
'Exception when invoking service call to '
'update org with org id "$orgId": $e',
);
throw OrgServiceError(
message: 'Failed to create org with id: $orgId',
innerException: e is Exception ? e : Exception(e),
innerStackTrace: stackTrace,
);
});
if (response.hasErrors) {
final errorPayload = jsonEncode(response.errors);
_logger.severe('Failed to update org: $errorPayload');
if (response.errors.any(
(error) => error.message.contains(
'not associated with the given org',
),
)) {
throw OrgDoesNotExistError(orgId: orgId);
} else {
throw OrgDataUpdateError(orgId: orgId);
}
}
final data = response.data;
_logger.finest('Org updated: $data');
return Org.fromJson(jsonDecode(data!)['updateOrg']);
}