create method

  1. @override
FutureOr<void> create(
  1. TaskModel entity, {
  2. bool createOpLog = true,
  3. DataOperation dataOperation = DataOperation.create,
})
override

The create method creates a new entity.

Implementation

@override
FutureOr<void> create(
  TaskModel entity, {
  bool createOpLog = true,
  DataOperation dataOperation = DataOperation.create,
}) async {
  return retryLocalCallOperation(() async {
    final taskCompanion = entity.companion;
    final addresses = entity.address?.copyWith(
      relatedClientReferenceId: entity.clientReferenceId,
    );
    final resources = entity.resources;
    await sql.batch((batch) async {
      batch.insert(sql.task, taskCompanion);

      if (resources != null) {
        final resourcesCompanions = resources.map((e) {
          return e.companion;
        }).toList();

        batch.insertAll(
          sql.taskResource,
          resourcesCompanions,
          mode: InsertMode.insertOrReplace,
        );
      }

      if (addresses != null) {
        final addressCompanions = addresses.companion;

        batch.insert(
          sql.address,
          addressCompanions,
          mode: InsertMode.insertOrReplace,
        );
      }

      await super.create(
        entity,
      );
    });
  });
}