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

Implement Agent Management System with CRUD Operations, Ticket Assignment, and Role-based Access Control #989

Merged
merged 1 commit into from
Nov 10, 2024

Conversation

IkkiOcean
Copy link
Contributor

Description:

This PR introduces an agent management system that includes:

  • Agent Schema: Defines the structure of agents in the database with fields such as name, email, role, and assigned tickets.
  • Agent Controller: Implements CRUD operations (create, update, retrieve, delete) for agents, including logic for assigning/unassigning tickets.
  • Agent Middleware: Ensures agents' existence, validates permissions, and prevents invalid actions (e.g., assigning tickets to inactive agents).
  • Agent Routes: Adds necessary API routes to manage agents, assign/unassign tickets, and change agent status.

Changes Made:

  1. Agent Schema (models/Agent.js):

    • Defined a schema for the agent, with necessary fields like name, email, assigned tickets, and status.
    • Added validations for the agent's email and status.
  2. Agent Controller (controllers/agentController.js):

    • Implemented controller functions for all CRUD operations (Create, Read, Update, Delete).
    • Added logic to assign/unassign tickets to agents, with checks for agent status and ticket validity.
    • Included helper functions for bulk assignment of tickets and handling ticket updates.
  3. Agent Middleware (middleware/agentMiddleware.js):

    • Added middleware to check if an agent exists before performing any actions (assigning tickets, updating agent details, etc.).
    • Created a role-based access control middleware to ensure agents have the correct permissions (e.g., only admins can delete or update agents).
  4. Agent Routes (routes/agentRoutes.js):

    • Defined the necessary routes to handle agent management:
      • GET /agents: Fetches all agents.
      • POST /agents: Creates a new agent.
      • GET /agents/:id: Fetches an agent's details by ID.
      • PUT /agents/:id: Updates an agent's details by ID.
      • DELETE /agents/:id: Deletes an agent by ID.
      • PATCH /agents/:id/assign-ticket: Assigns a ticket to an agent.
      • PATCH /agents/:id/unassign-ticket: Unassigns a ticket from an agent.
      • PATCH /agents/:id/status: Updates an agent’s status (active/inactive).
      • PATCH /agents/:id/assign-multiple-tickets: Assigns multiple tickets to an agent.
    • Ensured role-based access control for critical routes (admin actions).

Files Changed:

  • models/Agent.js: Agent schema definition.
  • controllers/agentController.js: Controller functions for managing agents.
  • middleware/agentMiddleware.js: Middleware for validating agents and permissions.
  • routes/agentRoutes.js: Routes for interacting with agents.

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 9:26am

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 de797f3 into manikumarreddyu:main Nov 10, 2024
4 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.

Agent Management System for Ticket Handling (Schema, Controller, Middleware, and Routes)
2 participants