markSyncUp method

Future<void> markSyncUp({
  1. OpLogEntry<UserActionModel>? entry,
  2. int? id,
  3. String? clientReferenceId,
  4. bool? nonRecoverableError,
})
inherited

Implementation

Future<void> markSyncUp({
  OpLogEntry<T>? entry,
  int? id,
  String? clientReferenceId,
  bool? nonRecoverableError,
}) async {
  if (nonRecoverableError == true && id != null && entry != null) {
    final oplog = await isar.opLogs.filter().idEqualTo(id).findFirst();
    if (oplog == null) return;
    final OpLogEntry<T> fetchedEntry = OpLogEntry.fromOpLog<T>(oplog);
    isar.writeTxnSync(() {
      isar.opLogs.putSync(fetchedEntry
          .copyWith(
            syncedUp: true,
            syncedDown: true,
            syncedDownOn: DateTime.now(),
            syncedUpOn: DateTime.now(),
          )
          .oplog);
    });
  } else if (entry != null) {
    await put(
      entry.copyWith(syncedUp: true, syncedUpOn: DateTime.now()),
    );
  } else if (id != null) {
    OpLog? oplog;

    oplog = await isar.opLogs.get(id);
    if (oplog == null) return;
    final OpLogEntry<T> fetchedEntry = OpLogEntry.fromOpLog<T>(oplog);

    await put(
      fetchedEntry.copyWith(
        syncedUp: true,
        syncedUpOn: DateTime.now(),
      ) as OpLogEntry<T>,
    );
  } else if (clientReferenceId != null) {
    final oplog = await isar.opLogs
        .filter()
        .clientReferenceIdEqualTo(clientReferenceId)
        .findFirst();

    if (oplog == null) return;

    final fetchedEntry = OpLogEntry.fromOpLog<T>(oplog);

    await put(
      fetchedEntry.copyWith(
        syncedUp: true,
        syncedUpOn: DateTime.now(),
      ) as OpLogEntry<T>,
    );
  } else {
    throw AppException('Invalid arguments');
  }

  return;
}