Compare commits
1 Commits
mobile-api
...
mobile-api
| Author | SHA1 | Date | |
|---|---|---|---|
| 27259cd86c |
@@ -1,7 +1,7 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { prisma } from "@/lib";
|
import { prisma } from "@/lib";
|
||||||
|
|
||||||
export { GET };
|
export { GET, PUT };
|
||||||
|
|
||||||
async function GET(req: Request, { params }: { params: { id: string } }) {
|
async function GET(req: Request, { params }: { params: { id: string } }) {
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
@@ -20,6 +20,7 @@ async function GET(req: Request, { params }: { params: { id: string } }) {
|
|||||||
StatusInvoice: true,
|
StatusInvoice: true,
|
||||||
imageId: true,
|
imageId: true,
|
||||||
MasterBank: 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 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -46,12 +46,14 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
MasterPeriodeDeviden: true,
|
MasterPeriodeDeviden: true,
|
||||||
MasterProgresInvestasi: true,
|
MasterProgresInvestasi: true,
|
||||||
masterStatusInvestasiId: true,
|
masterStatusInvestasiId: true,
|
||||||
|
countDown: true,
|
||||||
Investasi_Invoice: {
|
Investasi_Invoice: {
|
||||||
where: {
|
where: {
|
||||||
statusInvoiceId: "1",
|
statusInvoiceId: {
|
||||||
|
in: ["1", "2", "3", "4"],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
countDown: true,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ export async function adminInvestasi_funAcceptTransaksiById({
|
|||||||
invoiceId: string;
|
invoiceId: string;
|
||||||
investasiId: string;
|
investasiId: string;
|
||||||
lembarTerbeli: string;
|
lembarTerbeli: string;
|
||||||
}) {
|
}) {
|
||||||
console.log("Ini invoiceid", invoiceId)
|
console.log("Ini invoiceid", invoiceId);
|
||||||
console.log("Ini investasid", investasiId)
|
console.log("Ini investasid", investasiId);
|
||||||
console.log("Ini lembar terbeli", lembarTerbeli)
|
console.log("Ini lembar terbeli", lembarTerbeli);
|
||||||
|
|
||||||
const dataInvestasi: any = await prisma.investasi.findFirst({
|
const dataInvestasi: any = await prisma.investasi.findFirst({
|
||||||
where: {
|
where: {
|
||||||
@@ -50,7 +50,6 @@ export async function adminInvestasi_funAcceptTransaksiById({
|
|||||||
statusInvoiceId: "1",
|
statusInvoiceId: "1",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
if (!updt) {
|
if (!updt) {
|
||||||
return { status: 400, message: "Gagal Update Status" };
|
return { status: 400, message: "Gagal Update Status" };
|
||||||
@@ -87,6 +86,3 @@ export async function adminInvestasi_funAcceptTransaksiById({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user