diff --git a/src/lib/db/schema/invitations.query.ts b/src/lib/db/schema/invitations.query.ts new file mode 100644 index 0000000..bf6206e --- /dev/null +++ b/src/lib/db/schema/invitations.query.ts @@ -0,0 +1,35 @@ +"use server"; + +import { eq } from "drizzle-orm"; +import { db } from "~/lib/db"; +import { invitations } from "~/lib/db/schema/invitations"; + +type UpdateInvitationParams = { + id: string; + title?: string; + description?: string; + eventDate?: Date; + eventUrl?: string; + customFields?: Record; +}; + +async function updateInvitation(params: UpdateInvitationParams) { + const { id, ...updates } = params; + + if (!id) { + throw new Error("ID is required to update an invitation"); + } + + try { + await db + .update(invitations) + .set({ + ...updates, + updatedAt: new Date(), + }) + .where(eq(invitations.id, id)); + } catch (error) { + console.error("Error updating invitation:", error); + throw new Error("Could not update invitation"); + } +}