update method

Future<QueryResult> update(
  1. Query query,
  2. Firestore db
)
inherited

Tries to store queries payload in firestore

Implementation

Future<QueryResult> update(Query query, Firestore db) async {
  final id = query.payload['id'] ?? Uuid().v1();
  final ref = db.collection(query.entityName).doc(id);
  final json = JSON.from(query.payload)..putIfAbsent('id', () => id);

  try {
    await ref.set(json);
    return QueryResult.success(query, payload: json);
    // ignore: avoid_catches_without_on_clauses
  } catch (e) {
    return QueryResult.failed(query, errorMsg: e.toString());
  }
}