Compare commits

...

1 Commits

Author SHA1 Message Date
9a967f0965 API Mobile
Add:
- src/app/api/mobile/investment/[id]/investor/

Fix:
modified:   src/app/api/mobile/admin/investment/[id]/invoice/route.ts
modified:   src/app/api/mobile/admin/investment/[id]/route.ts
modified:   src/app/api/mobile/investment/[id]/invoice/route.ts
modified:   src/app/api/mobile/investment/[id]/route.ts
modified:   src/app/api/mobile/investment/route.ts

#### No Issue
2025-11-03 17:53:58 +08:00
6 changed files with 161 additions and 76 deletions

View File

@@ -65,10 +65,10 @@ async function PUT(req: Request, { params }: { params: { id: string } }) {
data: { data: {
statusInvoiceId: "4", statusInvoiceId: "4",
}, },
select: { // select: {
StatusInvoice: true, // StatusInvoice: true,
authorId: true, // authorId: true,
}, // },
}); });
fixData = updt; fixData = updt;

View File

@@ -5,7 +5,7 @@ export { GET, PUT };
async function GET(request: Request, { params }: { params: { id: string } }) { async function GET(request: Request, { params }: { params: { id: string } }) {
const { id } = params; const { id } = params;
try { try {
const data = await prisma.investasi.findUnique({ const data = await prisma.investasi.findUnique({
where: { where: {
@@ -49,9 +49,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
countDown: true, countDown: true,
Investasi_Invoice: { Investasi_Invoice: {
where: { where: {
statusInvoiceId: { statusInvoiceId: "2",
in: ["1", "2", "3", "4"],
},
}, },
}, },
}, },
@@ -83,11 +81,11 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
const status = searchParams.get("status"); const status = searchParams.get("status");
console.log("[=======Start Investment console=======]") console.log("[=======Start Investment console=======]");
console.log("[ID]", id); console.log("[ID]", id);
console.log("[DATA]", data); console.log("[DATA]", data);
console.log("[STATUS]", status); console.log("[STATUS]", status);
console.log("[=======End Investment console=======]") console.log("[=======End Investment console=======]");
const publishTime = new Date(); const publishTime = new Date();

View File

@@ -0,0 +1,48 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
export { GET };
async function GET(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
try {
const data = await prisma.investasi_Invoice.findMany({
where: {
investasiId: id,
statusInvoiceId: "1",
},
select: {
id: true,
nominal: true,
Author: {
select: {
id: true,
username: true,
Profile: {
select: {
id: true,
name: true,
imageId: true,
},
},
},
},
},
});
return NextResponse.json({
status: 200,
success: true,
message: "Berhasil Mendapatkan Data",
data: data,
});
} catch (error) {
return NextResponse.json({
status: 500,
success: false,
message: "Error Mendapatkan Data",
reason: (error as Error).message,
});
}
}

View File

@@ -48,6 +48,9 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
const category = searchParams.get("category"); const category = searchParams.get("category");
const authorId = searchParams.get("authorId"); const authorId = searchParams.get("authorId");
console.log("[ID INVOICE]", id);
let fixData; let fixData;
try { try {
@@ -80,6 +83,8 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
}, },
}); });
console.log("[DATA INVOICE]", data ? true : false);
const { ...allData } = data; const { ...allData } = data;
const Investor = data?.Investasi?.Investasi_Invoice; const Investor = data?.Investasi?.Investasi_Invoice;
fixData = { ...allData, Investor }; fixData = { ...allData, Investor };

View File

@@ -17,7 +17,11 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
Profile: true, Profile: true,
}, },
}, },
Investasi_Invoice: true, Investasi_Invoice: {
where: {
statusInvoiceId: "1"
}
},
MasterStatusInvestasi: true, MasterStatusInvestasi: true,
BeritaInvestasi: true, BeritaInvestasi: true,
DokumenInvestasi: true, DokumenInvestasi: true,

View File

@@ -47,82 +47,112 @@ async function POST(request: Request) {
} }
async function GET(request: Request) { async function GET(request: Request) {
let fixData;
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
const category = searchParams.get("category");
const authorId = searchParams.get("authorId");
console.log("[CATEGORY]", category);
console.log("[AUTHOR ID]", authorId);
let fixData;
try { try {
const data = await prisma.investasi.findMany({ if (category === "bursa") {
where: { const data = await prisma.investasi.findMany({
masterStatusInvestasiId: "1", where: {
masterProgresInvestasiId: "1", masterStatusInvestasiId: "1",
}, masterProgresInvestasiId: "1",
select: { },
id: true, select: {
MasterPencarianInvestor: true, id: true,
countDown: true, MasterPencarianInvestor: true,
progress: true, countDown: true,
}, progress: true,
}); },
});
for (let a of data) { for (let a of data) {
if ( if (
(a.MasterPencarianInvestor?.name as any) - (a.MasterPencarianInvestor?.name as any) -
moment(new Date()).diff(new Date(a.countDown as any), "days") <= moment(new Date()).diff(new Date(a.countDown as any), "days") <=
0 0
) { ) {
await prisma.investasi.update({ await prisma.investasi.update({
where: { where: {
id: a.id, id: a.id,
}, },
data: { data: {
masterProgresInvestasiId: "3", masterProgresInvestasiId: "3",
}, },
}); });
}
if (a.progress === "100") {
await prisma.investasi.update({
where: {
id: a.id,
},
data: {
masterProgresInvestasiId: "2",
},
});
}
} }
if (a.progress === "100") { const dataAwal = await prisma.investasi.findMany({
await prisma.investasi.update({ orderBy: [
where: { {
id: a.id, masterProgresInvestasiId: "asc",
}, },
data: { {
masterProgresInvestasiId: "2", countDown: "desc",
}, },
}); ],
} where: {
} masterStatusInvestasiId: "1",
const dataAwal = await prisma.investasi.findMany({
orderBy: [
{
masterProgresInvestasiId: "asc",
}, },
{ select: {
countDown: "desc", id: true,
}, imageId: true,
], title: true,
where: { progress: true,
masterStatusInvestasiId: "1", countDown: true,
}, MasterPencarianInvestor: {
select: { select: {
id: true, name: true,
imageId: true, },
title: true,
progress: true,
countDown: true,
MasterPencarianInvestor: {
select: {
name: true,
}, },
}, },
}, });
});
fixData = dataAwal.map((v: any) => ({ fixData = dataAwal.map((v: any) => ({
..._.omit(v, ["MasterPencarianInvestor"]), ..._.omit(v, ["MasterPencarianInvestor"]),
pencarianInvestor: v.MasterPencarianInvestor.name, pencarianInvestor: v.MasterPencarianInvestor.name,
})); }));
} else if (category === "my-holding") {
const data = await prisma.investasi_Invoice.findMany({
where: {
authorId: authorId,
statusInvoiceId: "1",
},
select: {
id: true,
investasiId: true,
nominal: true,
lembarTerbeli: true,
Investasi: {
select: {
title: true,
progress: true,
},
},
},
});
fixData = data.map((v: any) => ({
..._.omit(v, ["Investasi"]),
title: v.Investasi.title,
progress: v.Investasi.progress,
}));
}
return NextResponse.json({ return NextResponse.json({
status: 200, status: 200,
success: true, success: true,