searchWithoutClientReferenceId method

FutureOr<List<PgrServiceResponseModel>> searchWithoutClientReferenceId(
  1. PgrServiceSearchModel query, {
  2. int? offSet,
  3. int? limit,
})

Implementation

FutureOr<List<PgrServiceResponseModel>> searchWithoutClientReferenceId(
  PgrServiceSearchModel query, {
  int? offSet,
  int? limit,
}) async {
  Response response;

  try {
    response = await executeFuture(
      future: () async {
        return await dio.post(
          searchPath,
          queryParameters: {
            'offset': offSet ?? 0,
            'limit': limit ?? 100,
            'tenantId': DigitDataModelSingleton().tenantId,
          }..addAll(query.toMap()),
          data: query.toMap(),
        );
      },
    );
  } catch (error) {
    return [];
  }

  final responseMap = response.data;

  if (responseMap is! Map<String, dynamic>) {
    throw InvalidApiResponseException(
      data: query.toMap(),
      path: searchPath,
      response: responseMap,
    );
  }

  PgrServiceCreateResponseModel pgrServiceCreateResponseModel;
  List<PgrComplaintResponseModel> pgrComplaintModel;
  try {
    pgrServiceCreateResponseModel =
        PgrServiceCreateResponseModelMapper.fromMap(
      responseMap,
    );
    pgrComplaintModel = pgrServiceCreateResponseModel.serviceWrappers;
  } catch (e) {
    throw InvalidApiResponseException(
      data: query.toMap(),
      path: searchPath,
      response: responseMap,
    );
  }

  return pgrComplaintModel.map((e) {
    return e.service;
  }).toList();
}