From 1953be2da0c1a42e61692fcc714d4912e820256d Mon Sep 17 00:00:00 2001 From: Hanzo_dev <2002samudiojohan@gmail.com> Date: Wed, 1 Apr 2026 11:20:48 -0500 Subject: [PATCH] fix(core): resolucion de multiples bugs criticos de backend y visuales --- api/guiones.js | 7 ++++--- backend/api/generar.js | 1 + backend/lib/generador.js | 6 +++++- backend/server.js | 4 ++-- frontend/src/views/AnalysisCreateView.vue | 2 +- frontend/src/views/AnalysisDetailView.vue | 2 +- frontend/src/views/AnalysisListView.vue | 11 ++++++++--- 7 files changed, 22 insertions(+), 11 deletions(-) diff --git a/api/guiones.js b/api/guiones.js index 90d30c1..7509763 100644 --- a/api/guiones.js +++ b/api/guiones.js @@ -3,7 +3,7 @@ import { supabase } from '../backend/lib/supabase.js' export default async function handler(req, res) { if (req.method !== 'GET') return res.status(405).json({ error: 'Método no permitido' }) - const { niche, cliente_id, plataforma, page = 1, limit = 20 } = req.query + const { niche, cliente_id, plataforma, page = 1, limit = 20, todos } = req.query const offset = (Number(page) - 1) * Number(limit) let query = supabase @@ -12,13 +12,14 @@ export default async function handler(req, res) { id, niche, sub_niche, plataforma, url_origen, gancho_texto, gancho_tipo, estructura_narrativa, trigger_emocional, tono, score_engagement, score_virabilidad, score_cialdini, - fecha_analisis, procesado_ok, vistas, likes, compartidos, + fecha_analisis, procesado_ok, error_detalle, vistas, likes, compartidos, tema_principal, resumen_patron `, { count: 'exact' }) - .eq('procesado_ok', true) .order('fecha_analisis', { ascending: false }) .range(offset, offset + Number(limit) - 1) + if (todos !== '1' && todos !== 'true') query = query.eq('procesado_ok', true) + if (niche) query = query.eq('niche', niche) if (cliente_id) query = query.eq('cliente_id', cliente_id) if (plataforma) query = query.eq('plataforma', plataforma) diff --git a/backend/api/generar.js b/backend/api/generar.js index 9fb457d..fbc49bf 100644 --- a/backend/api/generar.js +++ b/backend/api/generar.js @@ -69,6 +69,7 @@ export default async function handler(req, res) { duracion_objetivo, tono, objetivo, estructura_usada: estructura, instrucciones_extra: instrucciones_extra || null, + referencias_ids: referencias_ids.length > 0 ? referencias_ids : (patrones.map ? patrones.map(p => p.id).filter(Boolean) : null), titulo_sugerido: guion.titulo_sugerido, gancho: guion.gancho, desarrollo: guion.desarrollo, diff --git a/backend/lib/generador.js b/backend/lib/generador.js index 9cb385e..5f7daea 100644 --- a/backend/lib/generador.js +++ b/backend/lib/generador.js @@ -98,5 +98,9 @@ Genera el guion con EXACTAMENTE este JSON: .replace(/\n?```$/, '') .trim() - return JSON.parse(jsonLimpio) + try { + return JSON.parse(jsonLimpio) + } catch (err) { + throw new Error(`Error parseando JSON de GPT: ${err.message}. Contenido crudo: ${contenido}`) + } } diff --git a/backend/server.js b/backend/server.js index 9df97a0..75732d7 100644 --- a/backend/server.js +++ b/backend/server.js @@ -33,7 +33,7 @@ app.get('/api/guiones', async (req, res) => { .from('guiones') .select(` id, niche, sub_niche, plataforma, url_origen, - gancho_texto, estructura_narrativa, trigger_emocional, + gancho_texto, gancho_tipo, estructura_narrativa, trigger_emocional, tono, score_engagement, score_virabilidad, score_cialdini, fecha_analisis, procesado_ok, error_detalle, vistas, likes, compartidos, tema_principal, resumen_patron @@ -41,7 +41,7 @@ app.get('/api/guiones', async (req, res) => { .order('fecha_analisis', { ascending: false }) .range(offset, offset + limit - 1) - if (!todos) query = query.eq('procesado_ok', true) + if (todos !== '1' && todos !== 'true') query = query.eq('procesado_ok', true) if (niche) query = query.eq('niche', niche) if (cliente_id) query = query.eq('cliente_id', cliente_id) if (plataforma) query = query.eq('plataforma', plataforma) diff --git a/frontend/src/views/AnalysisCreateView.vue b/frontend/src/views/AnalysisCreateView.vue index 92cac8e..ca33c1e 100644 --- a/frontend/src/views/AnalysisCreateView.vue +++ b/frontend/src/views/AnalysisCreateView.vue @@ -211,7 +211,7 @@

Tiempo estimado: ~15 segundos · GPT-4o + Whisper

diff --git a/frontend/src/views/AnalysisDetailView.vue b/frontend/src/views/AnalysisDetailView.vue index 5a6e5d9..6d799ec 100644 --- a/frontend/src/views/AnalysisDetailView.vue +++ b/frontend/src/views/AnalysisDetailView.vue @@ -89,7 +89,7 @@ analytics Puntaje de Viralidad -
+
guiones.value.filter(g => g.procesado_ok).length) -const totalFallidos = computed(() => guiones.value.filter(g => !g.procesado_ok).length) +const totalOk = ref(0) +const totalFallidos = ref(0) async function cargarDatos() { cargando.value = true @@ -204,11 +204,16 @@ async function cargarDatos() { const params = { page: filtros.value.page, limit: filtros.value.limit } if (filtros.value.niche) params.niche = filtros.value.niche - const [dg, dn] = await Promise.all([ + const [dg, dn, okReq, allReq] = await Promise.all([ api.guiones.listarTodos(params), api.nichos(), + api.guiones.listar({ limit: 1, ...(params.niche ? { niche: params.niche } : {}) }), + api.guiones.listarTodos({ limit: 1, ...(params.niche ? { niche: params.niche } : {}) }), ]) + totalOk.value = okReq.total || 0 + totalFallidos.value = (allReq.total || 0) - (okReq.total || 0) + let lista = dg.guiones if (filtroActivo.value === 'exitosos') lista = lista.filter(g => g.procesado_ok) if (filtroActivo.value === 'fallidos') lista = lista.filter(g => !g.procesado_ok)