Skip to content

Commit

Permalink
Feature/inv-119 초대장 update api (#36)
Browse files Browse the repository at this point in the history
* feat: implement modify invitation method

* feat: add update updated_at logic

* fix: syntax error in where clause
  • Loading branch information
delphox60 authored Aug 14, 2024
1 parent 117aa9d commit 87e7bd0
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/lib/db/schema/invitations.query.ts
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");
}
}

0 comments on commit 87e7bd0

Please sign in to comment.