Donasi API Mobile

Add:
- src/app/api/mobile/admin/donation/[id]/
- src/app/api/mobile/master/transaction-status/

Fix:
-  src/app/api/admin/donasi/[id]/donatur/route.ts

### No Issue
This commit is contained in:
2025-10-28 10:12:16 +08:00
parent 7fe5826f5c
commit d9e2fdaf30
4 changed files with 362 additions and 101 deletions

View File

@@ -3,109 +3,107 @@ import backendLogger from "@/util/backendLogger";
import _ from "lodash";
import { NextResponse } from "next/server";
export async function GET(req: Request,
{ params }: { params: { id: string } }) {
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 = 10;
const skipData = Number(page) * takeData - takeData;
try {
let fixData;
const { id } = params;
const { searchParams } = new URL(req.url);
const page = searchParams.get("page");
const status = searchParams.get("status");
const takeData = 10
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,
if (!page) {
fixData = await prisma.donasi_Invoice.findMany({
orderBy: {
createdAt: "desc",
},
{ 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
where: {
donasiId: id,
active: true,
},
{ status: 500 }
)
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 }
);
}
}

View File

@@ -0,0 +1,93 @@
import _ from "lodash";
import { NextResponse } from "next/server";
import { prisma } from "@/lib";
export { GET };
async function GET(req: Request, { params }: { params: { id: string } }) {
const { id } = params;
const { searchParams } = new URL(req.url);
const page = searchParams.get("page");
const status = searchParams.get("status");
const takeData = 10;
const skipData = Number(page) * takeData - takeData;
const fixStatus = _.startCase(status || "");
let fixData;
try {
if (fixStatus) {
const data = await prisma.donasi_Invoice.findMany({
take: page ? takeData : undefined,
skip: page ? skipData : undefined,
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,
},
});
fixData = data;
} else {
fixData = await prisma.donasi_Invoice.findMany({
take: page ? takeData : undefined,
skip: page ? skipData : undefined,
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,
},
});
}
return NextResponse.json(
{
success: true,
message: "Berhasil mendapatkan data",
data: fixData,
},
{ status: 200 }
);
} catch (error) {
console.log("[ERROR]", error);
return NextResponse.json(
{
success: false,
message: "Error get detail Investasi",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,140 @@
import prisma from "@/lib/prisma";
import _ from "lodash";
import { NextResponse } from "next/server";
export { GET, PUT };
async function GET(request: Request, { params }: { params: { id: string } }) {
try {
const { id } = params;
const donasiId = id;
const data = await prisma.donasi.findUnique({
where: {
id: donasiId,
},
select: {
id: true,
title: true,
target: true,
active: true,
createdAt: true,
updatedAt: true,
publishTime: true,
catatan: true,
progres: true,
terkumpul: true,
authorId: true,
namaBank: true,
rekening: true,
totalPencairan: true,
akumulasiPencairan: true,
imagesId: true,
donasiMaster_KategoriId: true,
donasiMaster_DurasiId: true,
donasiMaster_StatusDonasiId: true,
Author: true,
imageDonasi: true,
CeritaDonasi: true,
DonasiMaster_Ketegori: true,
DonasiMaster_Durasi: true,
DonasiMaster_Status: true,
imageId: true,
},
});
return NextResponse.json(
{
success: true,
message: "Data Donasi Berhasil Diambil",
data: data,
},
{ status: 200 }
);
} catch (error) {
return NextResponse.json(
{
success: false,
message: "Error get detail Investasi",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}
async function PUT(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
const { data } = await request.json();
const { searchParams } = new URL(request.url);
const status = searchParams.get("status");
const fixStatus = _.startCase(status as string);
console.log("[PUT ID]", id);
console.log("[PUT DATA DONASI]", data);
console.log("[PUT DATA DONASI]", fixStatus);
let fixData;
try {
const checkStatus = await prisma.donasiMaster_StatusDonasi.findFirst({
where: {
name: fixStatus,
},
});
console.log("[PUT CHECK STATUS]", checkStatus);
if (!checkStatus)
return NextResponse.json(
{
success: false,
message: "Error update data event",
reason: "Status not found",
},
{ status: 500 }
);
if (fixStatus === "Reject") {
const updateData = await prisma.donasi.update({
where: {
id: id,
},
data: {
catatan: data,
donasiMaster_StatusDonasiId: checkStatus.id,
},
});
fixData = updateData;
} else if (fixStatus === "Publish") {
const updateData = await prisma.donasi.update({
where: {
id: id,
},
data: {
donasiMaster_StatusDonasiId: checkStatus.id,
publishTime: new Date(),
},
});
fixData = updateData;
}
return NextResponse.json(
{
success: true,
message: "Data Donasi Berhasil Diambil",
data: data,
},
{ status: 200 }
);
} catch (error) {
return NextResponse.json(
{
success: false,
message: "Error get detail Investasi",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,30 @@
import { prisma } from "@/lib";
import { NextResponse } from "next/server";
export async function GET(request: Request) {
try {
const res = await prisma.masterStatusTransaksi.findMany({
orderBy: {
updatedAt: "asc",
},
where: {
isActive: true,
},
});
return NextResponse.json(
{ success: true, message: "Berhasil mendapatkan data", data: res },
{ status: 200 }
);
} catch (error) {
console.log("[ERROR]", error);
return NextResponse.json(
{
success: false,
message: "API Error Get Data",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}