Skip to content
This repository was archived by the owner on May 12, 2026. It is now read-only.

feat: add user search and discovery endpoint - #26

Closed
clinztouch wants to merge 10 commits into
devfrom
feat/user-search
Closed

feat: add user search and discovery endpoint#26
clinztouch wants to merge 10 commits into
devfrom
feat/user-search

Conversation

@clinztouch

@clinztouch clinztouch commented May 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a public user search and discovery endpoint to OpenProfile.

What changed and why

  • Add SearchQueryDto with validation and sanitization

    • @MinLength(2)
    • @MaxLength(100)
    • trimmed query inputs using @Transform()
  • Add search() method to UsersService

    • PostgreSQL ILIKE case-insensitive search
    • pagination support
    • sorting support
    • filtering by verified and role
  • Add GET /api/users/search endpoint to UsersController

    • decorated with @Public()
    • integrated into Swagger docs
  • Expose createQueryBuilder through UserModelAction

    • enables reusable query composition while preserving module boundaries
  • Add SEARCH_FEATURE.md

    • documents implementation details and feature behavior
  • Ensure response matches existing TransformInterceptor envelope:

{
  "success": true,
  "data": {
    "data": [],
    "meta": {}
  }
}

Why:
This feature enables user discovery workflows across the platform and unblocks frontend search functionality while preserving secure public responses.

Related issues

  • Closes #Stage5

Checklist

  • npm run lint passes
  • npm run build passes
  • Tests added or manually verified
  • Documentation updated

Notes

Implementation followed RFC exactly.

No scope changes were introduced.

Search remains limited to fullName using PostgreSQL ILIKE, with optional filters, sorting, and pagination.

Sensitive fields (email, password, refreshTokenHash, otpHash, deletedAt) are excluded from responses.

Summary by CodeRabbit

Release Notes

  • New Features
    • Added a public user search endpoint enabling discovery by full name
    • Supports filtering results by user role and verification status
    • Includes pagination and flexible sorting options (A-Z, Z-A, newest, oldest)

Review Change Stack

@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented May 10, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@clinztouch has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 6 minutes and 31 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: caf41234-42b9-4d2c-b496-1e28349c0cce

📥 Commits

Reviewing files that changed from the base of the PR and between aa933ce and 106bb9b.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • src/modules/users/users.service.ts
📝 Walkthrough

Walkthrough

This PR implements a complete public user search and discovery endpoint. The changes introduce query parameter validation via SearchQueryDto, service-layer search logic with filtering and pagination, controller route exposure, and comprehensive feature documentation covering API contract, behavioral rules, and testing coverage.

Changes

User Search & Discovery

Layer / File(s) Summary
Search Query Contract
src/modules/users/dto/search-query.dto.ts
Defines SearchQueryDto with validated fields: q (2–100 char trimmed string), page and limit (optional with defaults and bounds), verified and role (optional filters), and sort (predefined sort directions).
Query Builder Support
src/modules/users/actions/user.action.ts
Adds createQueryBuilder(alias) helper method to expose repository query construction; updates findByEmail to return promise directly.
Search Service Implementation
src/modules/users/users.service.ts
Implements search(dto) with case-insensitive full-name ILIKE filtering, optional verified/role filters, configurable sorting, pagination, and response payload containing masked user fields plus pagination metadata.
Controller Route
src/modules/users/users.controller.ts
Adds public GET /users/search endpoint that accepts SearchQueryDto from query parameters and delegates to usersService.search(dto).
Feature Documentation
SEARCH_FEATURE.md
Specifies the public API contract (parameters, response shape, error codes), design rules (ILIKE search, field masking, soft-delete exclusion), code implementation locations, and manual Swagger test coverage.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main feature: a new user search and discovery endpoint.
Description check ✅ Passed The description is comprehensive, covering all template sections with specific details about changes, rationale, related issues, and a completed checklist.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/user-search

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@SEARCH_FEATURE.md`:
- Around line 24-42: The example response uses top-level keys "success", "data"
(array) and "meta" but must follow the documented interceptor envelope shape of
"success" plus "data" being an object with "data" (array) and "meta" (object);
update the example in SEARCH_FEATURE.md so the top-level "meta" is moved under
"data" and the existing "data" array becomes data.data (i.e., structure: success
+ data: { data: [...], meta: {...} }) to match the contract.

In `@src/modules/users/dto/search-query.dto.ts`:
- Around line 44-45: The Transform on the verified property currently coerces
any non-'true' value to false; change it to only convert explicit 'true' or
'false' string values to booleans and leave other inputs untouched so validation
fails. Update the `@Transform` on the verified property (in the SearchQueryDto) to
return true for value === 'true' (case-insensitive), false for value ===
'false', and otherwise return the original value (or undefined/null) so
`@IsBoolean`() will reject invalid strings like 'abc'.

In `@src/modules/users/users.controller.ts`:
- Around line 40-46: The Swagger docs show the search endpoint as protected
because the controller has class-level `@ApiBearerAuth`(); update the
search(`@Query`() dto: SearchQueryDto) method's `@ApiOperation` to include security:
[] (i.e., `@ApiOperation`({ summary: 'Search users by name', security: [] })) so
the OpenAPI docs mark it public while keeping the runtime `@Public`() decorator,
or alternatively remove/move the class-level `@ApiBearerAuth`() and apply it only
to protected methods to avoid documenting public routes as secured.

In `@src/modules/users/users.service.ts`:
- Around line 247-250: The search query using
this.userModelAction.createQueryBuilder('u') currently fetches all User columns
then maps to public fields; restrict the SELECT to only needed columns to avoid
overfetching sensitive data by adding a .select(...) on the query builder for
u.id, u.fullName, u.role, u.isVerified and u.createdAt (use the same column
identifiers used elsewhere in users.service.ts so subsequent getMany() and map
logic still work) and keep the existing .where/.andWhere/getMany() flow.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6c596f28-d485-4876-a16b-b9fdd2ccd592

📥 Commits

Reviewing files that changed from the base of the PR and between 02e0165 and aa933ce.

📒 Files selected for processing (5)
  • SEARCH_FEATURE.md
  • src/modules/users/actions/user.action.ts
  • src/modules/users/dto/search-query.dto.ts
  • src/modules/users/users.controller.ts
  • src/modules/users/users.service.ts

Comment thread SEARCH_FEATURE.md
Comment thread src/modules/users/dto/search-query.dto.ts Outdated
Comment thread src/modules/users/users.controller.ts Outdated
Comment thread src/modules/users/users.service.ts Outdated
@amiabl-programr

Copy link
Copy Markdown
Collaborator

Fix your merge conflicts @clinztouch

@clinztouch

clinztouch commented May 10, 2026 via email

Copy link
Copy Markdown
Collaborator Author

{Calvin Iordye added 9 commits May 11, 2026 12:39
- Add SearchQueryDto with validation (MinLength 2, MaxLength 100, type-safe trim)
- Add search() method to UsersService with ILIKE, filters, sort, and pagination
- Add GET /users/search to UsersController decorated with @public()
- Expose createQueryBuilder via UserModelAction
- Add SEARCH_FEATURE.md documenting the feature
- Response matches TransformInterceptor envelope (success, data, meta)
@clinztouch clinztouch closed this May 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants