diff --git a/src/app/api/admin/investasi/detail/[id]/route.ts b/src/app/api/admin/investasi/detail/[id]/route.ts new file mode 100644 index 00000000..dfcddaa5 --- /dev/null +++ b/src/app/api/admin/investasi/detail/[id]/route.ts @@ -0,0 +1,79 @@ +import { prisma } from "@/app/lib"; +import backendLogger from "@/util/backendLogger"; +import { NextResponse } from "next/server"; + +export async function GET(req: Request, + { params }: { params: { id: string } }) { + + console.log("Ini ID", params.id); + + try { + const { id } = params; + const data = await prisma.investasi.findUnique({ + where: { + id: id, + }, + select: { + imageId: true, + prospektusFileId: true, + id: true, + author: { + select: { + id: true, + username: true, + nomor: true, + Profile: true, + }, + }, + title: true, + authorId: true, + hargaLembar: true, + targetDana: true, + totalLembar: true, + sisaLembar: true, + lembarTerbeli: true, + progress: true, + roi: true, + active: true, + createdAt: true, + updatedAt: true, + catatan: true, + imagesId: true, + MasterStatusInvestasi: true, + BeritaInvestasi: true, + DokumenInvestasi: true, + ProspektusInvestasi: true, + MasterPembagianDeviden: true, + MasterPencarianInvestor: true, + MasterPeriodeDeviden: true, + MasterProgresInvestasi: true, + masterStatusInvestasiId: true, + Investasi_Invoice: { + where: { + statusInvoiceId: "1", + }, + }, + countDown: true, + + }, + }); + + return NextResponse.json({ + success: true, + message: "Success get detail investasi", + data: data, + }, + { status: 200 } + ) + } catch (error) { + backendLogger.error("Error get detail investasi", error); + return NextResponse.json({ + success: false, + message: "Error get detail investasi", + reason: (error as Error).message + }, + { status: 500 } + ); + + } +} \ No newline at end of file diff --git a/src/app_modules/admin/investasi/_lib/api_fetch_admin_investasi.ts b/src/app_modules/admin/investasi/_lib/api_fetch_admin_investasi.ts index ea29f62b..dc1d4ed9 100644 --- a/src/app_modules/admin/investasi/_lib/api_fetch_admin_investasi.ts +++ b/src/app_modules/admin/investasi/_lib/api_fetch_admin_investasi.ts @@ -1,6 +1,8 @@ export { apiGetAdminInvestasiCountDashboard, apiGetAdminInvestasiByStatus, + apiGetAdminInvestasiById, + } const apiGetAdminInvestasiCountDashboard = async ({ name }: { name: "Publish" | "Review" | "Reject" }) => { @@ -37,6 +39,7 @@ const apiGetAdminInvestasiByStatus = async ({ status, page, search }: { const isPage = page ? `?page=${page}` : ""; const isSearch = search ? `&search=${search}` : ""; const response = await fetch(`/api/admin/investasi/${status}${isPage}${isSearch}`, { + method: "GET", headers: { "Content-Type": "application/json", Accept: "application/json", @@ -45,5 +48,24 @@ const apiGetAdminInvestasiByStatus = async ({ status, page, search }: { }, }) + return await response.json().catch(() => null); +} + +const apiGetAdminInvestasiById = async ({id} : {id: string}) => { + const { token } = await fetch ("/api/get-cookie").then((res) => res.json()); + if (!token) return await token.json().catch(() => null); + + + const response = await fetch(`/api/admin/investasi/detail/${id}`, { + method: "GET", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "Access-Control-Allow-Origin": "*", + Authorization: `Bearer ${token}`, + } + }) + + console.log("Ini data Response", await response.json()) return await response.json().catch(() => null); } \ No newline at end of file diff --git a/src/middleware.ts b/src/middleware.ts index 4dbd6ca6..4b86c388 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -35,6 +35,7 @@ const middlewareConfig: MiddlewareConfig = { // ADMIN API // >> buat dibawah sini << "/api/admin/collaboration/*", + "/api/admin/investasi/*", // Akses awal "/api/get-cookie",