Initial commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import type { UpdateComplexInput } from '@repo/api-contract'
|
||||
import { Prisma } from '@/generated/prisma/client'
|
||||
import type { AppContext } from '@/types/hono'
|
||||
import { getComplexById, updateComplex } from '@/modules/complex/services/complex.service'
|
||||
|
||||
type ComplexIdParams = { id: string }
|
||||
|
||||
export async function updateComplexHandler(c: AppContext) {
|
||||
const { id } = c.req.valid('param' as never) as ComplexIdParams
|
||||
const payload = c.req.valid('json' as never) as UpdateComplexInput
|
||||
|
||||
const existing = await getComplexById(id)
|
||||
|
||||
if (!existing) {
|
||||
return c.json({ message: 'Complejo no encontrado.' }, 404)
|
||||
}
|
||||
|
||||
try {
|
||||
const complex = await updateComplex(id, payload)
|
||||
return c.json(complex)
|
||||
} catch (error) {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
return c.json({ message: 'No se pudo actualizar el complejo.' }, 409)
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user