Merge pull request 'Mobile APi: Investasi' (#6) from mobile-api/31-oct-25 into staging

Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/6
This commit is contained in:
2025-11-03 11:44:39 +08:00
3 changed files with 142 additions and 11 deletions

View File

@@ -1,7 +1,7 @@
import { NextResponse } from "next/server";
import { prisma } from "@/lib";
export { GET };
export { GET, PUT };
async function GET(req: Request, { params }: { params: { id: string } }) {
const { id } = params;
@@ -20,6 +20,7 @@ async function GET(req: Request, { params }: { params: { id: string } }) {
StatusInvoice: true,
imageId: true,
MasterBank: true,
lembarTerbeli: true,
},
});
@@ -43,3 +44,135 @@ async function GET(req: Request, { params }: { params: { id: string } }) {
);
}
}
async function PUT(req: Request, { params }: { params: { id: string } }) {
const { id } = params;
const { data } = await req.json();
const { searchParams } = new URL(req.url);
const category = searchParams.get("category");
console.log("[ID]", id);
console.log("[DATA]", data);
console.log("[CATEGORY]", category);
let fixData;
try {
if (category === "deny") {
const updt = await prisma.investasi_Invoice.update({
where: {
id: id,
},
data: {
statusInvoiceId: "4",
},
select: {
StatusInvoice: true,
authorId: true,
},
});
fixData = updt;
} else if (category === "accept") {
const dataInvestasi: any = await prisma.investasi.findFirst({
where: {
id: data.investasiId,
},
select: {
totalLembar: true,
sisaLembar: true,
lembarTerbeli: true,
},
});
// Hitung TOTAL SISA LEMBAR
const investasi_sisaLembar = Number(dataInvestasi?.sisaLembar);
const invoice_lembarTerbeli = Number(data.lembarTerbeli);
const resultSisaLembar = investasi_sisaLembar - invoice_lembarTerbeli;
// TAMBAH LEMBAR TERBELI
const investasi_lembarTerbeli = Number(dataInvestasi?.lembarTerbeli);
const resultLembarTerbeli =
investasi_lembarTerbeli + invoice_lembarTerbeli;
// Progress
const investasi_totalLembar = Number(dataInvestasi?.totalLembar);
const progress = (resultLembarTerbeli / investasi_totalLembar) * 100;
const resultProgres = Number(progress).toFixed(2);
const updt = await prisma.investasi_Invoice.update({
where: {
id: id,
},
data: {
statusInvoiceId: "1",
},
});
if (!updt) {
return NextResponse.json(
{
success: false,
message: "Gagal Update Status",
reason: "Update status failed",
},
{ status: 500 }
);
}
const updateInvestasi = await prisma.investasi.update({
where: {
id: data.investasiId,
},
data: {
sisaLembar: resultSisaLembar.toString(),
lembarTerbeli: resultLembarTerbeli.toString(),
progress: resultProgres,
},
include: {
MasterStatusInvestasi: true,
},
});
if (!updateInvestasi) {
return NextResponse.json(
{
success: false,
message: "Gagal Update Data Investasi",
reason: "Update data investasi failed",
},
{ status: 500 }
);
}
fixData = updt;
} else {
return NextResponse.json(
{
success: false,
message: "Invalid category",
reason: "Invalid category",
},
{ status: 400 }
);
}
return NextResponse.json(
{
success: true,
message: "Berhasil update data",
data: fixData,
},
{ status: 200 }
);
} catch (error) {
console.log("[ERROR]", error);
return NextResponse.json(
{
success: false,
message: "Error update detail Investasi",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -46,12 +46,14 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
MasterPeriodeDeviden: true,
MasterProgresInvestasi: true,
masterStatusInvestasiId: true,
countDown: true,
Investasi_Invoice: {
where: {
statusInvoiceId: "1",
statusInvoiceId: {
in: ["1", "2", "3", "4"],
},
},
},
countDown: true,
},
});

View File

@@ -13,10 +13,10 @@ export async function adminInvestasi_funAcceptTransaksiById({
invoiceId: string;
investasiId: string;
lembarTerbeli: string;
}) {
console.log("Ini invoiceid", invoiceId)
console.log("Ini investasid", investasiId)
console.log("Ini lembar terbeli", lembarTerbeli)
}) {
console.log("Ini invoiceid", invoiceId);
console.log("Ini investasid", investasiId);
console.log("Ini lembar terbeli", lembarTerbeli);
const dataInvestasi: any = await prisma.investasi.findFirst({
where: {
@@ -50,7 +50,6 @@ export async function adminInvestasi_funAcceptTransaksiById({
statusInvoiceId: "1",
},
});
if (!updt) {
return { status: 400, message: "Gagal Update Status" };
@@ -87,6 +86,3 @@ export async function adminInvestasi_funAcceptTransaksiById({
};
}
}