seguimos confiando en codex
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m4s

This commit is contained in:
2025-11-22 00:57:13 -06:00
parent 9b1628485f
commit 47c42cbcf3
3 changed files with 52 additions and 26 deletions

View File

@@ -49,25 +49,25 @@
label: 'No hay lotes registrados'
}"
>
<template #codigo-cell="{ row }">
<span class="font-mono font-semibold">{{ row.codigo || '-' }}</span>
<template #codigo-cell="{ getValue }">
<span class="font-mono font-semibold">{{ getValue() || '-' }}</span>
</template>
<template #tipo-cell="{ row }">
<UBadge :color="getTipoColor(row.tipo)" variant="subtle">
{{ getTipoLabel(row.tipo) }}
<template #tipo-cell="{ getValue }">
<UBadge :color="getTipoColor(getValue())" variant="subtle">
{{ getTipoLabel(getValue()) }}
</UBadge>
</template>
<template #cantidad_kg-cell="{ row }">
<span v-if="row.cantidad_kg" class="font-medium">
{{ row.cantidad_kg.toLocaleString('es-AR') }} kg
<template #cantidad_kg-cell="{ getValue }">
<span v-if="getValue()" class="font-medium">
{{ getValue().toLocaleString('es-AR') }} kg
</span>
<span v-else class="text-gray-400">-</span>
</template>
<template #fecha_creado-cell="{ row }">
{{ formatDate(row.fecha_creado) }}
<template #fecha_creado-cell="{ getValue }">
{{ formatDate(getValue()) }}
</template>
<template #actions-cell="{ row }">

View File

@@ -49,17 +49,17 @@
label: 'No hay operaciones registradas'
}"
>
<template #tipo-cell="{ row }">
<template #tipo-cell="{ row, getValue }">
<div class="flex items-center gap-2">
<UIcon :name="getTipoIcon(row.tipo)" class="w-4 h-4" />
<UBadge :color="getTipoColor(row.tipo)" variant="subtle">
{{ getTipoLabel(row.tipo) }}
<UIcon :name="getTipoIcon(getValue())" class="w-4 h-4" />
<UBadge :color="getTipoColor(getValue())" variant="subtle">
{{ getTipoLabel(getValue()) }}
</UBadge>
</div>
</template>
<template #fecha-cell="{ row }">
{{ formatDate(row.fecha) }}
<template #fecha-cell="{ getValue }">
{{ formatDate(getValue()) }}
</template>
<template #actions-cell="{ row }">

View File

@@ -4,6 +4,7 @@ import { useRuntimeConfig } from '#imports'
const { Pool } = pg
let pool: pg.Pool | null = null
let connectionStringLogged = false
function buildConnectionString(): string {
const config = useRuntimeConfig()
@@ -28,6 +29,12 @@ export function getPool(): pg.Pool {
if (!pool) {
const connectionString = buildConnectionString()
if (!connectionStringLogged && process.env.NODE_ENV !== 'production') {
const masked = connectionString.replace(/:\/\/([^:]+):([^@]+)@/, '://$1:*****@')
console.log('[db] Usando connectionString:', masked)
connectionStringLogged = true
}
pool = new Pool({
connectionString,
max: 10,
@@ -58,7 +65,9 @@ export async function query<T = any>(
): Promise<pg.QueryResult<T>> {
const pool = getPool()
const start = Date.now()
const maxRetries = 2
for (let attempt = 0; attempt <= maxRetries; attempt++) {
try {
const result = await pool.query<T>(text, params)
const duration = Date.now() - start
@@ -68,11 +77,28 @@ export async function query<T = any>(
}
return result
} catch (error) {
console.error('Error ejecutando query:', { text, params, error })
} catch (error: any) {
const isAuthError = error?.code === '28P01'
const isConnError = ['ECONNREFUSED', 'ECONNRESET', '57P01'].includes(error?.code)
const shouldRetry = attempt < maxRetries && (isAuthError || isConnError)
console.error('Error ejecutando query:', { text, params, error: error?.message, code: error?.code, attempt })
if (shouldRetry) {
// Pequeño backoff y reintento
await new Promise((res) => setTimeout(res, 500 * (attempt + 1)))
// Resetear pool en auth/conn error por si la contraseña/estado cambia en caliente
try {
await pool.end()
} catch (_) {}
pool = null
continue
}
throw error
}
}
}
/**
* Obtiene un cliente del pool para ejecutar transacciones.