prod
This commit is contained in:
+16
-10
@@ -3,16 +3,22 @@
|
||||
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 pinPageAction(pageId: string) {
|
||||
const page = await prisma.page.findUnique({ where: { id: pageId } });
|
||||
if (!page) throw new Error(`Page not found: ${pageId}`);
|
||||
export async function togglePinAction(pageId: string, isPinned: boolean): Promise<ActionResult> {
|
||||
return runAction(async () => {
|
||||
await requireAdmin();
|
||||
|
||||
await addNavLink({ pageId });
|
||||
revalidatePath("/", "layout");
|
||||
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");
|
||||
});
|
||||
}
|
||||
|
||||
export async function unpinPageAction(pageId: string) {
|
||||
await deleteNavLinkByPageId(pageId);
|
||||
revalidatePath("/", "layout");
|
||||
}
|
||||
Reference in New Issue
Block a user