Merge pull request #201 from bipproduction/amalia/16-des-24
Amalia/16 des 24
This commit is contained in:
39
src/app/api/new/investasi/[id]/route.ts
Normal file
39
src/app/api/new/investasi/[id]/route.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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,
|
||||
masterPencarianInvestorId: true,
|
||||
masterPeriodeDevidenId: true,
|
||||
masterPembagianDevidenId: 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 });
|
||||
}
|
||||
}
|
||||
46
src/app/api/new/investasi/master/route.ts
Normal file
46
src/app/api/new/investasi/master/route.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import { NextResponse } from "next/server";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
|
||||
// GET ALL DATA MASTER UNTUK INVESTASI
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
let dataFix
|
||||
const { searchParams } = new URL(request.url)
|
||||
const kategori = searchParams.get("cat")
|
||||
|
||||
if (kategori == "pencarian-investor") {
|
||||
dataFix = await await prisma.masterPencarianInvestor.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
active: true,
|
||||
},
|
||||
});
|
||||
} else if (kategori == "periode-deviden") {
|
||||
dataFix = await prisma.masterPeriodeDeviden.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
active: true,
|
||||
},
|
||||
});
|
||||
} else if (kategori == "pembagian-deviden") {
|
||||
dataFix = await prisma.masterPembagianDeviden.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
active: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan data", data: dataFix }, { 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 });
|
||||
}
|
||||
}
|
||||
112
src/app/api/new/investasi/route.ts
Normal file
112
src/app/api/new/investasi/route.ts
Normal file
@@ -0,0 +1,112 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import _ from "lodash";
|
||||
import moment from "moment";
|
||||
import { NextResponse } from "next/server";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
|
||||
// GET ALL DATA INVESTASI
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
let dataFix
|
||||
const { searchParams } = new URL(request.url)
|
||||
const kategori = searchParams.get("cat")
|
||||
const status = searchParams.get("status")
|
||||
const page = searchParams.get("page")
|
||||
const dataSkip = Number(page) * 5 - 5;
|
||||
|
||||
if (kategori == "bursa") {
|
||||
const data = await prisma.investasi.findMany({
|
||||
where: {
|
||||
masterStatusInvestasiId: "1",
|
||||
masterProgresInvestasiId: "1",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
MasterPencarianInvestor: true,
|
||||
countDown: true,
|
||||
progress: true,
|
||||
},
|
||||
});
|
||||
|
||||
for (let a of data) {
|
||||
if (
|
||||
(a.MasterPencarianInvestor?.name as any) -
|
||||
moment(new Date()).diff(new Date(a.countDown as any), "days") <=
|
||||
0
|
||||
) {
|
||||
await prisma.investasi.update({
|
||||
where: {
|
||||
id: a.id,
|
||||
},
|
||||
data: {
|
||||
masterProgresInvestasiId: "3",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (a.progress === "100") {
|
||||
await prisma.investasi.update({
|
||||
where: {
|
||||
id: a.id,
|
||||
},
|
||||
data: {
|
||||
masterProgresInvestasiId: "2",
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// cek data yang lewat
|
||||
// klo ada, update status
|
||||
const dataAwal = await prisma.investasi.findMany({
|
||||
take: 5,
|
||||
skip: dataSkip,
|
||||
orderBy: [
|
||||
{
|
||||
masterProgresInvestasiId: "asc",
|
||||
},
|
||||
{
|
||||
countDown: "desc",
|
||||
},
|
||||
],
|
||||
where: {
|
||||
masterStatusInvestasiId: "1",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
imageId: true,
|
||||
title: true,
|
||||
progress: true,
|
||||
countDown: true,
|
||||
MasterPencarianInvestor: {
|
||||
select: {
|
||||
name: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dataFix = dataAwal.map((v: any) => ({
|
||||
..._.omit(v, ["MasterPencarianInvestor"]),
|
||||
pencarianInvestor: v.MasterPencarianInvestor.name
|
||||
}))
|
||||
|
||||
} else if (kategori == "portofolio") {
|
||||
const userLoginId = await funGetUserIdByToken()
|
||||
if (userLoginId == null) {
|
||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan data, user id tidak ada" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan data", data: dataFix }, { 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 });
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,20 @@
|
||||
import { InvestasiCreate } from "@/app_modules/investasi";
|
||||
import getPembagianDeviden from "@/app_modules/investasi/fun/master/get_pembagian_deviden";
|
||||
import getPencarianInvestor from "@/app_modules/investasi/fun/master/get_pencarian_investor";
|
||||
import getPeriodeDeviden from "@/app_modules/investasi/fun/master/get_periode_deviden";
|
||||
import getStatusInvestasi from "@/app_modules/investasi/fun/master/get_status_investasi";
|
||||
import { InvestasiCreateNew } from "@/app_modules/investasi";
|
||||
|
||||
export default async function Page() {
|
||||
|
||||
const pencarianInvestor = await getPencarianInvestor();
|
||||
const periodeDeviden = await getPeriodeDeviden();
|
||||
const pembagianDeviden = await getPembagianDeviden();
|
||||
const statusInvestasi = await getStatusInvestasi();
|
||||
// const pencarianInvestor = await getPencarianInvestor();
|
||||
// const periodeDeviden = await getPeriodeDeviden();
|
||||
// const pembagianDeviden = await getPembagianDeviden();
|
||||
// const statusInvestasi = await getStatusInvestasi();
|
||||
|
||||
return (
|
||||
<>
|
||||
<InvestasiCreate
|
||||
{/* <InvestasiCreate
|
||||
pencarianInvestor={pencarianInvestor as any}
|
||||
periodeDeviden={periodeDeviden as any}
|
||||
pembagianDeviden={pembagianDeviden as any}
|
||||
/>
|
||||
/> */}
|
||||
<InvestasiCreateNew />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
import { investasi_funGetOneInvestasiById } from "@/app_modules/investasi/_fun";
|
||||
import { Investasi_UiEditInvestasi } from "@/app_modules/investasi/_ui";
|
||||
import { Investasi_UiEditInvestasi, Investasi_UiEditInvestasiNew } from "@/app_modules/investasi/_ui";
|
||||
import getPembagianDeviden from "@/app_modules/investasi/fun/master/get_pembagian_deviden";
|
||||
import getPencarianInvestor from "@/app_modules/investasi/fun/master/get_pencarian_investor";
|
||||
import getPeriodeDeviden from "@/app_modules/investasi/fun/master/get_periode_deviden";
|
||||
import _ from "lodash";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
const investasiId = params.id;
|
||||
// console.log(investasiId);
|
||||
// const investasiId = params.id;
|
||||
|
||||
const allData = await investasi_funGetOneInvestasiById({ investasiId });
|
||||
const dataInvestasi = _.omit(allData, [
|
||||
"BeritaInvestasi",
|
||||
"DokumenInvestasi",
|
||||
"MasterPembagianDeviden",
|
||||
"MasterPencarianInvestor",
|
||||
"MasterProgresInvestasi",
|
||||
"MasterStatusInvestasi",
|
||||
"ProspektusInvestasi",
|
||||
"MasterPeriodeDeviden",
|
||||
"author",
|
||||
]);
|
||||
// const allData = await investasi_funGetOneInvestasiById({ investasiId });
|
||||
// const dataInvestasi = _.omit(allData, [
|
||||
// "BeritaInvestasi",
|
||||
// "DokumenInvestasi",
|
||||
// "MasterPembagianDeviden",
|
||||
// "MasterPencarianInvestor",
|
||||
// "MasterProgresInvestasi",
|
||||
// "MasterStatusInvestasi",
|
||||
// "ProspektusInvestasi",
|
||||
// "MasterPeriodeDeviden",
|
||||
// "author",
|
||||
// ]);
|
||||
|
||||
const listPencarian = await getPencarianInvestor();
|
||||
const listPeriode = await getPeriodeDeviden();
|
||||
const listPembagian = await getPembagianDeviden();
|
||||
// const listPencarian = await getPencarianInvestor();
|
||||
// const listPeriode = await getPeriodeDeviden();
|
||||
// const listPembagian = await getPembagianDeviden();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Investasi_UiEditInvestasi
|
||||
{/* <Investasi_UiEditInvestasi
|
||||
dataInvestasi={dataInvestasi}
|
||||
pembagianDeviden={listPembagian}
|
||||
pencarianInvestor={listPencarian}
|
||||
periodeDeviden={listPeriode}
|
||||
/>
|
||||
/> */}
|
||||
<Investasi_UiEditInvestasiNew />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Investasi_UiBeranda } from "@/app_modules/investasi/_ui";
|
||||
import { investasi_funGetAllPublish } from "@/app_modules/investasi/fun/get_all_investasi";
|
||||
import { Investasi_ViewBerandaNew } from "@/app_modules/investasi/_ui";
|
||||
|
||||
export default async function Page() {
|
||||
const allData = await investasi_funGetAllPublish({ page: 1 });
|
||||
// const allData = await investasi_funGetAllPublish({ page: 1 });
|
||||
|
||||
return (
|
||||
<>
|
||||
<Investasi_UiBeranda dataInvestasi={allData as any} />
|
||||
{/* <Investasi_UiBeranda dataInvestasi={allData as any} /> */}
|
||||
<Investasi_ViewBerandaNew />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user