From 3a1c3fb7a2798d223e966c285932c54164b80d6d Mon Sep 17 00:00:00 2001
From: josedario87
Date: Fri, 21 Nov 2025 19:43:04 -0600
Subject: [PATCH] =?UTF-8?q?Agregar=20botones=20de=20debug=20temporales=20p?=
=?UTF-8?q?ara=20gesti=C3=B3n=20de=20BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
⚠️ CÓDIGO TEMPORAL - NO ELIMINAR SIN CONSULTAR ⚠️
Backend:
- POST /api/debug/reset-database - Borra todos los datos
- POST /api/debug/seed-database - Carga datos de ejemplo
Frontend:
- Card rojo con advertencias notorias
- Botones: 🗑️ BORRAR TODA LA BD y 🌱 CARGAR DATOS DE EJEMPLO
- Confirmación antes de resetear
- Estados de loading
- Alertas de éxito/error
Todos los archivos marcados con comentarios muy visibles:
⚠️⚠️⚠️ NO ELIMINAR SIN CONSULTAR A DARIO/DRAGANEL/NUCLEO000 ⚠️⚠️⚠️
Útil para desarrollo y debugging del sistema de trazabilidad.
---
nuxt4/app/app.vue | 94 +++++++++++++++++++
nuxt4/server/api/debug/reset-database.post.ts | 52 ++++++++++
nuxt4/server/api/debug/seed-database.post.ts | 56 +++++++++++
3 files changed, 202 insertions(+)
create mode 100644 nuxt4/server/api/debug/reset-database.post.ts
create mode 100644 nuxt4/server/api/debug/seed-database.post.ts
diff --git a/nuxt4/app/app.vue b/nuxt4/app/app.vue
index 3e0d634..c36beb4 100644
--- a/nuxt4/app/app.vue
+++ b/nuxt4/app/app.vue
@@ -37,6 +37,44 @@
+
+
+
+
+
+
+ ⚠️ DEBUG - BOTONES TEMPORALES ⚠️
+
+
+
+ ADVERTENCIA: Estos botones modifican la base de datos directamente.
+
+ NO ELIMINAR este código sin consultar a Dario/Draganel/nucleo000.
+
+
+
+ 🗑️ BORRAR TODA LA BD
+
+
+ 🌱 CARGAR DATOS DE EJEMPLO
+
+
+
+ Resultados en consola (F12). Recarga la página después de usar estos botones.
+
+
+
+
@@ -189,6 +227,62 @@ const handleOperacionFormSuccess = () => {
// Las tablas se recargarán automáticamente
}
+// ⚠️⚠️⚠️ FUNCIONES DE DEBUG - TEMPORALES ⚠️⚠️⚠️
+// NO ELIMINAR SIN CONSULTAR A DARIO/DRAGANEL/NUCLEO000
+const resettingDB = ref(false)
+const seedingDB = ref(false)
+
+const resetDatabase = async () => {
+ if (!confirm('⚠️ ADVERTENCIA: Esto BORRARÁ TODOS LOS DATOS de la base de datos.\n\n¿Estás seguro de continuar?')) {
+ return
+ }
+
+ console.log('🗑️ === RESETEANDO BASE DE DATOS ===')
+ resettingDB.value = true
+
+ try {
+ const response = await fetch('/api/debug/reset-database', {
+ method: 'POST',
+ })
+ const data = await response.json()
+ console.log('Status:', response.status)
+ console.log('Respuesta:', data)
+
+ if (data.success) {
+ alert('✅ Base de datos reseteada exitosamente.\n\nRecarga la página para ver los cambios.')
+ }
+ } catch (error) {
+ console.error('❌ Error:', error)
+ alert('❌ Error reseteando la base de datos. Ver consola.')
+ } finally {
+ resettingDB.value = false
+ }
+}
+
+const seedDatabase = async () => {
+ console.log('🌱 === CARGANDO DATOS DE EJEMPLO ===')
+ seedingDB.value = true
+
+ try {
+ const response = await fetch('/api/debug/seed-database', {
+ method: 'POST',
+ })
+ const data = await response.json()
+ console.log('Status:', response.status)
+ console.log('Respuesta:', data)
+
+ if (data.success) {
+ alert('✅ Datos de ejemplo cargados exitosamente.\n\nRecarga la página para ver los cambios.')
+ }
+ } catch (error) {
+ console.error('❌ Error:', error)
+ alert('❌ Error cargando datos. Ver consola.')
+ } finally {
+ seedingDB.value = false
+ }
+}
+// ⚠️⚠️⚠️ FIN FUNCIONES DE DEBUG ⚠️⚠️⚠️
+
// Funciones de prueba de API
const testGetLotes = async () => {
console.log('=== Probando GET /api/lotes ===')
diff --git a/nuxt4/server/api/debug/reset-database.post.ts b/nuxt4/server/api/debug/reset-database.post.ts
new file mode 100644
index 0000000..6c1cffe
--- /dev/null
+++ b/nuxt4/server/api/debug/reset-database.post.ts
@@ -0,0 +1,52 @@
+/**
+ * ⚠️ ⚠️ ⚠️ ENDPOINT DE DEBUG - TEMPORAL ⚠️ ⚠️ ⚠️
+ *
+ * POST /api/debug/reset-database
+ *
+ * BORRA COMPLETAMENTE TODOS LOS DATOS DE LA BASE DE DATOS
+ *
+ * ⚠️ NO ELIMINAR SIN CONSULTAR A DARIO/DRAGANEL/NUCLEO000 ⚠️
+ *
+ * Este endpoint fue creado para desarrollo y debugging.
+ * Antes de eliminarlo, preguntar si todavía es necesario.
+ */
+
+import { query, getClient } from '../../utils/db'
+
+export default defineEventHandler(async (event) => {
+ try {
+ console.log('⚠️ RESET DATABASE - Borrando todos los datos...')
+
+ const client = await getClient()
+
+ try {
+ await client.query('BEGIN')
+
+ // Truncar todas las tablas en orden
+ await client.query('TRUNCATE TABLE operacion_lotes CASCADE')
+ await client.query('TRUNCATE TABLE operaciones CASCADE')
+ await client.query('TRUNCATE TABLE lotes CASCADE')
+
+ await client.query('COMMIT')
+
+ console.log('✅ Base de datos reseteada exitosamente')
+
+ return {
+ success: true,
+ message: 'Base de datos reseteada. Todas las tablas están vacías.',
+ }
+ } catch (error) {
+ await client.query('ROLLBACK')
+ throw error
+ } finally {
+ client.release()
+ }
+ } catch (error: any) {
+ console.error('❌ Error reseteando base de datos:', error)
+ throw createError({
+ statusCode: 500,
+ statusMessage: 'Error reseteando base de datos',
+ data: { message: error.message },
+ })
+ }
+})
diff --git a/nuxt4/server/api/debug/seed-database.post.ts b/nuxt4/server/api/debug/seed-database.post.ts
new file mode 100644
index 0000000..b258f1d
--- /dev/null
+++ b/nuxt4/server/api/debug/seed-database.post.ts
@@ -0,0 +1,56 @@
+/**
+ * ⚠️ ⚠️ ⚠️ ENDPOINT DE DEBUG - TEMPORAL ⚠️ ⚠️ ⚠️
+ *
+ * POST /api/debug/seed-database
+ *
+ * CARGA LOS DATOS DE EJEMPLO EN LA BASE DE DATOS
+ *
+ * ⚠️ NO ELIMINAR SIN CONSULTAR A DARIO/DRAGANEL/NUCLEO000 ⚠️
+ *
+ * Este endpoint fue creado para desarrollo y debugging.
+ * Antes de eliminarlo, preguntar si todavía es necesario.
+ */
+
+import { getClient } from '../../utils/db'
+import { readFile } from 'fs/promises'
+import { join } from 'path'
+
+export default defineEventHandler(async (event) => {
+ try {
+ console.log('🌱 SEED DATABASE - Cargando datos de ejemplo...')
+
+ const client = await getClient()
+
+ try {
+ // Leer el archivo de seed
+ const seedPath = join(process.cwd(), 'server', 'database', '02_seed.sql')
+ const seedSQL = await readFile(seedPath, 'utf-8')
+
+ await client.query('BEGIN')
+
+ // Ejecutar el script completo de seed
+ await client.query(seedSQL)
+
+ await client.query('COMMIT')
+
+ console.log('✅ Datos de ejemplo cargados exitosamente')
+
+ return {
+ success: true,
+ message: 'Datos de ejemplo cargados: 10 lotes, 7 operaciones, 16 relaciones',
+ }
+ } catch (error) {
+ await client.query('ROLLBACK')
+ throw error
+ } finally {
+ client.release()
+ }
+ } catch (error: any) {
+ console.error('❌ Error cargando datos de ejemplo:', error)
+ throw createError({
+ statusCode: 500,
+ statusMessage: 'Error cargando datos de ejemplo',
+ data: { message: error.message },
+ })
+ }
+})