- Create TASK-2026-01-25-NOTIFICACIONES-COMPLETAS with full CAPVED docs - Update DATABASE_INVENTORY with auth.notifications, auth.user_push_tokens, investment.distribution_history, investment.distribution_runs tables - Update BACKEND_INVENTORY with push-token endpoints, firebase.client, and unit tests - Update FRONTEND_INVENTORY with notification components, store, service - Update MASTER_INVENTORY with updated totals - Update _INDEX.yml with new task entry Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
100 lines
2.8 KiB
Markdown
100 lines
2.8 KiB
Markdown
# 02-ANALISIS - Phase 1 MVP Implementation
|
|
|
|
## Análisis de Dependencias
|
|
|
|
### Servicios Existentes Analizados
|
|
|
|
1. **WebSocket Manager** (`src/core/websocket/websocket.server.ts`)
|
|
- Método `sendToUser(userId, message)` disponible
|
|
- Soporte para canales privados (`user:*`, `account:*`)
|
|
- Heartbeat y reconexión automática
|
|
|
|
2. **Email Service** (`src/modules/auth/services/email.service.ts`)
|
|
- Nodemailer configurado
|
|
- Templates HTML existentes
|
|
- Patrón a replicar para notificaciones
|
|
|
|
3. **Alerts Service** (`src/modules/trading/services/alerts.service.ts`)
|
|
- TODO en línea 280 para integración de notificaciones
|
|
- Método `triggerAlert()` necesita enviar notificaciones
|
|
|
|
4. **Product Service** (`src/modules/investment/services/product.service.ts`)
|
|
- Productos Atlas/Orion/Nova con tasas de retorno
|
|
- `targetReturnMin/Max` para cálculo de distribuciones
|
|
|
|
### Tablas de Base de Datos Esperadas
|
|
|
|
```sql
|
|
-- Notificaciones
|
|
CREATE TABLE notifications (
|
|
id UUID PRIMARY KEY,
|
|
user_id UUID REFERENCES users(id),
|
|
type VARCHAR(50),
|
|
title VARCHAR(255),
|
|
message TEXT,
|
|
priority VARCHAR(20),
|
|
data JSONB,
|
|
action_url VARCHAR(255),
|
|
icon_type VARCHAR(20),
|
|
channels TEXT[],
|
|
is_read BOOLEAN DEFAULT FALSE,
|
|
read_at TIMESTAMPTZ,
|
|
created_at TIMESTAMPTZ DEFAULT NOW()
|
|
);
|
|
|
|
-- Push tokens
|
|
CREATE TABLE user_push_tokens (
|
|
id UUID PRIMARY KEY,
|
|
user_id UUID REFERENCES users(id),
|
|
token TEXT,
|
|
platform VARCHAR(20),
|
|
is_active BOOLEAN DEFAULT TRUE,
|
|
created_at TIMESTAMPTZ DEFAULT NOW()
|
|
);
|
|
|
|
-- Distribution history
|
|
CREATE TABLE investment.distribution_history (
|
|
id UUID PRIMARY KEY,
|
|
account_id UUID REFERENCES investment.accounts(id),
|
|
product_id UUID REFERENCES investment.products(id),
|
|
distribution_date DATE,
|
|
gross_amount DECIMAL(18,2),
|
|
fee_amount DECIMAL(18,2),
|
|
net_amount DECIMAL(18,2),
|
|
balance_before DECIMAL(18,2),
|
|
balance_after DECIMAL(18,2),
|
|
created_at TIMESTAMPTZ DEFAULT NOW()
|
|
);
|
|
|
|
-- Distribution runs (auditoría)
|
|
CREATE TABLE investment.distribution_runs (
|
|
id UUID PRIMARY KEY,
|
|
run_date DATE,
|
|
total_accounts INTEGER,
|
|
successful_count INTEGER,
|
|
failed_count INTEGER,
|
|
total_gross_amount DECIMAL(18,2),
|
|
total_fee_amount DECIMAL(18,2),
|
|
total_net_amount DECIMAL(18,2),
|
|
started_at TIMESTAMPTZ,
|
|
completed_at TIMESTAMPTZ,
|
|
duration_ms INTEGER,
|
|
created_at TIMESTAMPTZ DEFAULT NOW()
|
|
);
|
|
```
|
|
|
|
## Patrones Identificados
|
|
|
|
1. **Service Classes**: Singleton con export de instancia
|
|
2. **Controllers**: Funciones async con AuthenticatedRequest
|
|
3. **Routes**: Router con authHandler helper
|
|
4. **Error Handling**: try/catch con logger
|
|
|
|
## Riesgos Identificados
|
|
|
|
| Riesgo | Mitigación |
|
|
|--------|------------|
|
|
| Tablas DB no existen | Diseño flexible que maneja errores |
|
|
| Push tokens vacíos | Log debug, no error |
|
|
| Distribución negativa | Skip silencioso en días negativos |
|