delete method

  1. @override
FutureOr<void> delete(
  1. IndividualModel entity, {
  2. bool createOpLog = true,
})
override

The delete method deletes an existing entity.

Implementation

@override
FutureOr<void> delete(
  IndividualModel entity, {
  bool createOpLog = true,
}) async {
  return retryLocalCallOperation(() async {
    final updated = entity.copyWith(
      isDeleted: true,
      rowVersion: entity.rowVersion,
      clientAuditDetails: ClientAuditDetails(
        createdBy: entity.clientAuditDetails!.createdBy,
        createdTime: entity.clientAuditDetails!.createdTime,
        lastModifiedBy: entity.clientAuditDetails!.lastModifiedBy,
        lastModifiedTime: DateTime.now().millisecondsSinceEpoch,
      ),
    );
    await sql.batch((batch) {
      batch.update(
        sql.individual,
        updated.companion,
        where: (table) => table.clientReferenceId.equals(
          entity.clientReferenceId,
        ),
      );
    });

    return super.delete(updated);
  });
}