import PreRegistration from '../../../models/preRegistration.js'
import { connectDB } from '../../../utils/mongoose.js'

export default defineEventHandler(async (event) => {
  await requireAdmin(event)
  const id = getRouterParam(event, 'id')
  await connectDB()

  const preRegistrant = await PreRegistration.findById(id).lean()
  if (!preRegistrant) {
    throw createError({ statusCode: 404, statusMessage: 'Pre-registrant not found' })
  }

  return preRegistrant
})
