Files
hipmi/src/app/api/new/forum/route.ts
Bagasbanuna02 f419559379 fix lib
deskripsi:
- pindah lib di dalam app ke src ( lib setara app dan app_modules )
2025-02-12 10:57:10 +08:00

67 lines
1.9 KiB
TypeScript

import { prisma } from "@/lib"
import { NextResponse } from "next/server";
export const dynamic = "force-dynamic";
// GET ALL DATA PORTOFOLIO BY PROFILE ID
export async function GET(request: Request) {
try {
const { searchParams } = new URL(request.url)
const page = searchParams.get("page")
const search = searchParams.get("search")
const dataSkip = Number(page) * 5 - 5;
const data = await prisma.forum_Posting.findMany({
take: 5,
skip: dataSkip,
orderBy: {
createdAt: "desc",
},
where: {
isActive: true,
diskusi: {
mode: "insensitive",
contains: (search == undefined || search == "null") ? "" : search,
},
},
select: {
id: true,
diskusi: true,
createdAt: true,
isActive: true,
authorId: true,
Author: {
select: {
id: true,
username: true,
Profile: {
select: {
id: true,
name: true,
imageId: true,
},
},
},
},
Forum_Komentar: {
where: {
isActive: true,
},
},
ForumMaster_StatusPosting: {
select: {
id: true,
status: true,
},
},
forumMaster_StatusPostingId: true,
},
});
return NextResponse.json({ success: true, message: "Berhasil mendapatkan data", data }, { status: 200 });
}
catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal mendapatkan data, coba lagi nanti ", reason: (error as Error).message, }, { status: 500 });
}
}