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

Backend Implementation for Delivery Person Management #994

Merged
merged 2 commits into from
Nov 10, 2024

Conversation

IkkiOcean
Copy link
Contributor

Overview:
This PR adds a backend solution for managing delivery personnel within the system, implementing features such as CRUD operations, status toggling, and consistent response handling. This functionality allows for seamless management of delivery personnel with validation, secure password handling, and error messaging.


Key Features:

1. Delivery Person Model Definition

  • Schema Design: The DeliveryPerson schema includes fields such as name, email, phone_number, status, assigned_routes, vehicle_details, profile_picture, and password.
  • Field Validations: Email and phone number are validated for uniqueness and format correctness.
  • Password Security: Passwords are hashed using a utility function, ensuring stored passwords are secure.

2. CRUD Operations

  • Create Delivery Person: Adds new personnel with validated input and hashed passwords when provided.
  • Retrieve All Delivery Persons: Fetches a paginated list with selected fields.
  • Retrieve by ID: Provides detailed information about an individual delivery person, including route assignments.
  • Update Delivery Person: Supports updates with validation for fields such as email and phone number, with password hashing if updated.
  • Soft Delete: Allows deactivation of personnel instead of complete deletion by setting their status to inactive.

3. Status Toggling

  • Toggle Active/Inactive Status: Supports controlled toggling between active and inactive statuses based on provided values. Ensures only valid statuses are accepted.

4. Middleware Implementations

  • Authentication Middleware: Ensures that only authenticated users can access these endpoints.
  • Validation Middleware: Enforces input validity, including:
    • Email uniqueness and format
    • Phone number format and length
    • Validity of the status field
    • Route references, where applicable
  • Authorization Middleware: Restricts access to personnel management functions to admin users only.

5. Standardized Response Handling

  • Consistent Responses: Success and error response helper functions provide uniform structure across all endpoints, enhancing readability and consistency.
  • Detailed Feedback: Error responses include specific messages for user-friendly debugging, while success responses confirm actions and return relevant data.

6. Routing and Endpoint Definitions

  • Endpoint Setup: Defined endpoints for each CRUD operation, status toggling, and retrieval with pagination, using RESTful conventions.
  • RESTful Routes:
    • POST /api/delivery-persons: Create
    • GET /api/delivery-persons: Retrieve all (paginated)
    • GET /api/delivery-persons/:id: Retrieve by ID
    • PUT /api/delivery-persons/:id: Update by ID
    • DELETE /api/delivery-persons/:id: Soft delete
    • PATCH /api/delivery-persons/:id/status: Status toggle

Copy link

vercel bot commented Nov 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
agro-tech-ai ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 10, 2024 11:22am

Copy link
Contributor

Thank you for submitting your pull request! 🙌 We'll review it as soon as possible. In the meantime, please ensure that your changes align with our CONTRIBUTING.md. If there are any specific instructions or feedback regarding your PR, we'll provide them here. Thanks again for your contribution! 😊

@manikumarreddyu manikumarreddyu merged commit d19f340 into manikumarreddyu:main Nov 10, 2024
3 checks passed
Copy link
Contributor

🎉 Your pull request has been successfully merged! 🎉 Thank you for your valuable contribution to our project. Your efforts are greatly appreciated. Feel free to reach out if you have any more contributions or if there's anything else we can assist you with. Keep up the fantastic work! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Backend for Delivery Person Management
2 participants