Donation
Add: - api/mobile/donation/[id]/fundrising/ - api/mobile/donation/[id]/invoice/ - api/mobile/donation/[id]/news/ Fix: - api/mobile/donation/[id]/route.ts - api/mobile/donation/route.ts ### No Issue
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export { POST };
|
||||
|
||||
@@ -10,7 +10,6 @@ async function POST(request: Request) {
|
||||
const category = searchParams.get("category");
|
||||
let fixData;
|
||||
|
||||
|
||||
try {
|
||||
// CODE HERE
|
||||
|
||||
@@ -93,3 +92,105 @@ async function POST(request: Request) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// GET ALL DATA DONASI
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
const authorId = searchParams.get("authorId");
|
||||
let fixData;
|
||||
|
||||
console.log("[CATEGORY]", category);
|
||||
console.log("[AUTHOR ID]", authorId);
|
||||
|
||||
try {
|
||||
if (category === "beranda") {
|
||||
const data = await prisma.donasi.findMany({
|
||||
orderBy: {
|
||||
publishTime: "desc",
|
||||
},
|
||||
where: {
|
||||
donasiMaster_StatusDonasiId: "1",
|
||||
active: true,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
imageId: true,
|
||||
title: true,
|
||||
publishTime: true,
|
||||
progres: true,
|
||||
terkumpul: true,
|
||||
DonasiMaster_Durasi: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
fixData = data.map((v: any) => ({
|
||||
..._.omit(v, ["DonasiMaster_Durasi"]),
|
||||
durasiDonasi: v.DonasiMaster_Durasi.name,
|
||||
}));
|
||||
} else if (category === "my-donation") {
|
||||
const data = await prisma.donasi_Invoice.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
authorId: authorId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
nominal: true,
|
||||
donasiMaster_StatusInvoiceId: true,
|
||||
DonasiMaster_StatusInvoice: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
Donasi: {
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
publishTime: true,
|
||||
progres: true,
|
||||
imageId: true,
|
||||
DonasiMaster_Durasi: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
fixData = data.map((v: any) => ({
|
||||
..._.omit(v, ["DonasiMaster_StatusInvoice", "Donasi"]),
|
||||
statusInvoice: v.DonasiMaster_StatusInvoice.name,
|
||||
donasiId: v.Donasi.id,
|
||||
title: v.Donasi.title,
|
||||
publishTime: v.Donasi.publishTime,
|
||||
progres: v.Donasi.progres,
|
||||
imageId: v.Donasi.imageId,
|
||||
durasiDonasi: v.Donasi.DonasiMaster_Durasi.name,
|
||||
}));
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{ success: true, message: "Data berhasil diambil", data: fixData },
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("[ERROR]", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Gagal mendapatkan data, coba lagi nanti ",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user