update method

  1. @override
Future<Job> update(
  1. String id,
  2. Job updater(
    1. Job
    )
)
inherited

Implementation

@override
Future<T> update(String id, T Function(T) updater) async {
  try {
    final existingItem = await get(id);
    final updatedItem = updater(existingItem);
    final document = _toFirestore(updatedItem, id);
    final parent =
        collectionParentPath.isEmpty
            ? documentsPath
            : '$documentsPath/$collectionParentPath';
    final documentPath = '$parent/$collectionId/$id';
    document.name = documentPath;

    //only update whats changed.......

    final updatedDocument = await _firestore.projects.databases.documents
        .patch(document, documentPath, currentDocument_exists: true);
    return _fromFirestore(updatedDocument);
  } catch (e) {
    if (e is DetailedApiRequestError) {
      if (e.status == 404) {
        throw RepositoryException(
          message: 'Item with id $id not found',
          code: RepositoryErrorCode.notFound,
        );
      }
    }
    rethrow;
  }
}