Cambios incluidos: - INDICE-DIRECTIVAS-WORKSPACE.yml actualizado - Perfiles de agentes: PERFIL-ML.md, PERFIL-SECURITY.md - Directivas SIMCO actualizadas: - SIMCO-ASIGNACION-PERFILES.md - SIMCO-CCA-SUBAGENTE.md - SIMCO-CONTEXT-ENGINEERING.md - SIMCO-CONTEXT-RESOLUTION.md - SIMCO-DELEGACION-PARALELA.md - Inventarios actualizados: DEVENV-MASTER, DEVENV-PORTS - Documentos de analisis agregados: - Analisis y planes de fix student portal - Analisis scripts BD - Analisis achievements, duplicados, gamification - Auditoria documentacion gamilit - Backlog discrepancias NEXUS - Planes maestros de resolucion - Reportes de ejecucion agregados - Knowledge base gamilit README actualizado - Referencia submodulo gamilit actualizada (commit beb94f7) Validaciones: - Plan validado contra directivas SIMCO-GIT - Dependencias verificadas - Build gamilit: EXITOSO
214 lines
6.1 KiB
Markdown
214 lines
6.1 KiB
Markdown
# EJECUCIÓN COMPLETADA: CORRECCIONES ACHIEVEMENTS PAGE
|
|
|
|
**Fecha:** 2026-01-10
|
|
**Proyecto:** Gamilit
|
|
**Componente:** /achievements (Student Portal)
|
|
**Estado:** ✅ COMPLETADO
|
|
|
|
---
|
|
|
|
## RESUMEN DE EJECUCIÓN
|
|
|
|
### Correcciones Aplicadas
|
|
|
|
| ID | Archivo | Líneas | Estado |
|
|
|----|---------|--------|--------|
|
|
| **CORR-P1-001** | `claim_achievement_reward.sql` | 35-36 | ✅ Aplicado |
|
|
| **CORR-P1-002** | `claim_achievement_reward.sql` | 54-56 | ✅ Aplicado |
|
|
| **CORR-P1-003** | `claim_achievement_reward.sql` | 70-73 | ✅ Aplicado |
|
|
| **CORR-P1-004** | `claim_achievement_reward.sql` | 97-100 | ✅ Aplicado |
|
|
| **CORR-P2-001** | `achievementsStore.ts` | 165-182 | ✅ Aplicado |
|
|
| **CORR-P8-001** | `achievementsAPI.ts` | 340-370 | ✅ Aplicado |
|
|
|
|
---
|
|
|
|
## DETALLE DE CORRECCIONES
|
|
|
|
### 1. Función SQL `claim_achievement_reward.sql`
|
|
|
|
**Problema:** La función usaba columnas que no existen en las tablas DDL:
|
|
- `reward_claimed_at` (no existe en `user_achievements`)
|
|
- `xp_reward` (no existe en `achievements`)
|
|
|
|
**Correcciones aplicadas:**
|
|
|
|
```sql
|
|
-- CORR-P1-001: Verificación de reclamado
|
|
-- ANTES: v_already_claimed := v_user_achievement.reward_claimed_at IS NOT NULL;
|
|
-- DESPUÉS:
|
|
v_already_claimed := v_user_achievement.rewards_claimed = TRUE;
|
|
|
|
-- CORR-P1-002: Actualización de estado
|
|
-- ANTES: SET reward_claimed_at = NOW()
|
|
-- DESPUÉS:
|
|
SET rewards_claimed = TRUE
|
|
|
|
-- CORR-P1-003: Obtención de XP
|
|
-- ANTES: total_xp = total_xp + v_achievement.xp_reward
|
|
-- DESPUÉS:
|
|
total_xp = total_xp + COALESCE((v_achievement.rewards->>'xp')::INTEGER, v_achievement.points_value, 0)
|
|
|
|
-- CORR-P1-004: Retorno de XP
|
|
-- ANTES: v_achievement.xp_reward
|
|
-- DESPUÉS:
|
|
COALESCE((v_achievement.rewards->>'xp')::INTEGER, v_achievement.points_value, 0)
|
|
```
|
|
|
|
**Ubicación:** `/projects/gamilit/apps/database/ddl/schemas/gamification_system/functions/claim_achievement_reward.sql`
|
|
|
|
---
|
|
|
|
### 2. Frontend Store `achievementsStore.ts`
|
|
|
|
**Problema:** Usaba `||` (OR) en lugar de `??` (nullish coalescing), causando que valores de `0` se trataran como falsy.
|
|
|
|
**Corrección aplicada:**
|
|
|
|
```typescript
|
|
// CORR-P2-001: Usar ?? en lugar de ||
|
|
// ANTES:
|
|
mlCoinsReward: ach.rewards?.ml_coins || ach.ml_coins_reward || 0,
|
|
xpReward: ach.rewards?.xp || 0,
|
|
|
|
// DESPUÉS:
|
|
mlCoinsReward: ach.rewards?.ml_coins ?? ach.ml_coins_reward ?? 0,
|
|
xpReward: ach.rewards?.xp ?? ach.points_value ?? 0,
|
|
```
|
|
|
|
**Ubicación:** `/projects/gamilit/apps/frontend/src/features/gamification/social/store/achievementsStore.ts`
|
|
|
|
---
|
|
|
|
### 3. Frontend API `achievementsAPI.ts`
|
|
|
|
**Problema:** El mapeo de categorías no incluía todas las del ENUM `achievement_category`.
|
|
|
|
**Corrección aplicada:**
|
|
|
|
```typescript
|
|
// CORR-P8-001: Categorías agregadas
|
|
streak: 'progress',
|
|
completion: 'progress',
|
|
exploration: 'progress',
|
|
|
|
// También se cambió || a ?? en el retorno
|
|
return categoryMap[backendCategory.toLowerCase()] ?? 'progress';
|
|
```
|
|
|
|
**Ubicación:** `/projects/gamilit/apps/frontend/src/features/gamification/social/api/achievementsAPI.ts`
|
|
|
|
---
|
|
|
|
## VERIFICACIÓN
|
|
|
|
### Archivos Modificados
|
|
|
|
| Archivo | Antes | Después | Verificado |
|
|
|---------|-------|---------|------------|
|
|
| `claim_achievement_reward.sql` | Columnas inexistentes | Columnas correctas | ✅ |
|
|
| `achievementsStore.ts` | `\|\|` operator | `??` operator | ✅ |
|
|
| `achievementsAPI.ts` | 9 categorías | 12 categorías | ✅ |
|
|
|
|
### Sintaxis Verificada
|
|
|
|
- [x] Función SQL sintácticamente correcta
|
|
- [x] TypeScript sin errores de tipo visibles
|
|
- [x] Comentarios de corrección agregados para trazabilidad
|
|
|
|
### Validación Scripts de Base de Datos
|
|
|
|
- [x] Función ubicada correctamente en `ddl/schemas/gamification_system/functions/`
|
|
- [x] Será cargada por `init-database.sh` vía `execute_functions()` (línea 1467)
|
|
- [x] 4 correcciones CORR-P1-00X verificadas en el archivo
|
|
- [x] Estructura SQL válida (BEGIN/END, IF/END IF, RETURN)
|
|
- [ ] Recreación completa de BD pendiente (requiere credenciales superusuario)
|
|
|
|
### Validación Conventional Commits
|
|
|
|
Commits propuestos siguiendo estándares de CONTRIBUTING.md:
|
|
|
|
```
|
|
fix(database): correct column names in claim_achievement_reward function
|
|
|
|
- Replace reward_claimed_at with rewards_claimed (BOOLEAN)
|
|
- Replace xp_reward with COALESCE(rewards->>'xp', points_value, 0)
|
|
- Add CORR-P1-00X comments for traceability
|
|
```
|
|
|
|
```
|
|
fix(frontend): use nullish coalescing for achievement reward values
|
|
|
|
- Change || to ?? in achievementsStore.ts for mlCoinsReward and xpReward
|
|
- Add missing categories (streak, completion, exploration) to achievementsAPI.ts
|
|
- Ensures 0 values are respected as valid rewards
|
|
```
|
|
|
|
---
|
|
|
|
## PRÓXIMOS PASOS RECOMENDADOS
|
|
|
|
### Inmediato (Requerido)
|
|
|
|
1. **Aplicar función SQL en base de datos:**
|
|
```bash
|
|
psql -d gamilit_dev -f /apps/database/ddl/schemas/gamification_system/functions/claim_achievement_reward.sql
|
|
```
|
|
|
|
2. **Verificar compilación de frontend:**
|
|
```bash
|
|
cd /projects/gamilit/apps/frontend
|
|
npm run build
|
|
```
|
|
|
|
3. **Ejecutar tests existentes:**
|
|
```bash
|
|
cd /projects/gamilit/apps/frontend
|
|
npm run test -- --testPathPattern=achievements
|
|
```
|
|
|
|
### Testing (Recomendado)
|
|
|
|
4. **Test funcional de reclamar recompensas:**
|
|
- Crear usuario de prueba
|
|
- Otorgar achievement completado
|
|
- Verificar que `claimRewards` funciona correctamente
|
|
- Verificar que ML Coins y XP se suman al usuario
|
|
|
|
5. **Test de valores cero:**
|
|
- Crear achievement con `ml_coins = 0` y `xp = 0`
|
|
- Verificar que se muestra correctamente (no fallback incorrecto)
|
|
|
|
---
|
|
|
|
## DOCUMENTOS RELACIONADOS
|
|
|
|
| Documento | Estado |
|
|
|-----------|--------|
|
|
| `ANALISIS-ACHIEVEMENTS-PAGE-2026-01-10.md` | ✅ Creado |
|
|
| `PLAN-ACHIEVEMENTS-PAGE-2026-01-10.md` | ✅ Creado |
|
|
| `VALIDACION-PLAN-ACHIEVEMENTS-2026-01-10.md` | ✅ Creado |
|
|
| `EJECUCION-COMPLETADA-ACHIEVEMENTS-2026-01-10.md` | ✅ Creado |
|
|
|
|
---
|
|
|
|
## NOTAS TÉCNICAS
|
|
|
|
### Compatibilidad
|
|
|
|
- Las correcciones son retrocompatibles
|
|
- No se requieren migraciones de datos
|
|
- Los seeds existentes funcionarán sin cambios
|
|
|
|
### Trazabilidad
|
|
|
|
Todas las correcciones incluyen comentarios con formato `CORR-XX-NNN` para facilitar:
|
|
- Búsqueda en el código
|
|
- Auditoría de cambios
|
|
- Reversión si es necesario
|
|
|
|
---
|
|
|
|
**Ejecutado por:** Claude (Arquitecto Técnico)
|
|
**Fecha:** 2026-01-10
|
|
**Estado Final:** ✅ TODAS LAS CORRECCIONES APLICADAS
|