import { createError, readBody } from 'h3' import { z } from 'zod' import { requireAdminSession } from '../../../../utils/admin-auth' import { updateAdminPageSection } from '../../../../repositories/content-repository' const pageSectionInputSchema = z.object({ name: z.string().trim().min(1).max(80) }) /** * 관리자 페이지 섹션 수정 API * @param {import('h3').H3Event} event - 요청 이벤트 * @returns {Promise} 수정된 페이지 섹션 */ export default defineEventHandler(async (event) => { requireAdminSession(event) const id = String(event.context.params?.id || '') const parsedBody = pageSectionInputSchema.safeParse(await readBody(event)) if (!parsedBody.success) { throw createError({ statusCode: 400, message: '페이지 섹션 입력 형식이 올바르지 않습니다.' }) } try { const section = await updateAdminPageSection(id, parsedBody.data) if (!section) { throw createError({ statusCode: 404, message: '페이지 섹션을 찾을 수 없습니다.' }) } return section } catch (error) { if (error?.code === '23505') { throw createError({ statusCode: 409, message: '이미 사용 중인 페이지 섹션입니다.' }) } throw error } })