All files / apps/developer-portal/layers/workflows/app/composables useWorkflows.ts

100% Statements 17/17
50% Branches 1/2
100% Functions 4/4
100% Lines 16/16

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    32x     32x 86x     32x 2x 2x   2x   2x 2x 2x 1x 1x     1x   1x 1x       2x    
import type { Workflows } from "#layers/workflows/shared/workflows.ts";
 
const NONE: Workflows = { templates: [], projects: [], problems: [] };
 
/** Baked at build like every server route here; under `nuxt dev` it re-reads `data/workflows` on refresh. */
export const useWorkflows = () =>
    useFetch<Workflows>("/api/workflows", { key: "workflows", default: () => NONE });
 
/** Only `nuxt dev` has a server to write through; the static build offers the file as a download. */
export const useWorkflowEdit = () => {
    const toast = useToast();
    const { t } = useI18n();
 
    const editable = import.meta.dev;
 
    const edit = async (body: Record<string, unknown>): Promise<boolean> => {
        try {
            await $fetch("/api/workflows/edit", { method: "POST", body });
            await refreshNuxtData("workflows");
            return true;
        } catch (cause) {
            const message =
                (cause as { statusMessage?: string } | null)?.statusMessage ??
                t("workflowEdit.failed");
            toast.add({ title: message, color: "error", icon: "i-lucide-triangle-alert" });
            return false;
        }
    };
 
    return { editable, edit };
};