Skip to content
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

refactor(attendees.ts): update total attendees query #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

IndySeh
Copy link

@IndySeh IndySeh commented Jul 24, 2024

Description


  • Refactored the code to use the count() function for calculating totalAttendees directly in the query.
  • Removed the previous implementation that used the reduce function to calculate the total number of attendees.

Changes Made


  • Updated the query to use count(attendees.id) for counting total attendees.
  • Removed the reduce function logic and replaced it with the new method of extracting totalAttendees.
const counts = await db
      .select({
        totalAttendees: count(attendees.id),
      })
      .from(events)
      .leftJoin(rsvps, eq(rsvps.eventId, events.id))
      .leftJoin(attendees, eq(attendees.id, rsvps.attendeeId))
      .where(eq(events.createdById, userId))
      .execute()

    const [firstCount] = counts
    const totalAttendees = firstCount.totalAttendees | 0

    return totalAttendees

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant