22 lines
740 B
TypeScript
22 lines
740 B
TypeScript
import type { CreateCourtInput } from '@repo/api-contract'
|
|
import { CourtServiceError, createCourt } from '@/modules/court/services/court.service'
|
|
import type { AppContext } from '@/types/hono'
|
|
|
|
type ComplexIdParams = { complexId: string }
|
|
|
|
export async function createCourtHandler(c: AppContext) {
|
|
const { complexId } = c.req.valid('param' as never) as ComplexIdParams
|
|
const payload = c.req.valid('json' as never) as CreateCourtInput
|
|
const appUserId = c.get('appUserId')
|
|
|
|
try {
|
|
const court = await createCourt(appUserId, complexId, payload)
|
|
return c.json(court, 201)
|
|
} catch (error) {
|
|
if (error instanceof CourtServiceError) {
|
|
return c.json({ message: error.message }, error.status)
|
|
}
|
|
throw error
|
|
}
|
|
}
|