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

0% Statements 0/12
0% Branches 0/4
0% Functions 0/5
0% Lines 0/12

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                                                                                                     
import { customInstance } from "../index";
import { useQuery } from "react-query";
import { ROWS_PER_PAGE } from "@hooks/common/usePagination";
import { ProductParams, useQueryFactory } from "./queryFactory";
import { buildMerchantEndpoints } from "../utils.api";
 
export const addFundraiser = (query: any) => {
  return customInstance({
    url: "merchants/2/customers",
    method: "POST",
    data: query,
  });
};
 
export const getFundraisers = ({
  queryString,
  page,
  sorting,
  searchQuery,
}: ProductParams) => {
  const search = searchQuery ? `&q="${searchQuery}"` : "";
  return customInstance({
    url: buildMerchantEndpoints(
      `products?filter=typeName:"fundraiser"${queryString}&sort=${
        sorting ?? "-id"
      }${search}&page=${page}&max=${ROWS_PER_PAGE}`,
    ),
    method: "GET",
  });
};
 
export const useGetFundraisers = useQueryFactory("fundraiser");
 
export const getFundraiserById = (id: string) => {
  return customInstance({
    url: buildMerchantEndpoints(`products/${id}?filter=typeName:"fundraiser"`),
    method: "GET",
  });
};
 
export const useGetFundraiserById = (id: string) => {
  return useQuery(
    ["get-fundraiser-by-id", id],
    async () => {
      const data = await getFundraiserById(id);
      return data;
    },
    { cacheTime: 0, refetchOnWindowFocus: false },
  );
};