All files / src/components/AcquirerMerchants/hooks useGetBackgroundTaskStatus.ts

83.33% Statements 10/12
100% Branches 0/0
66.66% Functions 4/6
83.33% Lines 10/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 52 53 54 55 56 57 58        41x         2x           41x                         41x         1630x 1630x     2x           41x         1624x 1624x                
import { useQuery } from "react-query";
import { customInstance } from "@services/api";
import { useGetCurrentMerchantId } from "@hooks/common";
 
export const getLastBulkApprovalTask = ({
  accountId,
}: {
  accountId: number;
}) => {
  return customInstance({
    url: `/accounts/${accountId}/background-tasks?filter=%3B(name:"account_bulk_approve_task",name:"account_bulk_decline_task")%3B(status:"running")`,
    method: "GET",
  });
};
 
const getLastBulkApprovalTaskById = ({
  accountId,
  taskId,
}: {
  accountId: number;
  taskId: number | null;
}) => {
  return customInstance({
    url: `/accounts/${accountId}/background-tasks/${taskId}`,
    method: "GET",
  });
};
 
export const useGetBackgroundTaskStatus = ({
  enabled,
}: {
  enabled: boolean;
}) => {
  const { merchantId } = useGetCurrentMerchantId();
  return useQuery(
    ["get-last-background-task", merchantId],
    () => {
      return getLastBulkApprovalTask({ accountId: merchantId });
    },
    { enabled, staleTime: Infinity, cacheTime: Infinity },
  );
};
 
export const useGetBackgroundTaskStatusById = ({
  taskId,
}: {
  taskId: number | null;
}) => {
  const { merchantId } = useGetCurrentMerchantId();
  return useQuery(
    ["get-background-task-by-id", merchantId],
    () => {
      return getLastBulkApprovalTaskById({ accountId: merchantId, taskId });
    },
    { enabled: Boolean(taskId), refetchInterval: 2000 },
  );
};