Invesment

Add:
- api/mobile/investment/[id]/document: handle data dokumen

Fix:
- api/mobile/investment/route.ts
- api/mobile/investment/[id]/route.ts

### No Issue
This commit is contained in:
2025-10-01 17:32:12 +08:00
parent 00ced5b4f2
commit 76c2748fad
3 changed files with 291 additions and 21 deletions

View File

@@ -1,8 +1,9 @@
import _ from "lodash";
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
import moment from "moment";
export { POST };
export { POST, GET };
async function POST(request: Request) {
const { data } = await request.json();
console.log(["DATA INVESTASI"], data);
@@ -44,3 +45,96 @@ async function POST(request: Request) {
}
}
async function GET(request: Request) {
let fixData;
const { searchParams } = new URL(request.url);
try {
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",
},
});
}
}
const dataAwal = await prisma.investasi.findMany({
orderBy: [
{
masterProgresInvestasiId: "asc",
},
{
countDown: "desc",
},
],
where: {
masterStatusInvestasiId: "1",
},
select: {
id: true,
imageId: true,
title: true,
progress: true,
countDown: true,
MasterPencarianInvestor: {
select: {
name: true,
},
},
},
});
fixData = dataAwal.map((v: any) => ({
..._.omit(v, ["MasterPencarianInvestor"]),
pencarianInvestor: v.MasterPencarianInvestor.name,
}));
return NextResponse.json({
status: 200,
success: true,
message: "Berhasil Mendapatkan Data",
data: fixData,
});
} catch (error) {
console.log("[ERROR GET INVESTASI]", error);
return NextResponse.json({
status: 500,
success: false,
message: "Error Mendapatkan Data",
reason: error || (error as Error).message,
});
}
}