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