Skip to content

Commit

Permalink
fix: invitation response create
Browse files Browse the repository at this point in the history
  • Loading branch information
Gukhee Jo committed Aug 20, 2024
1 parent 6aa9629 commit 45ad8e9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
37 changes: 24 additions & 13 deletions src/lib/db/schema/invitation_response.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import {
type InvitationResponseInsert,
} from "~/lib/db/schema/invitation_response";

type CreateInvitationResponseParams = Omit<
InvitationResponseInsert,
"id" | "created_at"
>;

export async function getAllInvitationResponses() {
return await db.select().from(invitationResponses);
}
Expand Down Expand Up @@ -38,18 +43,24 @@ export async function getInvitationResponseStats() {
}

export async function createInvitationResponses(
participant_name: string,
attendance: boolean,
reason?: string,
) {
const data: InvitationResponseInsert = {
id: nanoid(),
participant_name: participant_name,
attendance: attendance,
reason: reason,
created_at: new Date(),
};
params: CreateInvitationResponseParams,
): Promise<InvitationResponseInsert> {
const id = nanoid();
const currentTimestamp = new Date();

try {
const res = await db
.insert(invitationResponses)
.values({
...params,
id,
created_at: currentTimestamp,
})
.returning();

const res = db.insert(invitationResponses).values(data);
return res;
return res[0];
} catch (error) {
console.error("Error creating invitatio response:", error);
throw new Error("Could not create invitation response");
}
}
4 changes: 3 additions & 1 deletion src/lib/db/schema/invitation_response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { invitations } from "~/lib/db/schema/invitations";

export const invitationResponses = pgTable("invitation_response", {
id: text("id").primaryKey().notNull(),
invitation_id: text("invitation_id").references(() => invitations.id),
invitation_id: text("invitation_id")
.references(() => invitations.id)
.notNull(),
participant_name: text("participant_name").notNull(),
attendance: boolean("attendance").notNull(),
reason: text("reason"),
Expand Down

0 comments on commit 45ad8e9

Please sign in to comment.