fix: forum admin
perubahan pada metode API
This commit is contained in:
65
src/app/api/admin/forum/[id]/route.ts
Normal file
65
src/app/api/admin/forum/[id]/route.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
import _ from "lodash";
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
try {
|
||||
const { id } = params;
|
||||
const data = await prisma.forum_Posting.findFirst({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
diskusi: true,
|
||||
ForumMaster_StatusPosting: {
|
||||
select: {
|
||||
id: true,
|
||||
status: true,
|
||||
},
|
||||
},
|
||||
authorId: true,
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Forum_Komentar: {
|
||||
where: {
|
||||
isActive: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const result = {
|
||||
..._.omit(data, "Forum_Komentar"),
|
||||
Forum_Komentar: data?.Forum_Komentar.length,
|
||||
};
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Success get data",
|
||||
data: result,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error get data forum", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Error get data forum",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,9 @@
|
||||
import { AdminForum_LihatSemuaKomentar } from "@/app_modules/admin/forum";
|
||||
import { adminForum_getOnePostingById } from "@/app_modules/admin/forum/fun/get/get_one_posting_by_id";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
let postingId = params.id;
|
||||
|
||||
// const listKomentar = await adminForum_getListKomentarById({
|
||||
// postingId: postingId,
|
||||
// page: 1,
|
||||
// });
|
||||
const dataPosting = await adminForum_getOnePostingById(postingId);
|
||||
// const countKomentar = await adminForum_countKomentarByPostingId({
|
||||
// postingId: postingId,
|
||||
// });
|
||||
|
||||
export default async function Page() {
|
||||
return (
|
||||
<>
|
||||
<AdminForum_LihatSemuaKomentar
|
||||
dataPosting={dataPosting as any}
|
||||
/>
|
||||
<AdminForum_LihatSemuaKomentar />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user