/** * ⚠️ ⚠️ ⚠️ ENDPOINT DE DEBUG - TEMPORAL ⚠️ ⚠️ ⚠️ * * POST /api/debug/clear-data * * ELIMINA TODOS LOS DATOS DE LAS TABLAS (TRUNCATE) SIN BORRAR LA ESTRUCTURA * * ⚠️ 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' export default defineEventHandler(async (event) => { try { console.log('🧹 CLEAR DATA - Eliminando todos los datos de las tablas...') const client = await getClient() try { await client.query('BEGIN') // Eliminar datos de todas las tablas en orden correcto (respetar foreign keys) console.log(' - Truncando operacion_lotes...') await client.query('TRUNCATE TABLE operacion_lotes CASCADE') console.log(' - Truncando operaciones...') await client.query('TRUNCATE TABLE operaciones CASCADE') console.log(' - Truncando lotes...') await client.query('TRUNCATE TABLE lotes CASCADE') await client.query('COMMIT') console.log('✅ Datos eliminados exitosamente. Las tablas están vacías pero la estructura se mantiene.') return { success: true, message: 'Datos eliminados exitosamente. Las tablas están vacías.', } } catch (error) { await client.query('ROLLBACK') throw error } finally { client.release() } } catch (error: any) { console.error('❌ Error limpiando datos:', error) throw createError({ statusCode: 500, statusMessage: 'Error limpiando datos', data: { message: error.message }, }) } })