- 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>
132 lines
4.3 KiB
Markdown
132 lines
4.3 KiB
Markdown
# 06-DOCUMENTACION - Phase 1 MVP Implementation
|
|
|
|
## Resumen Ejecutivo
|
|
|
|
Se completó la implementación de los componentes finales del Phase 1 MVP:
|
|
|
|
1. **Servicio de Notificaciones**: Sistema unificado para envío de notificaciones a través de múltiples canales (WebSocket, email, push).
|
|
|
|
2. **Job de Distribución**: Cron job diario para cálculo y distribución automática de rendimientos de inversión.
|
|
|
|
## API de Notificaciones
|
|
|
|
### Endpoints
|
|
|
|
| Método | Ruta | Descripción |
|
|
|--------|------|-------------|
|
|
| GET | /api/v1/notifications | Listar notificaciones del usuario |
|
|
| GET | /api/v1/notifications/unread-count | Obtener conteo de no leídas |
|
|
| GET | /api/v1/notifications/preferences | Obtener preferencias |
|
|
| PATCH | /api/v1/notifications/preferences | Actualizar preferencias |
|
|
| POST | /api/v1/notifications/read-all | Marcar todas como leídas |
|
|
| PATCH | /api/v1/notifications/:id/read | Marcar una como leída |
|
|
| DELETE | /api/v1/notifications/:id | Eliminar notificación |
|
|
|
|
### Tipos de Notificación
|
|
|
|
| Tipo | Descripción | Canales Default |
|
|
|------|-------------|-----------------|
|
|
| alert_triggered | Alerta de precio activada | in_app, email, push |
|
|
| trade_executed | Orden ejecutada | in_app, email |
|
|
| deposit_confirmed | Depósito confirmado | in_app, email |
|
|
| withdrawal_completed | Retiro completado | in_app, email |
|
|
| distribution_received | Rendimiento recibido | in_app, email |
|
|
| system_announcement | Anuncio del sistema | in_app |
|
|
| security_alert | Alerta de seguridad | in_app, email, push |
|
|
| account_update | Actualización de cuenta | in_app |
|
|
|
|
### Preferencias de Usuario
|
|
|
|
```typescript
|
|
interface UserNotificationPreferences {
|
|
emailEnabled: boolean; // Recibir emails
|
|
pushEnabled: boolean; // Recibir push
|
|
inAppEnabled: boolean; // Mostrar in-app
|
|
smsEnabled: boolean; // Recibir SMS
|
|
quietHoursStart?: string; // Inicio horas silenciosas (HH:MM)
|
|
quietHoursEnd?: string; // Fin horas silenciosas (HH:MM)
|
|
disabledTypes: string[]; // Tipos deshabilitados
|
|
}
|
|
```
|
|
|
|
## Job de Distribución
|
|
|
|
### Configuración
|
|
|
|
- **Frecuencia**: Diaria a las 00:00 UTC
|
|
- **Método de Cálculo**:
|
|
- Tasa mensual promedio / 30 días
|
|
- Varianza diaria: -15% a +35%
|
|
- **Performance Fee**: Aplicado sobre rendimiento bruto
|
|
- **Mínimo distribución**: > $0.01
|
|
|
|
### Productos y Tasas
|
|
|
|
| Producto | Retorno Mensual | Performance Fee |
|
|
|----------|-----------------|-----------------|
|
|
| Atlas | 3% - 5% | 20% |
|
|
| Orion | 5% - 10% | 20% |
|
|
| Nova | 10% - 20% | 20% |
|
|
|
|
### Flujo de Distribución
|
|
|
|
```
|
|
1. Obtener cuentas activas con balance > 0
|
|
2. Para cada cuenta:
|
|
a. Calcular retorno diario con varianza
|
|
b. Si retorno > 0:
|
|
- Calcular fee
|
|
- Actualizar balance
|
|
- Registrar transacción
|
|
- Registrar en distribution_history
|
|
- Enviar notificación
|
|
3. Registrar resumen en distribution_runs
|
|
```
|
|
|
|
## Integración con Alertas
|
|
|
|
El servicio de alertas ahora envía notificaciones automáticamente cuando se activa una alerta de precio:
|
|
|
|
```typescript
|
|
// alerts.service.ts - triggerAlert()
|
|
await notificationService.sendAlertNotification(alert.userId, {
|
|
symbol: alert.symbol,
|
|
condition: alert.condition,
|
|
targetPrice: alert.price,
|
|
currentPrice,
|
|
note: alert.note,
|
|
});
|
|
```
|
|
|
|
## Próximos Pasos Sugeridos
|
|
|
|
1. **DDL**: Crear tablas `notifications`, `user_push_tokens`, `investment.distribution_history`, `investment.distribution_runs`
|
|
|
|
2. **Push Notifications**: Integrar con Firebase Cloud Messaging (FCM) para Android/Web y APNS para iOS
|
|
|
|
3. **SMS**: Integrar Twilio para notificaciones SMS (ya en package.json)
|
|
|
|
4. **Testing**: Crear tests unitarios para notification.service y distribution.job
|
|
|
|
5. **Admin UI**: Panel para ver estadísticas de distribuciones
|
|
|
|
## Archivos de Referencia
|
|
|
|
| Archivo | Propósito |
|
|
|---------|-----------|
|
|
| notification.service.ts | Servicio core de notificaciones |
|
|
| distribution.job.ts | Job de distribución de rendimientos |
|
|
| alerts.service.ts | Integración de alertas con notificaciones |
|
|
|
|
## Checklist Final
|
|
|
|
- [x] Servicio de notificaciones creado
|
|
- [x] API REST de notificaciones expuesta
|
|
- [x] Integración con WebSocket para real-time
|
|
- [x] Templates de email implementados
|
|
- [x] Job de distribución implementado
|
|
- [x] Integración con alerts service
|
|
- [x] Graceful shutdown implementado
|
|
- [x] TypeScript compila sin errores (en archivos nuevos)
|
|
- [x] Documentación CAPVED completa
|