Files
seguidorDeLotes/nuxt4/server/api/lotes/index.get.ts
josedario87 30a5e1aafb
Some checks failed
build-and-deploy / build-and-deploy (push) Failing after 1m4s
Corregir imports en archivos API del servidor
- Cambiar imports de ~/server/utils a rutas relativas
- Fix build error en Docker
- Build local verificado exitosamente
2025-11-21 18:46:14 -06:00

38 lines
961 B
TypeScript

import { getLotes } from '../../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 },
})
}
})