export async function POST()

in src/app/api/v1/admin/qa-customs/hibp/route.ts [91:155]


export async function POST(req: NextRequest) {
  const err = await checkAdmin();
  if (err) return err;

  const body = await req.json();

  if (!body.emailHashPrefix || body.emailHashPrefix.length < 6)
    return NextResponse.json(
      { error: "emailHash is too small" },
      { status: 400 },
    );

  const emailHashPrefix = body.emailHashPrefix.slice(0, 6);
  const Name = body.Name || "Custom-Breach";
  const Title = body.Title || "Custom-Breach";
  const Domain = body.Domain || "custom-breach.com";
  const ModifiedDate = body.ModifiedDate;
  const Description =
    body.Description ||
    "This is a <em>Custom Breach</em>! Nothing to worry about :)";
  const LogoPath =
    body.LogoPath ||
    "https://www.mozilla.org/media/protocol/img/logos/mozilla/logo-word-hor.e20791bb4dd4.svg";
  const DataClasses = body.DataClasses || [];
  const IsVerified = body.IsVerified !== undefined ? body.IsVerified : true;
  const IsFabricated = body.IsFabricated || false;
  const IsSensitive = body.IsSensitive || false;
  const IsRetired = body.IsRetired || false;
  const IsSpamList = body.IsSpamList || false;
  const IsMalware = body.IsMalware || false;
  const FaviconUrl = body.FaviconUrl || null;
  const currentTime = new Date().toISOString();
  const AddedDate = body.AddedDate || currentTime;
  const BreachDate = body.BreachDate || currentTime;

  const breachData: QaBreachData = {
    emailHashPrefix,
    Id: randomInt(10 ** 6, 10 ** 9),
    PwnCount: randomInt(10 ** 6, 10 ** 9),
    Name,
    Title,
    Domain,
    ModifiedDate,
    Description,
    LogoPath,
    DataClasses,
    IsVerified,
    IsFabricated,
    IsSensitive,
    IsRetired,
    IsSpamList,
    IsMalware,
    FaviconUrl,
    BreachDate,
    AddedDate,
  };

  try {
    await addQaCustomBreach(breachData);
    return successResponse();
  } catch (error) {
    console.error("Error inserting custom breach:", error);
    return internalServerError();
  }
}