Fix Detail Publish Daftar Donatur

This commit is contained in:
2025-02-27 17:31:14 +08:00
parent 32bc632387
commit 12ff284ff1
12 changed files with 2496 additions and 496 deletions

View File

@@ -0,0 +1,111 @@
import { prisma } from "@/lib";
import backendLogger from "@/util/backendLogger";
import _ from "lodash";
import { NextResponse } from "next/server";
export async function GET(req: Request,
{ params }: { params: { id: string } }) {
try {
let fixData;
const { id } = params;
const { searchParams } = new URL(req.url);
const page = searchParams.get("page");
const status = searchParams.get("status");
const takeData = 2
const skipData = Number(page) * takeData - takeData;
if (!page) {
fixData = await prisma.donasi_Invoice.findMany({
orderBy: {
createdAt: "desc",
},
where: {
donasiId: id,
active: true,
},
select: {
id: true,
nominal: true,
createdAt: true,
Author: true,
DonasiMaster_Bank: true,
DonasiMaster_StatusInvoice: true,
donasiMaster_StatusInvoiceId: true,
imagesId: true,
imageId: true,
},
})
} else {
const fixStatus = _.startCase(status ? status : "");
const data = await prisma.donasi_Invoice.findMany({
take: takeData,
skip: skipData,
orderBy: {
createdAt: "desc",
},
where: {
donasiId: id,
active: true,
DonasiMaster_StatusInvoice: {
name: {
contains: fixStatus,
mode: "insensitive",
}
}
},
select: {
id: true,
nominal: true,
createdAt: true,
Author: true,
DonasiMaster_Bank: true,
DonasiMaster_StatusInvoice: true,
donasiMaster_StatusInvoiceId: true,
imagesId: true,
imageId: true,
},
})
const nCount = await prisma.donasi_Invoice.count({
where: {
donasiId: id,
active: true,
DonasiMaster_StatusInvoice: {
name: {
contains: fixStatus,
mode: "insensitive",
}
}
}
})
fixData = {
data: data,
nPage: _.ceil(nCount / takeData)
}
}
return NextResponse.json({
success: true,
message: "Success",
data: fixData,
},
{ status: 200 }
)
} catch (error) {
backendLogger.error("Error get data donatur >>", error);
return NextResponse.json({
success: false,
message: "Error get data donatur",
reason: (error as Error).message
},
{ status: 500 }
)
}
}