fix ( upload image & api )
deskripsi: - fix upload dokumen investasi - fix api investasi
This commit is contained in:
@@ -2,39 +2,48 @@ import { prisma } from "@/app/lib";
|
||||
import { NextResponse } from "next/server";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
|
||||
|
||||
// GET ONE DATA INVESTASI BY ID
|
||||
export async function GET(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
const { id } = context.params
|
||||
const data = await prisma.investasi.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
targetDana: true,
|
||||
hargaLembar: true,
|
||||
totalLembar: true,
|
||||
roi: true,
|
||||
countDown: true,
|
||||
catatan: true,
|
||||
sisaLembar: true,
|
||||
imageId: true,
|
||||
prospektusFileId: true,
|
||||
masterPencarianInvestorId: true,
|
||||
masterPeriodeDevidenId: true,
|
||||
masterPembagianDevidenId: true,
|
||||
}
|
||||
});
|
||||
export async function GET(
|
||||
request: Request,
|
||||
context: { params: { id: string } }
|
||||
) {
|
||||
try {
|
||||
const { id } = context.params;
|
||||
const data = await prisma.investasi.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
include: {
|
||||
author: {
|
||||
include: {
|
||||
Profile: true,
|
||||
},
|
||||
},
|
||||
Investasi_Invoice: true,
|
||||
MasterStatusInvestasi: true,
|
||||
BeritaInvestasi: true,
|
||||
DokumenInvestasi: true,
|
||||
ProspektusInvestasi: true,
|
||||
MasterPembagianDeviden: true,
|
||||
MasterPencarianInvestor: true,
|
||||
MasterPeriodeDeviden: true,
|
||||
MasterProgresInvestasi: 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 });
|
||||
}
|
||||
}
|
||||
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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
61
src/app/api/new/investasi/dokumen/[id]/route.ts
Normal file
61
src/app/api/new/investasi/dokumen/[id]/route.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
context: { params: { id: string } }
|
||||
) {
|
||||
if (request.method === "GET") {
|
||||
try {
|
||||
let fixData;
|
||||
const { id } = context.params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const kategori = searchParams.get("kategori");
|
||||
const page = searchParams.get("page");
|
||||
const takeData = 10;
|
||||
const skipData = Number(page) * takeData - takeData;
|
||||
|
||||
if (kategori == null) {
|
||||
fixData = await prisma.dokumenInvestasi.findFirst({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
} else if (kategori == "get-all") {
|
||||
fixData = await prisma.dokumenInvestasi.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
investasiId: id,
|
||||
active: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
await prisma.$disconnect();
|
||||
|
||||
return NextResponse.json(
|
||||
{ success: true, message: "Success get data document", data: fixData },
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
backendLogger.error("Error get data document", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Failed to get data, try again later",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Method not allowed" },
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
import { Investasi_UiCreateDocument } from "@/app_modules/investasi/_ui";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
const investasiId = params.id;
|
||||
|
||||
export default async function Page() {
|
||||
return (
|
||||
<>
|
||||
<Investasi_UiCreateDocument investasiId={investasiId} />
|
||||
<Investasi_UiCreateDocument />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,21 +1,9 @@
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { investasi_funGetOneInvestasiById } from "@/app_modules/investasi/_fun";
|
||||
import { Investasi_UiDetailPortofolio } from "@/app_modules/investasi/_ui";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
const investasiId = params.id;
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
|
||||
const dataPortofolio = await investasi_funGetOneInvestasiById({
|
||||
investasiId,
|
||||
});
|
||||
|
||||
export default async function Page() {
|
||||
return (
|
||||
<>
|
||||
<Investasi_UiDetailPortofolio
|
||||
dataInvestasi={dataPortofolio as any}
|
||||
userLoginId={userLoginId as string}
|
||||
/>
|
||||
<Investasi_UiDetailPortofolio />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,21 +1,9 @@
|
||||
import {
|
||||
investasi_funGetAllDocumentById
|
||||
} from "@/app_modules/investasi/_fun";
|
||||
import { Investasi_UiDaftarDokmen } from "@/app_modules/investasi/_ui";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
const investasiId = params.id;
|
||||
const dataDokumen = await investasi_funGetAllDocumentById({
|
||||
investasiId: investasiId,
|
||||
page: 1,
|
||||
});
|
||||
|
||||
export default async function Page() {
|
||||
return (
|
||||
<>
|
||||
<Investasi_UiDaftarDokmen
|
||||
dataDokumen={dataDokumen}
|
||||
investasiId={investasiId}
|
||||
/>
|
||||
<Investasi_UiDaftarDokmen />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,9 @@
|
||||
import { investasi_funGetAllDocumentById } from "@/app_modules/investasi/_fun";
|
||||
import { Investasi_UiRekapDokumen } from "@/app_modules/investasi/_ui";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
const investasiId = params.id;
|
||||
const dataDokumen = await investasi_funGetAllDocumentById({
|
||||
investasiId,
|
||||
page: 1,
|
||||
});
|
||||
|
||||
export default async function Page() {
|
||||
return (
|
||||
<>
|
||||
<Investasi_UiRekapDokumen
|
||||
investasiId={investasiId}
|
||||
dataDokumen={dataDokumen}
|
||||
/>
|
||||
<Investasi_UiRekapDokumen />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
import { investasi_funGetOneDocumentById } from "@/app_modules/investasi/_fun";
|
||||
import { Investasi_UiEditDokumen } from "@/app_modules/investasi/_ui";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
const documentId = params.id;
|
||||
const dataDokumen = await investasi_funGetOneDocumentById({ documentId });
|
||||
|
||||
|
||||
export default async function Page() {
|
||||
return (
|
||||
<>
|
||||
<Investasi_UiEditDokumen dataDokumen={dataDokumen} />
|
||||
<Investasi_UiEditDokumen/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
import { LayoutEditDokumenInvestasi } from "@/app_modules/investasi";
|
||||
import React from "react";
|
||||
|
||||
export default async function Layout({children, params}: {children: React.ReactNode, params: {id: string}}) {
|
||||
return<>
|
||||
<LayoutEditDokumenInvestasi idInves={params.id}>{children}</LayoutEditDokumenInvestasi>
|
||||
</>
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { EditDokumenInvestasi } from "@/app_modules/investasi";
|
||||
import getOneInvestasiById from "@/app_modules/investasi/fun/get_one_investasi_by_id";
|
||||
|
||||
export default async function Page({params}: {params: {id: string}}) {
|
||||
const dataInvestasi = await getOneInvestasiById(params.id)
|
||||
// console.log(dataInvestasi)
|
||||
return<>
|
||||
<EditDokumenInvestasi dataInvestasi={dataInvestasi as any} />
|
||||
</>
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useDisclosure } from "@mantine/hooks";
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
|
||||
// Singleton PrismaClient untuk pengembangan
|
||||
@@ -20,8 +21,9 @@ if (process.env.NODE_ENV !== "production") {
|
||||
}
|
||||
|
||||
process.on("SIGINT", async () => {
|
||||
// console.log("Disconnecting PrismaClient...");
|
||||
await prisma.$disconnect();
|
||||
console.log("Start in Disconnecting PrismaClient...");
|
||||
const disconnect = await prisma.$disconnect();
|
||||
console.log("End of Disconnecting PrismaClient...", disconnect);
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user