-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/inv-119 초대장 update api (#36)
* feat: implement modify invitation method * feat: add update updated_at logic * fix: syntax error in where clause
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string, any>; | ||
}; | ||
|
||
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"); | ||
} | ||
} |