All files / src/features/TransactionPanel/helpers getPurchaseItems.ts

84.61% Statements 11/13
62.5% Branches 5/8
100% Functions 3/3
100% Lines 10/10

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          52x                 52x                   52x 68x 68x 124x 124x 124x 124x   124x                                                  
// features/TransactionPanel/helpers/getPurchaseItems.ts
 
import { parseAmount } from "@utils/index";
import { TTransaction } from "../types";
 
const recurringIntervalMap: Record<string, string> = {
  once: "One Time",
  monthly: "Monthly",
  yearly: "Yearly",
  weekly: "Weekly",
  daily: "Daily",
  quarterly: "Quarterly",
};
 
const paymentFormTypeMap: Record<string, string> = {
  standard: "Product",
  event: "Event",
  fundraiser: "Fundraiser",
  membership: "Membership",
  sweepstake: "Sweepstakes",
  invoice: "Invoice",
  product: "Product",
};
 
export const getPurchaseItems = (data: TTransaction) => {
  const seen = new Set<string | number>();
  const uniqueItems = (data?.items ?? []).filter((item: any) => {
    Iif (item?.id == null) return true;
    Iif (seen.has(item.id)) return false;
    seen.add(item.id);
    return true;
  });
  return uniqueItems.map((item: any) => ({
    paymentFormName: item?.product?.name,
    paymentFormType:
      paymentFormTypeMap[
        item?.product?.type as keyof typeof paymentFormTypeMap
      ],
    purchaseAmount: item?.quantity,
    recurrence:
      recurringIntervalMap[
        item?.recurringInterval as keyof typeof recurringIntervalMap
      ],
    itemName: item?.product?.variant?.name,
    price: parseAmount(item?.price / 100),
    createdAt: item?.createdAt,
    recurringNextAt: item?.recurringNextAt,
    recurringStatus: item?.recurringStatus,
    cardNumberLast4: data?.sourceMethod?.method?.numberLast4,
    cardBrandName: data?.sourceMethod?.method?.brand,
    orderRecurringObjID: item?.orderRecurringItemID || "",
    id: item?.id,
    disallowReversalRequests: item?.disallowReversalRequests,
    reference: item?.product?.reference,
    metadata: data?.metadata,
  }));
};