Skip to content

fix(WEBAPP-117): find user by id adjustments#119

Merged
HermanPlay merged 2 commits intomasterfrom
webapp-117
Jun 2, 2025
Merged

fix(WEBAPP-117): find user by id adjustments#119
HermanPlay merged 2 commits intomasterfrom
webapp-117

Conversation

@TheRealSeber
Copy link
Contributor

No description provided.

@github-actions
Copy link

github-actions bot commented May 31, 2025

Coverage report

The coverage rate went from 88.0% to 88.27% ⬆️

The branch rate is 72.41%

100% of new lines are covered.

Diff Coverage details (click to unfold)

app/api/auth/reset-password/route.ts

100.0% of new lines are covered

@TheRealSeber TheRealSeber requested a review from Copilot May 31, 2025 15:45
@TheRealSeber
Copy link
Contributor Author

This pull request refactors the user-related data fetching logic to separate concerns and enhance modularity. The most significant change is the introduction of new functions in lib/users/actions.ts to handle specific aspects of user and listing data retrieval. Additionally, the findUserByIdWithListings function replaces the previous findUserById function in various components to support fetching more detailed user data, including listings and categories.

Refactoring and Modularization of User Data Fetching (lib/users/actions.ts):

  • Introduced findUserByIdWithListings: A new function that fetches user data along with listing counts, active listings, and categories. This function consolidates multiple data-fetching operations into a single call for user profile pages. (Ff0a74c8L137R137)
  • Created getUserListingsCounts: A dedicated function to retrieve counts of active, archived, and sold listings for a specific user. This separates the logic for counting listings from other operations.
  • Added getUserActiveListings: A function to fetch paginated active listings with attached photos, ensuring each listing has exactly one photo. This improves the clarity and reusability of the active listing retrieval logic.
  • Implemented getAllCategories: A helper function to fetch all listing categories for display purposes. This simplifies category retrieval for components that need it.

Updates to Components:

These changes improve the maintainability and scalability of the codebase by isolating specific data-fetching concerns into modular functions.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors user-fetching logic by splitting the record retrieval and listing aggregation into focused functions, and updates components to use the new combined findUserByIdWithListings API.

  • Separated basic user fetch (findUserById) from listing counts and active listings retrieval
  • Introduced getUserListingsCounts, getUserActiveListings, attachPhotosToListings, and getAllCategories
  • Updated UI components to call findUserByIdWithListings instead of the old findUserById

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
lib/users/actions.ts Split user lookup and listing queries, added helper functions
components/listings/user-listings.tsx Swapped in findUserByIdWithListings for listing-aware user fetch
app/(dashboard)/user/[id]/page.tsx Updated profile page to use the combined listing API
Comments suppressed due to low confidence (1)

lib/users/actions.ts:238

  • Consider adding unit tests for findUserByIdWithListings and its helper functions (getUserListingsCounts, getUserActiveListings, attachPhotosToListings) to ensure correct data fetching and transformation.
export async function findUserByIdWithListings(

@TheRealSeber TheRealSeber requested a review from Copilot May 31, 2025 16:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses WEBAPP-117 by adjusting how users are fetched by ID across the codebase and refactors related functions for improved consistency. Key changes include:

  • Renaming and replacing the findUserById function with getUserById and findUserByIdWithListings.
  • Updating test files, API routes, and dashboard pages to use the new function names.
  • Refactoring listing-related queries in lib/users/actions.ts for clarity and performance improvements.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/setup.js Updated user action mocks to use getUserById
tests/api/auth/reset-password.test.ts Updated function imports and mocks from findUserById to getUserById
lib/users/actions.ts Refactored user query functions and introduced listing counts functions
components/listings/user-listings.tsx Updated the user listings function import to use findUserByIdWithListings
app/api/auth/reset-password/route.ts Updated function imports from findUserById to getUserById
app/(dashboard)/user/edit/page.tsx Replaced findUserById with getUserById for user profile fetching
app/(dashboard)/user/[id]/page.tsx Replaced findUserById with findUserByIdWithListings for richer user data

@HermanPlay HermanPlay linked an issue Jun 1, 2025 that may be closed by this pull request
8 tasks
@HermanPlay HermanPlay merged commit db051fa into master Jun 2, 2025
1 check passed
@HermanPlay HermanPlay deleted the webapp-117 branch June 2, 2025 09:06
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.

[WebApp] Refactor find user by id function

3 participants

Comments