Skip to content

feat: get user - #38

Merged
daniloamsilva merged 3 commits into
dddfrom
feat/get-user
Dec 15, 2025
Merged

daniloamsilva merged 3 commits into
dddfrom
feat/get-user

Conversation

@daniloamsilva

Copy link
Copy Markdown
Owner

This pull request introduces a new authenticated endpoint for retrieving the current user's details and implements supporting infrastructure for authentication using JWT. It also adds corresponding controller, service, and tests, and improves test reliability.

Authentication infrastructure:

  • Added a global AuthGuard using JWT to secure endpoints by default, with support for public routes via metadata. (src/application/shared/guards/auth.guard.ts, src/app.module.ts) [1] [2] [3]
  • Introduced a Payload decorator to easily access the JWT payload in controllers. (src/application/shared/decorators/payload.decorator.ts)

User endpoint and logic:

  • Added a new GET /users/me endpoint via GetUserController to return the currently authenticated user's details, using the new GetUserService. (src/application/users/controllers/get-user.controller.ts, src/application/users/services/get-user.service.ts, src/application/users/users.module.ts) [1] [2] [3] [4]
  • Implemented a toJSON method on the User entity to exclude sensitive fields like password and tokens from API responses. (src/domain/users/entities/user.entity.ts)

Testing improvements:

  • Added integration and unit tests for the new endpoint and service, covering both successful and failure scenarios. (tests/integration/application/users/controllers/get-user.controller.test.ts, tests/unit/application/users/services/get-user.service.test.ts) [1] [2]

Other improvements:

  • Modified the Jest test script to run tests sequentially for improved reliability. (package.json)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 introduces a new authenticated endpoint for retrieving the current user's details (GET /users/me) and implements the necessary JWT-based authentication infrastructure to secure endpoints globally. The implementation follows domain-driven design principles with proper separation between controllers, services, and domain entities.

Key changes:

  • Added a global AuthGuard that secures all endpoints by default using JWT authentication, with support for marking routes as public
  • Implemented GET /users/me endpoint with corresponding service layer and domain method to safely serialize user data
  • Enhanced test reliability by running Jest tests sequentially

Reviewed changes

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

Show a summary per file
File Description
src/application/shared/guards/auth.guard.ts Implements JWT authentication guard to protect endpoints globally
src/application/shared/decorators/payload.decorator.ts Provides decorator to extract JWT payload from authenticated requests
src/app.module.ts Registers AuthGuard as a global guard for application-wide authentication
src/application/users/controllers/get-user.controller.ts Adds controller for retrieving authenticated user details with OpenAPI documentation
src/application/users/services/get-user.service.ts Implements service to retrieve user by ID and return sanitized data
src/domain/users/entities/user.entity.ts Adds toJSON method to exclude sensitive fields from serialization
src/application/users/users.module.ts Registers new GetUserController and GetUserService
tests/integration/application/users/controllers/get-user.controller.test.ts Adds integration tests for the new endpoint
tests/unit/application/users/services/get-user.service.test.ts Adds unit tests for GetUserService
package.json Modifies test script to run sequentially for improved reliability

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/unit/application/users/services/get-user.service.test.ts Outdated
Comment thread tests/unit/application/users/services/get-user.service.test.ts Outdated
Comment thread src/domain/users/entities/user.entity.ts
@daniloamsilva
daniloamsilva merged commit 6a14092 into ddd Dec 15, 2025
2 checks passed
@daniloamsilva
daniloamsilva deleted the feat/get-user branch December 15, 2025 00:57
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.

2 participants