getReportUrlById method

  1. @override
Future<String> getReportUrlById(
  1. String businessId,
  2. int id, {
  3. String reportType = 'dashboard',
})
override

Implementation

@override
Future<String> getReportUrlById(
  String businessId,
  int id, {
  String reportType = 'dashboard',
}) async {
  if (businessId.isEmpty) {
    throw Exception(
      'Business Id is required, please provide a valid businessId',
    );
  }

  if (id <= 0) {
    throw Exception('Invalid report id, please provide a valid report id');
  }

  if (reportType.isEmpty) {
    throw Exception(
        'Invalid report type, please provide a valid report type');
  }

  if (user == null) {
    throw Exception('User is not authenticated, please sign in to continue');
  }

  if (!_isReady) {
    throw Exception(
        'Report client is not ready for usage, call initialise before attempting to make this call');
  }

  logger.info(
    this,
    'getting report url for report id: $id, for user: ${user?.uid}, and business: $businessId',
  );

  final String url =
      '$baseUrl/Get${settings.provider}ReportURL/businessId=$businessId';

  final LittleFishHttpClient http = LittleFishHttpClient();

  final response =
      await http.post(url: url, user: authService.user, requestData: {
    'type': reportType,
    'typeId': id,
  }, additionalHeaders: {
    'x-api-key': apiKey,
  });

  logger.debug(
    this,
    'response status code: ${response?.statusCode}, from getting reports, for business: $businessId, and user:${user?.uid}, from url: $url',
  );

  if ((response?.isOk ?? false)) {
    logger.info(
      this,
      'got report url for report id: $id successfully, for business:$businessId, and user:${user?.uid}',
    );
    final uri = response?.data['uriValue'] ?? '';

    logger.debug(
      this,
      'got report url for report id: $id, and business:$businessId, and user:${user?.uid}, uri: $uri',
    );

    return uri;
  } else {
    logger.error(
      this,
      'failed to get user report:$id, from $url, for business: $businessId, and user:${user?.uid}, with error: ${response?.statusCode}, and message: ${response?.statusMessage}',
    );

    throw Exception(
      'failed to get user report:$id, from $url, for business: $businessId, and user:${user?.uid}, with error: ${response?.statusCode}, and message: ${response?.statusMessage}',
    );
  }
}