diff options
Diffstat (limited to 'app/api/vendor-responses/update-comment/route.ts')
| -rw-r--r-- | app/api/vendor-responses/update-comment/route.ts | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/app/api/vendor-responses/update-comment/route.ts b/app/api/vendor-responses/update-comment/route.ts new file mode 100644 index 00000000..212173d7 --- /dev/null +++ b/app/api/vendor-responses/update-comment/route.ts @@ -0,0 +1,60 @@ +// app/api/vendor-responses/update-comment/route.ts +import { NextRequest, NextResponse } from "next/server"; +import db from "@/db/db"; +import { vendorAttachmentResponses } from "@/db/schema"; + +import { getServerSession } from "next-auth/next" +import { authOptions } from "@/app/api/auth/[...nextauth]/route" + +export async function POST(request: NextRequest) { + try { + // 인증 확인 + const session = await getServerSession(authOptions); + if (!session?.user?.id) { + return NextResponse.json( + { message: "인증이 필요합니다." }, + { status: 401 } + ); + } + + const body = await request.json(); + const { responseId, responseComment, vendorComment } = body; + + if (!responseId) { + return NextResponse.json( + { message: "응답 ID가 필요합니다." }, + { status: 400 } + ); + } + + // 코멘트만 업데이트 + const [updatedResponse] = await db + .update(vendorAttachmentResponses) + .set({ + responseComment, + vendorComment, + updatedAt: new Date(), + }) + .where(eq(vendorAttachmentResponses.id, parseInt(responseId))) + .returning(); + + if (!updatedResponse) { + return NextResponse.json( + { message: "응답을 찾을 수 없습니다." }, + { status: 404 } + ); + } + + return NextResponse.json({ + message: "코멘트가 성공적으로 업데이트되었습니다.", + response: updatedResponse, + }); + + } catch (error) { + console.error("Comment update error:", error); + return NextResponse.json( + { message: "코멘트 업데이트 중 오류가 발생했습니다." }, + { status: 500 } + ); + } +}
\ No newline at end of file |
