search method
The search
method searches for entities that match the given query.
Implementation
@override
FutureOr<List<ReferralModel>> search(
ReferralSearchModel query, [
String? userId,
]) async {
return retryLocalCallOperation<List<ReferralModel>>(() async {
final selectQuery = sql.select(sql.referral).join([]);
final results = await (selectQuery
..where(buildAnd([
if (query.clientReferenceId != null)
sql.referral.clientReferenceId.isIn(
query.clientReferenceId!,
),
if (query.projectBeneficiaryClientReferenceId != null)
sql.referral.projectBeneficiaryClientReferenceId.isIn(
query.projectBeneficiaryClientReferenceId!,
),
if (userId != null)
sql.referral.auditCreatedBy.equals(
userId,
),
])))
.get();
return results
.map((e) {
final referral = e.readTableOrNull(sql.referral);
if (referral == null) return null;
return ReferralModel(
id: referral.id,
clientReferenceId: referral.clientReferenceId,
rowVersion: referral.rowVersion,
tenantId: referral.tenantId,
isDeleted: referral.isDeleted,
projectBeneficiaryClientReferenceId:
referral.projectBeneficiaryClientReferenceId,
auditDetails: AuditDetails(
createdBy: referral.auditCreatedBy!,
createdTime: referral.auditCreatedTime!,
lastModifiedBy: referral.auditModifiedBy,
lastModifiedTime: referral.auditModifiedTime,
),
clientAuditDetails: referral.clientCreatedTime == null ||
referral.clientCreatedBy == null
? null
: ClientAuditDetails(
createdTime: referral.clientCreatedTime!,
createdBy: referral.clientCreatedBy!,
lastModifiedBy: referral.clientModifiedBy,
lastModifiedTime: referral.clientModifiedTime,
),
);
})
.whereNotNull()
.where((element) => element.isDeleted != true)
.toList();
});
}