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

Refactored authentication and user routes: Moved validatePassword and… #25

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

Conversation

vsrodriguez3
Copy link
Collaborator

… resetPassword to authRoutes; created userRoutes and userController.

Description

  1. What does this PR do?
    This PR organizes routing of user and authentication endpoints. It ensures better file structure.

  2. List of changes:

    • Moved validatePassword and resetPassword routes to authRoutes.js and their logic to authController.js.
    • Created a new route to fetch all users in userRoutes.js and its logic in userController.js.
    • Removed user-related routes from testRoutes.js
    • Updated the app.js file to reflect these changes by including the new userRoutes

Type of Changes

  • Feature update
  • Code refactoring

Acceptance Criteria

  • User-related functionality is properly refactored into userRoutes.js and userController.js.
  • Authentication routes (validatePassword and resetPassword) are moved to authRoutes.js and authController.js.
  • All routes are functional.

Update Screenshots

Before

  • User and auth logic were all over testRoutes.js.
  • No clear separation of concerns between authentication and user-related logic.

After

  • User-related routes in userRoutes.js:
    • GET /api/v1/users
    • PUT /api/v1/users/:id
    • DELETE /api/v1/users/:id
  • Authentication-related routes in authRoutes.js:
    • POST /api/v1/auth/validate-password
    • POST /api/v1/auth/reset-password

Testing Instructions

  1. Start the Server

    • Run npm run dev in the terminal.
  2. Test User Routes

    • Use Postman:
      • Create a New User:
        • URL: POST http://localhost:8000/api/v1/users
        • Body (JSON):
          {
            "name": "John Doe",
            "email": "[email protected]",
            "password": "SecurePassword123",
            "role": "admin",
            "store": "Main Clinic"
          }
        • Expected Response:
          {
            "success": true,
            "message": "User created successfully",
            "data": {
              "name": "John Doe",
              "email": "[email protected]",
              "role": "admin",
              "store": "Main Clinic",
              "_id": "64f1d3e292ebf8a2cd456abc",
              "createdAt": "2024-11-24T12:00:00.000Z",
              "updatedAt": "2024-11-24T12:00:00.000Z"
            }
          }
      • Get All Users:
        • GET http://localhost:8000/api/v1/users
        • No body required.
      • Update User:
        • PUT http://localhost:8000/api/v1/users/:id
        • Body example:
          {
            "role": "inventoryManager"
          }
      • Delete User:
        • DELETE http://localhost:8000/api/v1/users/:id
  3. Test Auth Routes

    • Use Postman:
      • Validate Password:
        • POST http://localhost:8000/api/v1/auth/validate-password
        • Body example:
          {
            "email": "[email protected]",
            "password": "SecurePassword123"
          }
      • Reset Password:
        • POST http://localhost:8000/api/v1/auth/reset-password
        • Body example:
          {
            "email": "[email protected]",
            "currentPassword": "SecurePassword123",
            "newPassword": "NewSecurePassword456"
          }
  4. Verify

    • Ensure all responses return the expected results.

Learnings (Optional)

  • Keeping routes and controllers organized improves code readability and maintainability.

… resetPassword to authRoutes; created userRoutes and userController.
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