From f99ec28cc4010cc3fdb6cde80a4ddb15e8fb4df7 Mon Sep 17 00:00:00 2001 From: nabillah Date: Fri, 17 Oct 2025 17:45:11 +0800 Subject: [PATCH] Mobile API: Add: - src/app/api/mobile/admin/forum/ Fix: - src/app/api/mobile/admin/job/route.ts ### Issue: Reminder kalau api komen report bekum ada --- .../mobile/admin/forum/[id]/comment/route.ts | 75 ++++++++++++ src/app/api/mobile/admin/forum/[id]/route.ts | 78 +++++++++++++ src/app/api/mobile/admin/forum/route.ts | 108 ++++++++++++++++++ src/app/api/mobile/admin/job/route.ts | 3 - 4 files changed, 261 insertions(+), 3 deletions(-) create mode 100644 src/app/api/mobile/admin/forum/[id]/comment/route.ts create mode 100644 src/app/api/mobile/admin/forum/[id]/route.ts create mode 100644 src/app/api/mobile/admin/forum/route.ts diff --git a/src/app/api/mobile/admin/forum/[id]/comment/route.ts b/src/app/api/mobile/admin/forum/[id]/comment/route.ts new file mode 100644 index 00000000..49436f7a --- /dev/null +++ b/src/app/api/mobile/admin/forum/[id]/comment/route.ts @@ -0,0 +1,75 @@ + +import _ from "lodash"; +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export async function GET( + request: Request, + { params }: { params: { id: string } } +) { + const { id } = params; + const { searchParams } = new URL(request.url); + const search = searchParams.get("search"); + const page = searchParams.get("page"); + const takeData = 10; + const skipData = Number(page) * takeData - takeData; + const category = searchParams.get("category"); + let fixData; + try { + if (category === "get-all") { + fixData = await prisma.forum_Komentar.findMany({ + orderBy: { + createdAt: "desc", + }, + where: { + forum_PostingId: id, + isActive: true, + komentar: { + contains: search ?? "", + mode: "insensitive", + }, + }, + include: { + Forum_ReportKomentar: true, + Author: { + select: { + username: true, + }, + }, + }, + }); + } else if (category === "get-one") { + fixData = await prisma.forum_Komentar.findUnique({ + where: { + id: id, + }, + include: { + Forum_ReportKomentar: true, + Author: { + select: { + username: true, + }, + }, + }, + }); + } + + return NextResponse.json( + { + success: true, + message: "Success get detail comment", + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Error get detail data comment", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/admin/forum/[id]/route.ts b/src/app/api/mobile/admin/forum/[id]/route.ts new file mode 100644 index 00000000..0a16d054 --- /dev/null +++ b/src/app/api/mobile/admin/forum/[id]/route.ts @@ -0,0 +1,78 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; +import _ from "lodash"; + +export async function GET( + request: Request, + { params }: { params: { id: string } } +) { + const { searchParams } = new URL(request.url); + const search = searchParams.get("search"); + const page = searchParams.get("page"); + const takeData = 10; + const skipData = Number(page) * takeData - takeData; + + const { id } = params; + try { + + 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, + }, + }, + Forum_ReportPosting: { + where: { + isActive: true, + }, + }, + }, + }); + + const result = { + ..._.omit(data, "Forum_Komentar", "Forum_ReportPosting"), + JumlahKomentar: data?.Forum_Komentar.length, + JumlahReportPosting: data?.Forum_ReportPosting.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 } + ); + } +} diff --git a/src/app/api/mobile/admin/forum/route.ts b/src/app/api/mobile/admin/forum/route.ts new file mode 100644 index 00000000..c52dd09c --- /dev/null +++ b/src/app/api/mobile/admin/forum/route.ts @@ -0,0 +1,108 @@ +import { NextResponse } from "next/server"; +import { prisma } from "@/lib"; + +export { GET }; + +async function GET(request: Request, { params }: { params: { name: string } }) { + const { searchParams } = new URL(request.url); + const category = searchParams.get("category"); + const search = searchParams.get("search"); + + + let fixData; + try { + if (category === "dashboard") { + const posting = await prisma.forum_Posting.count({ + orderBy: { + createdAt: "desc", + }, + where: { + isActive: true, + }, + }); + + const reportPosting = await prisma.forum_ReportPosting.count({ + orderBy: { + createdAt: "desc", + }, + where: { + Forum_Posting: { + isActive: true, + }, + }, + }); + + const reportComment = await prisma.forum_ReportKomentar.count({ + orderBy: { + createdAt: "desc", + }, + where: { + Forum_Komentar: { + isActive: true, + }, + }, + }); + + fixData = { + posting, + reportPosting, + reportComment, + }; + } else if (category === "posting") { + fixData = await prisma.forum_Posting.findMany({ + orderBy: { + createdAt: "desc", + }, + where: { + isActive: true, + diskusi: { + contains: search || "", + mode: "insensitive", + }, + }, + select: { + id: true, + diskusi: true, + isActive: true, + Author: { + select: { + id: true, + username: true, + Profile: true, + }, + }, + }, + }); + } else if (category === "report_posting") { + } else if (category === "report_comment") { + } else { + return NextResponse.json( + { + success: false, + message: "Invalid category", + reason: "Invalid category", + }, + { status: 400 } + ); + } + + + return NextResponse.json( + { + success: true, + message: `Success get data forum ${category}`, + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: `Error get data forum ${category}`, + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/admin/job/route.ts b/src/app/api/mobile/admin/job/route.ts index 652301ba..cf986c09 100644 --- a/src/app/api/mobile/admin/job/route.ts +++ b/src/app/api/mobile/admin/job/route.ts @@ -10,9 +10,6 @@ async function GET(request: Request, { params }: { params: { name: string } }) { const search = searchParams.get("search"); let fixData; - console.log("[CAT]", category); - - try { if (category === "dashboard") { const publish = await prisma.job.count({