Request Management System
Relevant source files
The following files were used as context for generating this wiki page:
The Request Management System is a core module within the ELMEC Mobile App v2 designed to facilitate the creation, tracking, and resolution of technical and commercial requests. It serves as a centralized hub where customers can report issues, request quotes, or seek support, while agents and administrators manage the lifecycle of these requests through a structured workflow.
The system integrates directly with Supabase for data persistence and storage, featuring a robust CRUD (Create, Read, Update, Delete) implementation, a multi-source file attachment system, and real-time status updates. It operates with a strong security layer provided by Row Level Security (RLS) to ensure data privacy based on user roles (Customer, Agent, Admin).
Sources: README.md:10-15, VALIDACION-COMPLETA.md:50-58, FIXES-APLICADOS.md:327-353
Architecture and Workflow
The Request Management System follows a client-server architecture using React Native (Expo) on the frontend and Supabase as the backend. The workflow is driven by state transitions and role-based permissions.
Request Lifecycle
Requests progress through several predefined statuses. The system enforces specific constraints on these values to maintain data integrity.
The valid status values allowed by the database constraints are: nuevo, asignado, en_proceso, pausado, and resuelto.
Sources: REPORTE-EJECUCION-PRUEBAS.md:144-150, REPORTE_FINAL_VALIDACION.md:175-180
System Components
| Component | Description |
|---|---|
| Request Creation Form | UI for users to input title, message, type, and priority. Supports multi-file attachments. |
| File Upload Manager | Handles interactions with expo-image-picker and expo-document-picker to upload blobs to Supabase Storage. |
| Status Monitor | Provides real-time updates and filtering based on request progress. |
| Feedback System | Allows users to provide a 1-5 star rating and textual feedback upon resolution. |
Sources: VALIDACION-COMPLETA.md:50-58, RESUMEN_CONFIGURACION.md:100-115, REPORTE_FINAL_VALIDACION.md:17-25
Data Model and Schema
The system relies on a PostgreSQL table named requests containing 16 columns designed to store both the core request data and operational metadata.
Database Schema Table
| Field | Type | Description |
|---|---|---|
id | UUID | Primary Key. |
titulo | TEXT | Title (5-200 characters). |
mensaje | TEXT | Detailed description (min 10 characters). |
tipo | INTEGER | Numeric identifier for request category (e.g., Sales, Support). |
prioridad | TEXT | Priority level: baja, media, alta, urgente. |
estatus | TEXT | Current state of the request. |
usuario_id | UUID | Foreign Key to the requesting user. |
agente_id | UUID | Foreign Key to the assigned agent. |
archivos | TEXT[] | Array of public URLs for attached files. |
feedback | TEXT | Post-resolution user comments. |
rating | INTEGER | 1-5 star rating. |
metadata | JSONB | Additional info (e.g., created_from: 'mobile'). |
Sources: REPORTE_FINAL_VALIDACION.md:33-55, FIXES-APLICADOS.md:43-55, REPORTE_PRUEBAS_REQUESTS_CRUD.md:105-130
SQL Constraints and Indices
To optimize performance and enforce business logic, the following SQL structures are implemented:
- Check Constraint:
check_rating_rangeensuresratingis between 1 and 5. - Indices: Created on
usuario_id,agente_id,estatus, andprioridadto speed up filtering.
Sources: REPORTE_FINAL_VALIDACION.md:175-190
File Attachment System
The module includes a sophisticated file handling system that supports three primary sources: Local Document Picker, Photo Gallery, and Live Camera.
Upload Sequence
When a user attaches files to a request, the following sequence occurs:
Technical Specifications
- Storage Bucket:
request-files(configured as public for read access). - Size Limit: Maximum 5MB per file.
- Quantity Limit: Maximum 3 files per request.
- Supported Types: Images (JPG, PNG, GIF), Documents (PDF, Word, Excel), and Text files.
Sources: TEST_REPORT.md:95-115, RESUMEN_CONFIGURACION.md:115-125
Security and Permissions
Security is managed via Row Level Security (RLS) policies on both the database tables and the storage buckets. This ensures that users can only interact with data they are authorized to see.
RLS Policies for Requests
| Policy Name | Action | Permission Logic |
|---|---|---|
authenticated_users_can_create | INSERT | Any authenticated user can submit a request. |
users_can_view_own | SELECT | Users see only requests where usuario_id matches their ID. |
agents_can_view_assigned | SELECT | Agents see requests assigned to their agente_id. |
admins_can_view_all | SELECT | Full visibility for admin roles. |
Storage Policies for request-files
- SELECT: Public read access allowed for the bucket.
- INSERT: Authenticated users can upload if
auth.uid()matchesowner_id. - UPDATE/DELETE: Restricted to the owner of the file.
Sources: FIXES-APLICADOS.md:140-155, TEST_REPORT.md:185-205, RESUMEN_FINAL.md:90-105
Implementation Details (Code Analysis)
Request Creation Logic
The system implements strict validation before attempting a database insert. If valid, it processes files first to obtain URLs before creating the final record.
// From app/(tabs)/requests.tsx
const requestData: any = {
titulo: newRequest.titulo.trim(),
mensaje: newRequest.mensaje.trim(),
tipo: newRequest.tipo,
prioridad: newRequest.prioridad,
estatus: 'nuevo',
usuario_id: user.id,
metadata: {
created_from: 'mobile',
app_version: '1.0.0',
},
};
if (uploadedFiles.length > 0) {
requestData.archivos = uploadedFiles.map(file => file.url);
}
Sources: FIXES-APLICADOS.md:58-85
Validation Metrics
The validation process ensures data quality:
- Title: Must be between 5 and 200 characters.
- Message: Minimum 10 characters.
- Agent Assignment: Validates that the assigned agent exists and is active before assignment.
Sources: VALIDACION-COMPLETA.md:50-58, TEST_REPORT.md:55-70
Conclusion
The Request Management System is a mature, fully functional module within the ELMEC v2 project. It successfully bridges the gap between client needs and agent resolution by providing a secure, real-time environment. With its 100% success rate in CRUD operations and a robust file attachment system, it meets the requirements for professional production environments.
Sources: REPORTE_FINAL_VALIDACION.md:210-230, VALIDACION-COMPLETA.md:10-20