All files / react-app/src/api getAttachmentArchive.ts

100% Statements 6/6
66.66% Branches 4/6
100% Functions 1/1
100% Lines 6/6

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                                          105x         3x               2x 1x     1x     1x    
import { API } from "aws-amplify";
 
import { sendGAEvent } from "@/utils/ReactGA/SendGAEvent";
 
export type AttachmentArchiveScope = "all" | "section";
 
export type AttachmentArchiveResponse =
  | {
      status: "READY";
      filename: string;
      url: string;
    }
  | {
      status: "PENDING";
      pollAfterSeconds?: number;
    }
  | {
      status: "FAILED";
      message?: string;
    };
 
export const getAttachmentArchive = async (
  id: string,
  scope: AttachmentArchiveScope,
  sectionId?: string,
): Promise<AttachmentArchiveResponse> => {
  const response = (await API.post("os", "/getAttachmentArchive", {
    body: {
      id,
      scope,
      ...(sectionId ? { sectionId } : {}),
    },
  })) as Partial<AttachmentArchiveResponse>;
 
  if (!response.status) {
    sendGAEvent("api_error", {
      message: `failure /getAttachmentArchive for ${id} (${scope}${sectionId ? `:${sectionId}` : ""})`,
    });
    throw new Error("Attachment archive response was missing a status");
  }
 
  return response as AttachmentArchiveResponse;
};