search method
The search
method searches for entities that match the given query.
Implementation
@override
FutureOr<List<ServiceModel>> search(
ServiceSearchModel query,
) async {
return retryLocalCallOperation<List<ServiceModel>>(() async {
final selectQuery = sql.select(sql.service).join([]);
final results = await (selectQuery
..where(buildAnd([
if (query.id != null)
sql.service.serviceDefId.equals(
query.id!,
),
if (query.clientId != null)
sql.service.clientId.equals(
query.clientId!,
),
])))
.get();
final List<ServiceModel> serviceList = [];
for (final e in results) {
final data = e.readTable(sql.service);
final selectattributeQuery = sql.select(sql.serviceAttributes).join([]);
final val = await (selectattributeQuery
..where(buildAnd([
sql.serviceAttributes.referenceId.equals(
data.clientId,
),
])))
.get();
final res = val.map((e) {
final attribute = e.readTableOrNull(sql.serviceAttributes);
if (attribute != null) {
return ServiceAttributesModel(
clientReferenceId: attribute.clientReferenceId,
attributeCode: attribute.attributeCode,
value: attribute.value,
referenceId: attribute.referenceId,
dataType: attribute.dataType,
additionalDetails: attribute.additionalDetails,
tenantId: attribute.tenantId,
isDeleted: attribute.isDeleted,
rowVersion: attribute.rowVersion,
);
}
}).toList();
serviceList.add(ServiceModel(
clientId: data.clientId,
id: data.id,
tenantId: data.tenantId,
rowVersion: data.rowVersion,
isActive: data.isActive,
isDeleted: data.isDeleted,
serviceDefId: data.serviceDefId,
createdAt: data.createdAt,
attributes: res.whereNotNull().toList(),
));
}
return serviceList;
});
}