API Detail Publish Event Progresss

This commit is contained in:
2025-02-14 17:46:10 +08:00
parent 54314ee506
commit 83ee4e257b
5 changed files with 386 additions and 177 deletions

View File

@@ -0,0 +1,105 @@
import backendLogger from "@/util/backendLogger";
import _ from "lodash";
import { NextResponse } from "next/server";
export async function GET(request: Request, { params }: { params: { id: string } }) {
try {
let fixData
const { id } = params;
const { searchParams } = new URL(request.url);
const page = searchParams.get("page");
const status = searchParams.get("status");
const takeData = 10;
const skipData = Number(page) * takeData - takeData;
console.log("status >", status)
if (!page) {
fixData = await prisma.investasi_Invoice.findMany({
orderBy: [
{
createdAt: "desc",
},
],
where: {
investasiId: id,
isActive: true,
},
include: {
Author: true,
Images: true,
StatusInvoice: true,
MasterBank: true,
},
});
} else {
const data = await prisma.investasi_Invoice.findMany({
take: takeData,
skip: skipData,
orderBy: [
{
createdAt: "desc",
},
],
where: {
investasiId: id,
isActive: true,
StatusInvoice: {
name: {
contains: status ? status : "",
mode: "insensitive",
}
}
},
include: {
Author: true,
Images: true,
StatusInvoice: true,
MasterBank: true,
},
});
const nCount = await prisma.investasi_Invoice.count({
where: {
investasiId: id,
isActive: true,
StatusInvoice: {
name: {
contains: status ? status : "",
mode: "insensitive",
}
}
},
});
fixData = {
data: data,
nPage: _.ceil(nCount / takeData),
};
}
return NextResponse.json({
success: true,
message: "Success get status transaksi",
data: fixData
},
{ status: 200 }
)
} catch (error) {
backendLogger.error("Eror get status transaksi", error);
return NextResponse.json({
success: false,
message: "Error get status transaksi",
reason: (error as Error).message
},
{ status: 500 }
)
}
}