search method

  1. @override
FutureOr<List<AttendanceLogModel>> search(
  1. AttendanceLogSearchModel query, [
  2. String? userId
])
override

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

Implementation

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

    final results = await (selectQuery
          ..where(buildAnd([
            if (query.individualId != null)
              sql.attendance.individualId.equals(
                query.individualId!,
              ),
            if (query.registerId != null)
              sql.attendance.registerId.equals(
                query.registerId!,
              ),
            if (query.uploadToServer != null)
              sql.attendance.uploadToServer.equals(
                query.uploadToServer!,
              ),
          ])))
        .get();

    return results
        .map((e) {
          final attendeeLog = e.readTableOrNull(sql.attendance);
          if (attendeeLog == null) return null;

          return AttendanceLogModel(
            id: attendeeLog.id,
            registerId: attendeeLog.registerId,
            individualId: attendeeLog.individualId,
            status: attendeeLog.status,
            clientReferenceId: attendeeLog.clientReferenceId,
            time: attendeeLog.time,
            type: attendeeLog.type,
            uploadToServer: attendeeLog.uploadToServer,
            additionalDetails: attendeeLog.additionalFields != null
                ? jsonDecode(attendeeLog.additionalFields!.toString())
                : null,
            auditDetails: AuditDetails(
              createdTime: attendeeLog.auditCreatedTime!,
              createdBy: attendeeLog.auditCreatedBy!,
              lastModifiedBy: attendeeLog.auditModifiedBy,
              lastModifiedTime: attendeeLog.auditModifiedTime,
            ),
            clientAuditDetails: ClientAuditDetails(
              createdTime: attendeeLog.clientCreatedTime!,
              createdBy: attendeeLog.clientCreatedBy!,
              lastModifiedBy: attendeeLog.clientModifiedBy,
              lastModifiedTime: attendeeLog.clientModifiedTime,
            ),
          );
        })
        .whereNotNull()
        .where((element) => element.isDeleted != true)
        .toList();
  });
}