search method

The search method searches for entities that match the given query.

Implementation

@override
FutureOr<List<ProjectFacilityModel>> search(
  ProjectFacilitySearchModel query, [
  String? userId,
]) async {
  return retryLocalCallOperation<List<ProjectFacilityModel>>(() async {
    final selectQuery = sql.select(sql.projectFacility).join([]);

    final results = await (selectQuery
          ..where(
            buildAnd(
              [
                if (query.projectId != null)
                  sql.projectFacility.projectId.isIn(query.projectId!),
                if (query.facilityId != null)
                  sql.projectFacility.facilityId.isIn(query.facilityId!),
              ],
            ),
          ))
        .get();

    return results.map((e) {
      final projectFacility = e.readTable(sql.projectFacility);

      return ProjectFacilityModel(
        facilityId: projectFacility.facilityId,
        projectId: projectFacility.projectId,
        tenantId: projectFacility.tenantId,
        rowVersion: projectFacility.rowVersion,
        id: projectFacility.id,
        isDeleted: projectFacility.isDeleted,
      );
    }).toList();
  });
}