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 getUser controller function based on query parameter #2370

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

Prakhar-FF13
Copy link

@Prakhar-FF13 Prakhar-FF13 commented Jan 26, 2025

Date: 26 Jan 2025

Developer Name: Prakhar Kumar


Issue Ticket Number

Description

Refactored get users function in user controller by decomposing into smaller functions based on query parameters.

Documentation Updated?

  • Yes
  • No

Under Feature Flag

  • Yes
  • No

Database Changes

  • Yes
  • No

Breaking Changes

  • Yes
  • No

Development Tested?

  • Yes
  • No

Screenshots

NA

Test Coverage

image image

Additional Notes

Tejas Sir has asked for a peer review for the PR and then design doc can be discussed.

Design Doc - https://docs.google.com/document/d/19cs4FndY-Rh37A7ptZ2db9S-1Mqd2BICwpWV-SZJQv4/edit?tab=t.0#heading=h.o43h9priqbg

TCR - https://dashboard.realdevsquad.com/task-requests/details/?id=65zapL8S5y4mm9M2bPzC

@pankajjs pankajjs changed the title Refactor get user controller function based on query parameter; Issue - 2274 Refactor getUser controller function based on query parameter Jan 26, 2025
@pankajjs pankajjs force-pushed the refactor/user-controller-2274 branch from 26351df to 3b2fefe Compare January 26, 2025 07:38
@Prakhar-FF13 Prakhar-FF13 force-pushed the refactor/user-controller-2274 branch from 3b2fefe to 47b8ba9 Compare January 27, 2025 15:03
…ameters

Signed-off-by: Prakhar Kumar <prakhar.meerut@gmail.com>
Signed-off-by: Prakhar Kumar <prakhar.meerut@gmail.com>
Signed-off-by: Prakhar Kumar <prakhar.meerut@gmail.com>
…for reusability.

2. Updated the integration tests after refactoring of code.

Signed-off-by: Prakhar Kumar <prakhar.meerut@gmail.com>
@Prakhar-FF13 Prakhar-FF13 force-pushed the refactor/user-controller-2274 branch from b733ceb to 220e533 Compare February 5, 2025 14:43
…ryparam

Signed-off-by: Prakhar Kumar <prakhar.meerut@gmail.com>
services/users.js Show resolved Hide resolved
services/users.js Show resolved Hide resolved
services/users.js Show resolved Hide resolved
controllers/users.js Show resolved Hide resolved
controllers/users.js Show resolved Hide resolved
return res.json({
message: "User returned successfully!",
user,
message: user ? "User returned successfully!" : "User not found",
Copy link
Member

Choose a reason for hiding this comment

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

why this change?

count: usersData.length,
users: usersData,
message: "No users found",
users: [],
Copy link
Member

Choose a reason for hiding this comment

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

why we removed the count field?

user = result.user;
if (!result.userExists) {
return null;
}
Copy link
Member

Choose a reason for hiding this comment

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

why are we not throwing error here?

Copy link
Author

Choose a reason for hiding this comment

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

This is the original functionality haven't changed the code, just refactored it, if i throw error here. Tests will fail as it would require null user but we would return a 404 status code.

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.

Refactor getUsers Controller to Avoid Tight Coupling with Query Parameters
3 participants