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:
55
nuxt4/server/api/lotes/[id].patch.ts
Normal file
55
nuxt4/server/api/lotes/[id].patch.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { updateLote } from '~/server/utils/queries'
|
||||
|
||||
/**
|
||||
* PATCH /api/lotes/:id
|
||||
* Actualiza un lote existente
|
||||
*
|
||||
* Body (todos opcionales):
|
||||
* {
|
||||
* codigo?: string | null,
|
||||
* tipo?: string,
|
||||
* cantidad_kg?: number | null,
|
||||
* lugar_id?: number | null,
|
||||
* meta?: object | null
|
||||
* }
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
const id = getRouterParam(event, 'id')
|
||||
|
||||
if (!id) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'ID de lote requerido',
|
||||
})
|
||||
}
|
||||
|
||||
const body = await readBody(event)
|
||||
|
||||
const lote = await updateLote(id, body)
|
||||
|
||||
if (!lote) {
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: 'Lote no encontrado',
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: lote,
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('Error actualizando lote:', error)
|
||||
|
||||
if (error.statusCode) {
|
||||
throw error
|
||||
}
|
||||
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Error actualizando lote',
|
||||
data: { message: error.message },
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user