All files / src/features/Settlements/ReconciliationHub/hooks buildHubQueryString.ts

100% Statements 10/10
100% Branches 6/6
100% Functions 1/1
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31                  6x       118x         118x 118x 118x 115x   118x 118x 4x     118x    
import { HubFilters, resolvePeriodRange } from "../useHubFilters";
 
/**
 * Builds the query string the reconciliation-hub endpoints expect from the UI
 * filter state: `processorName`, the resolved `startDate`/`endDate` (startDate
 * omitted for `all_time`), and — only for the summary/export endpoints —
 * `merchantAccId`. The period tabs (`periodType`/`anchorDate`) are FE-only and
 * are intentionally never sent.
 */
export const buildHubQueryString = (
  filters: HubFilters,
  options?: { includeMerchant?: boolean },
) => {
  const { startDate, endDate } = resolvePeriodRange(
    filters.periodType,
    filters.anchorDate,
  );
 
  const params = new URLSearchParams();
  params.append("processorName", filters.processorName);
  if (startDate) {
    params.append("startDate", startDate);
  }
  params.append("endDate", endDate);
  if (options?.includeMerchant && filters.merchantAccId != null) {
    params.append("merchantAccId", String(filters.merchantAccId));
  }
 
  return params.toString();
};