Some checks failed
build-and-deploy / build-and-deploy (push) Failing after 1m47s
- Agregar PostgreSQL 16 con esquema completo - Crear API endpoints para lotes y operaciones - Implementar UI con Nuxt UI (tablas, formularios, trazabilidad) - Agregar datos de ejemplo del flujo completo - Documentar sistema en PLAN_TRAZABILIDAD.md
38 lines
964 B
TypeScript
38 lines
964 B
TypeScript
import { getLotes } from '~/server/utils/queries'
|
|
|
|
/**
|
|
* GET /api/lotes
|
|
* Lista todos los lotes con filtros opcionales
|
|
*
|
|
* Query params:
|
|
* - tipo: filtrar por tipo de lote (uva, despulpado_primera, oreado, etc.)
|
|
* - limit: límite de resultados
|
|
* - offset: offset para paginación
|
|
*/
|
|
export default defineEventHandler(async (event) => {
|
|
try {
|
|
const query = getQuery(event)
|
|
|
|
const filtros = {
|
|
tipo: query.tipo as string | undefined,
|
|
limit: query.limit ? parseInt(query.limit as string) : undefined,
|
|
offset: query.offset ? parseInt(query.offset as string) : undefined,
|
|
}
|
|
|
|
const lotes = await getLotes(filtros)
|
|
|
|
return {
|
|
success: true,
|
|
data: lotes,
|
|
count: lotes.length,
|
|
}
|
|
} catch (error: any) {
|
|
console.error('Error obteniendo lotes:', error)
|
|
throw createError({
|
|
statusCode: 500,
|
|
statusMessage: 'Error obteniendo lotes',
|
|
data: { message: error.message },
|
|
})
|
|
}
|
|
})
|