Request Management
Relevant source files
The following files were used as context for generating this wiki page:
The Request Management module is a core feature of the ElmecV2 application, providing a comprehensive system for users to create, track, and manage support, sales, and quotation requests. It facilitates communication between customers and agents, supports file attachments, and includes a complete lifecycle for requests from creation to resolution. The system is built on Supabase, leveraging its database for storage and Row Level Security (RLS) for access control.
This module integrates with other parts of the application, such as the Chat Management system, allowing users to initiate conversations directly from a request.
Data Model (requests table)
The entire request management system is centered around the requests table in the Supabase database. This table stores all information related to a request, including its content, status, priority, associated users, and attached files.
Entity Relationship Diagram
The following diagram shows the requests table and its relationship with the users table. A request is created by one user (usuario_id) and can be assigned to another user (agente_id).
Table Schema
The requests table consists of 16 columns, including fields for content, status tracking, user feedback, and file attachments.
| Column | Data Type | Description |
|---|---|---|
id | uuid (PK) | Unique identifier for the request. |
created_at | timestamp | Timestamp when the request was created. |
updated_at | timestamp | Timestamp of the last update. |
titulo | text | The title of the request (validated 5-200 characters). |
mensaje | text | The detailed message body of the request (min 10 characters). |
tipo | integer | Foreign key representing the request type (e.g., Sales, Support). |
prioridad | text | The priority level ('baja', 'media', 'alta', 'urgente'). |
estatus | text | The current status in the lifecycle (e.g., 'nuevo', 'resuelto'). |
usuario_id | uuid (FK) | The ID of the user who created the request. |
agente_id | uuid (FK) | The ID of the agent assigned to the request. |
tags | text[] | An array of tags for categorization. |
metadata | jsonb | JSON object for storing extra information, like app version. |
archivos | text[] | An array of public URLs for files uploaded to Supabase Storage. |
feedback | text | Customer feedback after the request is resolved. |
rating | integer | A 1-5 star rating provided by the customer. |
fecha_vencimiento | date | Due date for the request. |
Sources: REPORTE_FINAL_VALIDACION.md, REPORTE_PRUEBAS_REQUESTS_CRUD.md, TEST_REPORT.md
Request Lifecycle and Statuses
A request progresses through a defined set of statuses, from initial creation to final resolution. The estatus field in the requests table tracks this lifecycle.
Status Flow Diagram
This diagram illustrates the possible state transitions for a request.
Status Definitions
| Status | Value | Description |
|---|---|---|
| New | nuevo | The initial state of a request after creation. |
| Assigned | asignado | The request has been assigned to an agent. |
| In Progress | en_proceso | The assigned agent is actively working on the request. |
| Paused | pausado | Work on the request has been temporarily stopped. |
| Resolved | resuelto | The request has been completed and a solution provided. |
Sources: constants/commons.ts:58-65, REPORTE-EJECUCION-PRUEBAS.md
Core Functionality (CRUD)
The module provides full Create, Read, Update, and Delete (CRUD) functionality for requests, managed through the application's UI and tested via dedicated scripts.
Sources: scripts/test-requests-crud.js, app/(tabs)/requests.tsx
Create Request
A new request is created via a form in the requests.tsx component. The process involves frontend validation, optional file uploads, and an insert operation into the Supabase requests table.
Creation Flow
The sequence diagram below details the steps involved in creating a new request with file attachments.
Frontend Validations
Before submission, the frontend performs several checks:
- Title Length: Must be between 5 and 200 characters.
- Message Length: Must be at least 10 characters.
- Agent Exists: Validates that the selected agent exists and is active.
Sources: TEST_REPORT.md
Read Requests
Requests are fetched and displayed in a list. The application provides functionality to filter requests by status and priority. The test-requests-crud.js script validates the ability to read a list of requests, retrieve a specific request by ID, and filter results.
- List All: Fetches all requests visible to the current user based on RLS policies.
- Get Specific: Retrieves a single request, including related user and agent data.
- Filtering: Supports filtering by
estatusandprioridad.
Sources: scripts/test-requests-crud.js:88-129, app/(tabs)/requests.tsx:402-463
Update Requests
Existing requests can be modified. Common updates include changing the status, priority, or adding feedback and a rating upon resolution.
- Status Change: The
estatusfield is updated as the request moves through its lifecycle. - Priority Change: The
prioridadcan be escalated or de-escalated. - Feedback & Rating: After a request is
resuelto, the customer can add comments to thefeedbackcolumn and a value to theratingcolumn.
Sources: scripts/test-requests-crud.js:134-168, REPORTE_FINAL_VALIDACION.md
Delete Requests
Requests can be deleted from the system. This operation is also protected by RLS policies to ensure users can only delete appropriate data.
Sources: scripts/test-requests-crud.js:173-190
File Attachments
The system allows users to attach up to 3 files (max 5MB each) to a request. The process is handled by the FileUploadComponent and integrates with expo-image-picker and expo-document-picker.
File Upload Flow
- Sources: Users can select images from the gallery, take a new photo with the camera, or pick a document from the file system.
- Storage: Files are uploaded to a private Supabase Storage bucket named
request-files. - Database: The public URLs of the uploaded files are stored in the
archivos(TEXT[]) column of therequeststable.
Sources: RESUMEN_FINAL.md, TEST_REPORT.md
Security (Row Level Security)
Access to the requests table is controlled by Supabase's Row Level Security (RLS) policies. These policies ensure that users can only view and manipulate data they are authorized to access.
authenticated_users_can_create_requests: Allows any logged-in user to create a new request.users_can_view_own_requests: Allows users to view the requests they have created.agents_can_view_assigned_requests: Allows agents to view requests that are assigned to them.admins_can_view_all_requests: Allows users with an 'admin' role to view all requests in the system.
Sources: FIXES-APLICADOS.md
Constants and Enums
The module uses predefined constants for request types, statuses, and priorities to ensure data consistency.
Request Types
| Type | ID |
|---|---|
| Sales | 1 |
| Support | 2 |
| Quotation | 3 |
| Order Tracking | 4 |
Sources: constants/commons.ts:46-51
Priorities
| Priority | Value |
|---|---|
| Low | baja |
| Medium | media |
| High | alta |
| Urgent | urgente |
Sources: app/(tabs)/requests.tsx:1069-1089, TEST_REPORT.md
Conclusion
The Request Management module is a robust and well-structured feature that forms the backbone of the ElmecV2 application. It provides a complete lifecycle for handling customer inquiries, supported by a secure data model, file attachment capabilities, and clear status transitions. The use of Supabase for the backend, combined with a React Native frontend, delivers a comprehensive solution for creating, tracking, and resolving requests efficiently.