API Investasi By Id & Fetch API Investasi By Id
This commit is contained in:
79
src/app/api/admin/investasi/detail/[id]/route.ts
Normal file
79
src/app/api/admin/investasi/detail/[id]/route.ts
Normal file
@@ -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 }
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
export {
|
export {
|
||||||
apiGetAdminInvestasiCountDashboard,
|
apiGetAdminInvestasiCountDashboard,
|
||||||
apiGetAdminInvestasiByStatus,
|
apiGetAdminInvestasiByStatus,
|
||||||
|
apiGetAdminInvestasiById,
|
||||||
|
|
||||||
}
|
}
|
||||||
const apiGetAdminInvestasiCountDashboard = async ({ name }:
|
const apiGetAdminInvestasiCountDashboard = async ({ name }:
|
||||||
{ name: "Publish" | "Review" | "Reject" }) => {
|
{ name: "Publish" | "Review" | "Reject" }) => {
|
||||||
@@ -37,6 +39,7 @@ const apiGetAdminInvestasiByStatus = async ({ status, page, search }: {
|
|||||||
const isPage = page ? `?page=${page}` : "";
|
const isPage = page ? `?page=${page}` : "";
|
||||||
const isSearch = search ? `&search=${search}` : "";
|
const isSearch = search ? `&search=${search}` : "";
|
||||||
const response = await fetch(`/api/admin/investasi/${status}${isPage}${isSearch}`, {
|
const response = await fetch(`/api/admin/investasi/${status}${isPage}${isSearch}`, {
|
||||||
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Accept: "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);
|
return await response.json().catch(() => null);
|
||||||
}
|
}
|
||||||
@@ -35,6 +35,7 @@ const middlewareConfig: MiddlewareConfig = {
|
|||||||
// ADMIN API
|
// ADMIN API
|
||||||
// >> buat dibawah sini <<
|
// >> buat dibawah sini <<
|
||||||
"/api/admin/collaboration/*",
|
"/api/admin/collaboration/*",
|
||||||
|
"/api/admin/investasi/*",
|
||||||
|
|
||||||
// Akses awal
|
// Akses awal
|
||||||
"/api/get-cookie",
|
"/api/get-cookie",
|
||||||
|
|||||||
Reference in New Issue
Block a user