API Table Forum Posting & API Table Forum Report Komentar

This commit is contained in:
2025-02-10 17:15:01 +08:00
25 changed files with 412 additions and 357 deletions

View File

@@ -4,7 +4,7 @@ import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
import _ from 'lodash';
export async function GET(request: Request, { komentarId }: { komentarId: string }) {
export async function GET(request: Request) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
@@ -26,8 +26,6 @@ export async function GET(request: Request, { komentarId }: { komentarId: string
try {
let fixData;
if (!page) {
fixData = await prisma.forum_ReportKomentar.findMany({
@@ -35,7 +33,13 @@ export async function GET(request: Request, { komentarId }: { komentarId: string
createdAt: "desc"
},
where: {
forum_KomentarId: komentarId,
Forum_Komentar: {
isActive: true,
komentar: {
contains: search ? search : "",
mode: "insensitive",
},
},
},
select: {
id: true,
@@ -53,6 +57,7 @@ export async function GET(request: Request, { komentarId }: { komentarId: string
},
},
},
},
})
} else {
@@ -63,7 +68,13 @@ export async function GET(request: Request, { komentarId }: { komentarId: string
createdAt: "desc",
},
where: {
forum_KomentarId: komentarId,
Forum_Komentar: {
isActive: true,
komentar: {
contains: search ? search : "",
mode: "insensitive",
},
},
},
select: {
id: true,
@@ -85,7 +96,13 @@ export async function GET(request: Request, { komentarId }: { komentarId: string
})
const nCount = await prisma.forum_ReportKomentar.count({
where: {
forum_KomentarId: komentarId,
Forum_Komentar: {
isActive: true,
komentar: {
contains: search ? search : "",
mode: "insensitive",
},
},
}
})
@@ -94,7 +111,7 @@ export async function GET(request: Request, { komentarId }: { komentarId: string
nCount: _.ceil(nCount / takeData)
}
}
console.log("Ini fixData", fixData)
return NextResponse.json({
success: true,
message: "Success get data forum komentar",

View File

@@ -131,8 +131,8 @@ export async function GET(request: Request,
}
return NextResponse.json({
success: true,
data: fixData,
message: "Success get data forum posting"
message: "Success get data forum posting",
data: fixData
},
{ status: 200 }
)

View File

@@ -25,7 +25,6 @@ export async function GET(request: Request) {
if (!page) {
fixData = await prisma.forum_Posting.findMany({
orderBy: {
createdAt: "desc",
},

View File

@@ -3,42 +3,46 @@ import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
export async function GET(request: Request) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed",
if (request.method !== "GET") {
return NextResponse.json(
{
success: false,
message: "Method not allowed",
},
{ status: 405 }
);
}
try {
let fixData;
fixData = await prisma.voting.count({
where: {
Voting_Status: {
name: "Publish",
},
{ status: 405 }
)
}
try {
let fixData;
fixData = await prisma.voting.count({
where: {
Voting_Status: {
name: "Publish",
},
isArsip: true,
}
})
return NextResponse.json({
success: true,
message: 'Success get data voting dashboard',
data: fixData
},
{ status: 200 }
)
} catch (error) {
backendLogger.error('Error get data voting dashboard >>', error);
return NextResponse.json({
success: false,
message: 'Error get data voting dashboard',
reason: (error as Error).message
},
{ status: 500 }
)
} finally {
await prisma.$disconnect();
}
}
isArsip: true,
},
});
return NextResponse.json(
{
success: true,
message: "Success get data voting dashboard",
data: fixData,
},
{ status: 200 }
);
} catch (error) {
backendLogger.error("Error get data voting dashboard >>", error);
return NextResponse.json(
{
success: false,
message: "Error get data voting dashboard",
reason: (error as Error).message,
},
{ status: 500 }
);
} finally {
await prisma.$disconnect();
}
}