feat(admin) : persist drafts and add constellation conditions
This commit is contained in:
@@ -16,6 +16,7 @@ import { builtInTemplates } from "@/lib/templates";
|
||||
import { persistTemplateApplication } from "@/lib/templates/persist";
|
||||
import {
|
||||
createGuide,
|
||||
GuideVersionConflictError,
|
||||
permanentlyDeleteGuide,
|
||||
restoreGuide,
|
||||
runCatalogSync,
|
||||
@@ -204,13 +205,19 @@ export async function applyEditorTemplate(input: unknown): Promise<
|
||||
|
||||
type GuideActionResult =
|
||||
| { status: "saved"; version?: number; location?: string }
|
||||
| { status: "conflict"; currentVersion: number; message: string }
|
||||
| { status: "error"; message: string };
|
||||
|
||||
type CreateGuideActionResult = Exclude<GuideActionResult, { status: "conflict" }>;
|
||||
|
||||
async function runGuideAction(action: () => Promise<{ version?: number }>): Promise<GuideActionResult> {
|
||||
try {
|
||||
const result = await action();
|
||||
return { status: "saved", version: result.version };
|
||||
} catch (cause) {
|
||||
if (cause instanceof GuideVersionConflictError) {
|
||||
return { status: "conflict", currentVersion: cause.currentVersion, message: cause.message };
|
||||
}
|
||||
if (cause instanceof z.ZodError) {
|
||||
return { status: "error", message: cause.issues.map((issue) => issue.message).join(" • ") };
|
||||
}
|
||||
@@ -218,7 +225,7 @@ async function runGuideAction(action: () => Promise<{ version?: number }>): Prom
|
||||
}
|
||||
}
|
||||
|
||||
export async function createStructuredGuide(input: unknown): Promise<GuideActionResult> {
|
||||
export async function createStructuredGuide(input: unknown): Promise<CreateGuideActionResult> {
|
||||
await requireAdmin();
|
||||
try {
|
||||
const guide = await createGuide(input);
|
||||
|
||||
Reference in New Issue
Block a user