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