Files
hipmi/src/app/api/mobile/forum/[id]/comment/route.ts
Bagasbanuna02 a9b57be0a6 Mobile API
Forum add:
- mobile/forum/[id]/comment
- mobile/forum/[id]/report-comment
- mobile/forum/[id]/report-commentar
- mobile/forum/[id]/report-postin
- mobile/master/forum-report

Fix:
- mobile/forum/[id]/route
- mobile/forum/route

### No isssue
2025-09-27 00:01:36 +08:00

149 lines
3.2 KiB
TypeScript

import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
export { POST, GET, DELETE };
async function POST(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
const { data } = await request.json();
console.log("[ID COMMENT]", id);
console.log("[DATA COMMENT]", data);
try {
const createComment = await prisma.forum_Komentar.create({
data: {
forum_PostingId: id,
komentar: data.comment,
authorId: data.authorId,
},
select: {
id: true,
isActive: true,
komentar: true,
createdAt: true,
authorId: true,
Author: {
select: {
id: true,
username: true,
Profile: {
select: {
id: true,
imageId: true,
},
},
},
},
},
});
if (!createComment) {
return NextResponse.json({
status: 400,
success: false,
message: "Gagal update data",
});
}
return NextResponse.json({
status: 200,
success: true,
message: "Berhasil update data",
data: createComment,
});
} catch (error) {
console.log("[ERROR COMMENT]", error);
return NextResponse.json({
status: 500,
success: false,
message: "Gagal update data",
reason: (error as Error).message || error,
});
}
}
async function GET(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
try {
const data = await prisma.forum_Komentar.findMany({
orderBy: {
createdAt: "desc",
},
where: {
forum_PostingId: id,
isActive: true,
},
select: {
id: true,
isActive: true,
komentar: true,
createdAt: true,
authorId: true,
Author: {
select: {
id: true,
username: true,
Profile: {
select: {
id: true,
imageId: true,
},
},
},
},
},
});
return NextResponse.json({
status: 200,
success: true,
message: "Berhasil mendapatkan data",
data: data,
});
} catch (error) {
console.log("[ERROR COMMENT]", error);
return NextResponse.json({
status: 500,
success: false,
message: "Gagal mendapatkan data",
reason: (error as Error).message || error,
});
}
}
async function DELETE(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
try {
const deleteComment = await prisma.forum_Komentar.delete({
where: {
id: id,
},
});
if (!deleteComment) {
return NextResponse.json({
status: 400,
success: false,
message: "Gagal hapus komentar",
});
}
return NextResponse.json({
status: 200,
success: true,
message: "Berhasil hapus komentar",
});
} catch (error) {
console.log("[ERROR COMMENT]", error);
return NextResponse.json({
status: 500,
success: false,
message: "Gagal hapus komentar",
reason: (error as Error).message || error,
});
}
}