createOrModifyUser method
Create a new user or modify an existing one.
A user must have a login, an email or a mobilePhone defined, a user should be linked to either a Healthcare Professional, a Patient or a Device. When modifying an user, you must ensure that the rev obtained when getting or creating the user is present as the rev is used to guarantee that the user has not been modified by a third party.
Parameters:
- User user (required): The user that must be created in the database.
Implementation
@override
Future<User?> createOrModifyUser(User user) async {
if (user.rev != null) {
final modifiedUser = user.toUserDto();
final userToUpdate = await _constraintsUserModificationsBasedOnCurrentUserPermission(modifiedUser);
return (await api.baseUserApi.modifyUser(userToUpdate))?.toUser()
?? (throw StateError("Cannot modify user with id ${user.id}"));
} else {
return (await api.baseUserApi.createUser(user.toUserDto()))?.toUser()
?? (throw StateError("Cannot create user"));
}
}