25 lines
767 B
TypeScript
25 lines
767 B
TypeScript
"use server";
|
|
|
|
import { revalidatePath } from "next/cache";
|
|
import { addNavLink, deleteNavLinkByPageId } from "./repository";
|
|
import { prisma } from "../prisma";
|
|
import { requireAdmin } from "../user/require";
|
|
import { runAction } from "../run-action";
|
|
import type { ActionResult } from "../action-result";
|
|
|
|
export async function togglePinAction(pageId: string, isPinned: boolean): Promise<ActionResult> {
|
|
return runAction(async () => {
|
|
await requireAdmin();
|
|
|
|
if (isPinned) {
|
|
await deleteNavLinkByPageId(pageId);
|
|
} else {
|
|
const page = await prisma.page.findUnique({ where: { id: pageId } });
|
|
if (!page) throw new Error(`Page not found: ${pageId}`);
|
|
await addNavLink({ pageId });
|
|
}
|
|
|
|
revalidatePath("/", "layout");
|
|
});
|
|
}
|