ㅋㅓ밋
This commit is contained in:
57
backend/api/feedback/[id]/update.put.ts
Normal file
57
backend/api/feedback/[id]/update.put.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { query, execute } from '../../../utils/db'
|
||||
|
||||
/**
|
||||
* 개선의견 수정
|
||||
* PUT /api/feedback/[id]/update
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const userId = getCookie(event, 'user_id')
|
||||
if (!userId) {
|
||||
throw createError({ statusCode: 401, message: '로그인이 필요합니다.' })
|
||||
}
|
||||
|
||||
const feedbackId = getRouterParam(event, 'id')
|
||||
if (!feedbackId) {
|
||||
throw createError({ statusCode: 400, message: '피드백 ID가 필요합니다.' })
|
||||
}
|
||||
|
||||
// 본인 확인
|
||||
const feedback = await query<any>(`
|
||||
SELECT author_id FROM wr_feedback WHERE feedback_id = $1
|
||||
`, [feedbackId])
|
||||
|
||||
if (!feedback[0]) {
|
||||
throw createError({ statusCode: 404, message: '의견을 찾을 수 없습니다.' })
|
||||
}
|
||||
|
||||
if (feedback[0].author_id !== parseInt(userId)) {
|
||||
throw createError({ statusCode: 403, message: '본인의 의견만 수정할 수 있습니다.' })
|
||||
}
|
||||
|
||||
const body = await readBody<{
|
||||
category?: string
|
||||
content?: string
|
||||
}>(event)
|
||||
|
||||
if (!body.content?.trim()) {
|
||||
throw createError({ statusCode: 400, message: '내용을 입력해주세요.' })
|
||||
}
|
||||
|
||||
const validCategories = ['FEATURE', 'UI', 'BUG', 'ETC']
|
||||
if (body.category && !validCategories.includes(body.category)) {
|
||||
throw createError({ statusCode: 400, message: '올바른 카테고리를 선택해주세요.' })
|
||||
}
|
||||
|
||||
await execute(`
|
||||
UPDATE wr_feedback
|
||||
SET category = COALESCE($1, category),
|
||||
content = $2,
|
||||
updated_at = NOW()
|
||||
WHERE feedback_id = $3
|
||||
`, [body.category, body.content.trim(), feedbackId])
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: '수정되었습니다.'
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user