Implementar sistema completo de trazabilidad de lotes
Some checks failed
build-and-deploy / build-and-deploy (push) Failing after 1m47s
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
This commit is contained in:
53
nuxt4/server/api/lotes/index.post.ts
Normal file
53
nuxt4/server/api/lotes/index.post.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { createLote } from '~/server/utils/queries'
|
||||
|
||||
/**
|
||||
* POST /api/lotes
|
||||
* Crea un nuevo lote
|
||||
*
|
||||
* Body:
|
||||
* {
|
||||
* codigo?: string,
|
||||
* tipo: string,
|
||||
* cantidad_kg?: number,
|
||||
* lugar_id?: number,
|
||||
* meta?: object
|
||||
* }
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
const body = await readBody(event)
|
||||
|
||||
// Validaciones básicas
|
||||
if (!body.tipo) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'El campo "tipo" es requerido',
|
||||
})
|
||||
}
|
||||
|
||||
const lote = await createLote({
|
||||
codigo: body.codigo,
|
||||
tipo: body.tipo,
|
||||
cantidad_kg: body.cantidad_kg,
|
||||
lugar_id: body.lugar_id,
|
||||
meta: body.meta,
|
||||
})
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: lote,
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('Error creando lote:', error)
|
||||
|
||||
if (error.statusCode) {
|
||||
throw error
|
||||
}
|
||||
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Error creando lote',
|
||||
data: { message: error.message },
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user