import Member from '../../../models/member.js'
import { connectDB } from '../../../utils/mongoose.js'

export default defineEventHandler(async (event) => {
  await requireAdmin(event)

  const memberId = getRouterParam(event, 'id')

  await connectDB()

  const member = await Member.findById(memberId).lean()
  if (!member) {
    throw createError({ statusCode: 404, statusMessage: 'Member not found' })
  }

  return member
})
