-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inv-54 참석 여부 조회 #6
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
국희 이제 풀스택 개발자 해도 되겠다 👍🏻👍🏻
수고했습니다 🙌🏻
queryKey: ["invitationResponseStats"], | ||
queryFn: () => getInvitationResponseStats(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
음 이상하다 이건 서버 사이드에서 prefetch 안해도 괜찮나?
잘 동작하면 이 코멘트 무시해 주세요.
const result = await db | ||
.select({ | ||
totalResponses: sql`COUNT(*)`.as("total_responses"), | ||
attendingCount: | ||
sql`SUM(CASE WHEN ${invitationResponses.attendance} = true THEN 1 ELSE 0 END)`.as( | ||
"attending_count", | ||
), | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sql
을 깡통으로 쓰기 보단 drizzle ORM이 제공해주는 helper를 활용하면,
더 안전하고 가독성이 좋을 것 같은데 한번 검토해 봐주세요!
sql
을 쓰는게 편하다면 지금도 좋습니다~!
https://orm.drizzle.team/learn/guides/count-rows
https://orm.drizzle.team/docs/select#aggregations-helpers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오오 활용해서 수정해볼게요~!
export async function getAllInvitationResponses() { | ||
return await db.select().from(invitationResponses); | ||
} | ||
|
||
export async function getInvitationResponseById(id: InvitationResponse["id"]) { | ||
const responses = await db | ||
.select() | ||
.from(invitationResponses) | ||
.where(eq(invitationResponses.id, id)); | ||
return responses[0]; | ||
} | ||
|
||
export async function getInvitationResponseStats() { | ||
const result = await db | ||
.select({ | ||
totalResponses: sql`COUNT(*)`.as("total_responses"), | ||
attendingCount: | ||
sql`SUM(CASE WHEN ${invitationResponses.attendance} = true THEN 1 ELSE 0 END)`.as( | ||
"attending_count", | ||
), | ||
}) | ||
.from(invitationResponses); | ||
|
||
return { | ||
totalResponses: Number(result[0].totalResponses), | ||
attendingCount: Number(result[0].attendingCount), | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JavaScript는 외부 리소스를 접근할 때 try catch를 감싸주어야 합니다
익숙치 않으시면 제가 나중에 감싸놓을게요 🐝
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 반영하겠습니당~~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
일단 액션 호출하는 단(클라이언트 단)에서 try catch 묶어도 되니 추후 개선으로 가도 될 것 같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앗 넵넵! 화요일에 창완오빠랑도 클라이언트 단에서 처리하는 것으로 이야기했습니당
TypeScript도 낯설텐데 프론트까지.. 국희님께 프론트엔드 배우러 가겠습니ㄷ..r |
오예 고생하셨습니다 LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
프론트 개발자가 네명...!!
수고하셨습니다👍
작업 내용
아래 항목 확인할 수 있는 쿼리 작성하였습니다.
playground/invitation-response
에서 확인 가능합니다. (neon dev branch 사용)