All files / lib/lambda getAllForms.ts

100% Statements 15/15
75% Branches 3/4
100% Functions 4/4
100% Lines 14/14

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        1x     2x   2x 3x     2x     1x 2x 2x   2x 1x   1x         1x 1x                 1x  
import { response } from "libs/handler-lib";
import { webformVersions } from "../libs/webforms";
import { FormSchema } from "shared-types";
 
export const mapWebformsKeys = (
  webforms: Record<string, Record<string, FormSchema>>,
): Record<string, string[]> => {
  const result: Record<string, string[]> = {};
 
  Object.entries(webforms).forEach(([key, value]) => {
    result[key] = Object.keys(value).map((v) => v.replace("v", ""));
  });
 
  return result;
};
 
export const getAllForms = async () => {
  try {
    const formsWithVersions = mapWebformsKeys(webformVersions);
 
    if (Object.keys(formsWithVersions).length === 0) {
      throw new Error("No form Versions available");
    }
    return response({
      statusCode: 200,
      body: formsWithVersions,
    });
  } catch (error: any) {
    console.error("Error:", error);
    return response({
      statusCode: 502,
      body: JSON.stringify({
        error: error.message ? error.message : "Internal server error",
      }),
    });
  }
};
 
export const handler = getAllForms;