All files / src/services/api utils.api.ts

78.57% Statements 22/28
65% Branches 13/20
71.42% Functions 5/7
76.92% Lines 20/26

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70      541x         1152x   693x     541x         1152x 1152x 1152x     541x 4x   541x 1148x   541x                       541x         3x       3x   3x   3x 2x     3x     541x                
import { POLICY_PATHS } from "@routes/paths";
import { getMerchantId } from "@utils/helpers";
 
const buildUrl = (
  url: string,
  parent: string,
  customParam?: string | number | null,
) => {
  if (!customParam) return url;
 
  return `/${parent}/${customParam}/${url}`;
};
 
const buildWithMerchantId = (
  url: string,
  parent: string,
  customId?: number | string,
) => {
  const merchant = getMerchantId();
  const id = typeof merchant === "number" ? merchant : merchant.id;
  return buildUrl(url, parent, customId ? customId : id);
};
 
export const buildAccountsUrl = (url: string) =>
  buildWithMerchantId(url, "accounts");
 
export const buildMerchantEndpoints = (url: string, id?: number | string) =>
  buildWithMerchantId(url, "merchants", id);
 
export const addFiltersToUrl = (url: string, filters?: string) => {
  if (!filters) {
    return url; // Return the original URL if no filters are provided
  }
 
  // Check if the URL already contains a query parameter
  const separator = url.includes("?") ? "&" : "?";
 
  // Append the filter using the appropriate separator
  return `${url}${separator}filter=${encodeURIComponent(filters)}`;
};
 
export const addFiltersAndSortToUrl = (
  url: string,
  filters?: string,
  sort?: string,
) => {
  Iif (!filters && !sort) {
    return url;
  }
  let formattedUrl;
  Eif (sort) formattedUrl = `${url}?sort=${sort}`;
 
  const separator = sort ? "&" : "?";
 
  if (filters) {
    formattedUrl += `${separator}filter=${filters}`;
  }
 
  return formattedUrl;
};
 
const exemptPaths = [
  `/${POLICY_PATHS.PRIVACY}`,
  `/${POLICY_PATHS.TERMS_OF_SERVICE}`,
  `/${POLICY_PATHS.SLA}`,
];
export function isExemptPath(pathname: string): boolean {
  return exemptPaths.includes(pathname);
}