All files / src/services/api/products invoice.ts

54.54% Statements 12/22
33.33% Branches 3/9
12.5% Functions 1/8
54.54% Lines 12/22

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 71 72 73 74 75 76            46x                                 46x   46x             46x             46x       65x     65x 65x     65x   65x           46x             46x                    
import { ROWS_PER_PAGE } from "@hooks/common/usePagination";
import { useQuery } from "react-query";
import { customInstance } from "../index";
import { buildMerchantEndpoints } from "../utils.api";
import { ProductParams, useQueryFactory } from "./queryFactory";
 
export const getInvoices = ({
  queryString,
  page,
  sorting,
  searchQuery,
}: ProductParams) => {
  const search = searchQuery ? `&q="${searchQuery}"` : "";
  return customInstance({
    url: buildMerchantEndpoints(
      `products?filter=typeName:"invoice"${queryString}&sort=${
        sorting ?? "-id"
      }${search}&page=${page}&max=${ROWS_PER_PAGE}`,
    ),
    method: "GET",
  });
};
 
export const useGetInvoices = useQueryFactory("invoice");
 
export const getProductById = (id: string) => {
  return customInstance({
    url: buildMerchantEndpoints(`products/${id}?filter=typeName:"invoice"`),
    method: "GET",
  });
};
 
export const getInvoicesVariants = (id: number) => {
  return customInstance({
    url: buildMerchantEndpoints(`products/${id}/variants`),
    method: "GET",
  });
};
 
export const getPaymentFormVariants = (
  id: string,
  options?: { shouldWrap: boolean },
) => {
  const { shouldWrap = false } = options || {};
 
  // GB - 13407
  const filterValueMaiusc = "Any Amount";
  const filterValueMinusc = "Any amount"; // Not capitalized
  // %3B === AND
  const url = 
    `products/${id}/variants?filter=name:!"${filterValueMaiusc}"%3Bname:!"${filterValueMinusc}"&sort=displayOrder`
  ;
  return customInstance({
    url: shouldWrap ? buildMerchantEndpoints(url) : url,
    method: "GET",
  });
};
 
export const useGetEventVariants = (id: number) => {
  return useQuery("event-variants", async () => {
    const data = await getInvoicesVariants(id);
    return data;
  });
};
 
export const useGetInvoiceById = (id: string) => {
  return useQuery(
    ["get-invoice-by-id", id],
    async () => {
      const data = await getProductById(id);
      return data;
    },
    { cacheTime: 0, refetchOnWindowFocus: false },
  );
};