Some checks failed
build-and-deploy / build-and-deploy (push) Failing after 1m4s
- Cambiar imports de ~/server/utils a rutas relativas - Fix build error en Docker - Build local verificado exitosamente
45 lines
966 B
TypeScript
45 lines
966 B
TypeScript
import { getOperacionConLotes } from '../../utils/queries'
|
|
|
|
/**
|
|
* GET /api/operaciones/:id
|
|
* Obtiene una operación específica con sus lotes relacionados (inputs y outputs)
|
|
*/
|
|
export default defineEventHandler(async (event) => {
|
|
try {
|
|
const id = getRouterParam(event, 'id')
|
|
|
|
if (!id) {
|
|
throw createError({
|
|
statusCode: 400,
|
|
statusMessage: 'ID de operación requerido',
|
|
})
|
|
}
|
|
|
|
const operacion = await getOperacionConLotes(id)
|
|
|
|
if (!operacion) {
|
|
throw createError({
|
|
statusCode: 404,
|
|
statusMessage: 'Operación no encontrada',
|
|
})
|
|
}
|
|
|
|
return {
|
|
success: true,
|
|
data: operacion,
|
|
}
|
|
} catch (error: any) {
|
|
console.error('Error obteniendo operación:', error)
|
|
|
|
if (error.statusCode) {
|
|
throw error
|
|
}
|
|
|
|
throw createError({
|
|
statusCode: 500,
|
|
statusMessage: 'Error obteniendo operación',
|
|
data: { message: error.message },
|
|
})
|
|
}
|
|
})
|