All files / src/features/MerchantPortal/Customer/utils AvailabilityCheckFunctions.ts

0% Statements 0/10
0% Branches 0/6
0% Functions 0/1
0% Lines 0/9

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                                                                       
import { customInstance } from "@services/api";
import { convertPhoneNumber } from "@utils/date.helpers";
 
export const checkCustomerAvailability = async (
  type: "email" | "phoneNumber",
  merchantId: number,
  value?: string,
) => {
  if (!value) return false;
 
  try {
    let response;
    if (type === "email") {
      response = await customInstance({
        url: `/merchants/${merchantId}/customers/email-check`,
        method: "POST",
        data: {
          email: value,
        },
      });
    } else if (type === "phoneNumber") {
      response = await customInstance({
        url: `/merchants/${merchantId}/customers/phonenumber-check`,
        method: "POST",
        data: {
          phoneNumber: convertPhoneNumber(value),
        },
      });
    }
 
    return response.isAvailable;
  } catch (error) {
    return false;
  }
};