Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

1.4 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.

import { requirePermissions } from "@carbon/auth/auth.server";
import type { LoaderFunctionArgs } from "react-router";
import { getCompanyExportRun } from "~/modules/settings/backups.service";
import { canManageBackups } from "~/modules/settings/settings.service";

// Polled by the export progress modal (and the in-progress list row) for live
// phase/done/total. One marker per company: the export job writes it while
// running, clears it on success and flips it to "failed" on error — so a null
// `status` means the run hasn't written its first heartbeat yet OR has finished;
// the modal uses the backup list appearing to confirm completion.
export async function loader({ request }: LoaderFunctionArgs) {
  const { client, companyId, email } = await requirePermissions(request, {
    update: "settings"
  });
  if (!(await canManageBackups(client, companyId, email)))
    throw new Response("Not found", { status: 404 });

  const run = await getCompanyExportRun(client, companyId);
  return {
    status: run.data?.status ?? null,
    progress: run.data?.progress ?? null,
    startedAt: run.data?.startedAt ?? null,
    error: run.data?.error ?? null
  };
}