Organize/lib/actions/notes.ts

21 lines
632 B
TypeScript

"use server";
import { revalidatePath } from "next/cache";
import { prisma } from "@/lib/db";
import { requireUserId } from "@/lib/auth-helpers";
import { GroupNoteContentSchema } from "@/lib/validation/group";
export async function updateGroupNote(groupId: string, noteContent: string): Promise<void> {
const userId = await requireUserId();
const parsed = GroupNoteContentSchema.parse(noteContent);
const { count } = await prisma.group.updateMany({
where: { id: groupId, category: { userId } },
data: { noteContent: parsed },
});
if (count === 0) throw new Error("Group not found");
revalidatePath("/");
}