Compare commits

...

4 Commits

Author SHA1 Message Date
5553f451e8 update version 2025-10-28 17:50:19 +08:00
027ec4f6c5 chore(release): 1.5.7 2025-10-28 17:49:52 +08:00
8485209a75 Mobile API: Donation & Admin Donation
Add:
- prisma/migrations/20251028063234_donasi_invoice_relation_bank_master/ : penambahan master bank ke donasi invoce
- src/app/api/mobile/admin/donation/[id]/invoice/

Fix:
- prisma/schema.prisma
- src/app/api/mobile/admin/donation/[id]/donatur/route.ts
- src/app/api/mobile/admin/donation/[id]/route.ts
- src/app/api/mobile/donation/[id]/invoice/route.ts

### No Issue
2025-10-28 17:48:36 +08:00
d9e2fdaf30 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
2025-10-28 10:12:16 +08:00
10 changed files with 591 additions and 106 deletions

View File

@@ -2,6 +2,8 @@
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
## [1.5.7](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.6...v1.5.7) (2025-10-28)
## [1.5.6](https://wibugit.wibudev.com/bip/hipmi/compare/v1.5.5...v1.5.6) (2025-10-21)
## [1.5.5](https://wibugit.wibudev.com/bip/hipmi/compare/v1.5.4...v1.5.5) (2025-10-20)

View File

@@ -1,6 +1,6 @@
{
"name": "hipmi",
"version": "1.5.6",
"version": "1.5.7",
"private": true,
"prisma": {
"seed": "bun prisma/seed.ts"

View File

@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "Donasi_Invoice" ADD COLUMN "masterBankId" TEXT;
-- AddForeignKey
ALTER TABLE "Donasi_Invoice" ADD CONSTRAINT "Donasi_Invoice_masterBankId_fkey" FOREIGN KEY ("masterBankId") REFERENCES "MasterBank"("id") ON DELETE SET NULL ON UPDATE CASCADE;

View File

@@ -202,6 +202,7 @@ model MasterBank {
updatedAt DateTime @updatedAt
Investasi_Invoice Investasi_Invoice[]
EventTransaksi EventTransaksi[]
Donasi_Invoice Donasi_Invoice[]
}
model MasterStatus {
@@ -576,7 +577,9 @@ model Donasi_Invoice {
Images Images? @relation(fields: [imagesId], references: [id])
imagesId String?
imageId String?
imageId String?
MasterBank MasterBank? @relation(fields: [masterBankId], references: [id])
masterBankId String? @default("null")
}
model Donasi_Kabar {

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,115 @@
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 || "");
console.log("[FIX STATUS]", fixStatus);
let fixData;
try {
if (status === null) {
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,
MasterBank: true,
},
});
} else {
const checkStatusTransaksi =
await prisma.donasiMaster_StatusInvoice.findFirst({
where: {
name: fixStatus,
},
});
console.log("[CHECK STATUS TRANSAKSI]", checkStatusTransaksi);
if (!checkStatusTransaksi)
return NextResponse.json(
{
success: false,
message: "Error get detail Investasi",
reason: "Status not found",
},
{ status: 500 }
);
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: checkStatusTransaksi.name,
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;
}
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,176 @@
import { NextResponse } from "next/server";
import { prisma } from "@/lib";
import _ from "lodash";
export { GET, PUT };
async function GET(req: Request, { params }: { params: { id: string } }) {
const { id } = params;
console.log("[ID]", id);
try {
const data = await prisma.donasi_Invoice.findUnique({
where: {
id: id,
},
select: {
id: true,
donasiId: true,
nominal: true,
createdAt: true,
Author: true,
DonasiMaster_StatusInvoice: true,
imageId: true,
MasterBank: true,
},
});
return NextResponse.json(
{
success: true,
message: "Berhasil mendapatkan data",
data: data,
},
{ 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 }
);
}
}
// TYPE DATA
interface DataType {
donationId: string;
nominal: number;
}
async function PUT(req: Request, { params }: { params: { id: string } }) {
const { id } = params;
const { data } = await req.json();
const { searchParams } = new URL(req.url);
const status = searchParams.get("status");
const fixStatus = _.startCase(status as string);
console.log("[ID]", id);
console.log("[DATA]", data);
console.log("[FIX STATUS]", fixStatus);
const cloneData = data as DataType;
try {
const checkStatusTransaksi =
await prisma.donasiMaster_StatusInvoice.findFirst({
where: {
name: fixStatus,
},
});
if (!checkStatusTransaksi)
return NextResponse.json(
{
success: false,
message: "Failed update status invoice",
reason: "Status not found",
},
{ status: 500 }
);
const donasi = await prisma.donasi.findUnique({
where: {
id: data?.donationId,
},
select: {
target: true,
terkumpul: true,
},
});
if (!donasi) {
return NextResponse.json(
{
success: false,
message: "Failed update status invoice",
reason: "Donasi not found",
},
{ status: 500 }
);
}
const updateInvoice = await prisma.donasi_Invoice.update({
where: {
id: id,
},
data: {
donasiMaster_StatusInvoiceId: checkStatusTransaksi.id,
},
});
if (!updateInvoice) {
return NextResponse.json(
{
success: false,
message: "Failed update status invoice",
reason: "Update invoice failed",
},
{ status: 500 }
);
}
let totalNominal =
Number(cloneData.nominal) + (Number(donasi.terkumpul) || 0);
const progres =
Math.floor((totalNominal / Number(donasi.target)) * 1000) / 10;
console.log("[STATUS]", checkStatusTransaksi);
console.log("[TOTAL NOMINAL]", totalNominal);
console.log("[PROGRES]", progres);
const updateDonasi = await prisma.donasi.update({
where: {
id: data?.donationId,
},
data: {
terkumpul: "" + totalNominal,
progres: "" + progres,
},
});
if (!updateDonasi) {
return NextResponse.json(
{
success: false,
message: "Failed update status invoice",
reason: "Update donasi failed",
},
{ status: 500 }
);
}
return NextResponse.json(
{
success: true,
message: "Berhasil update status invoice",
data: updateDonasi,
},
{ status: 200 }
);
} catch (error) {
console.log("[ERROR]", error);
return NextResponse.json(
{
success: false,
message: "Error update status invoice",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,152 @@
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,
},
});
const successInvoice = await prisma.donasi_Invoice.count({
where: {
donasiId: donasiId,
DonasiMaster_StatusInvoice: {
name: "Berhasil",
},
},
});
return NextResponse.json(
{
success: true,
message: "Data Donasi Berhasil Diambil",
data: {
donasi: data,
donatur: successInvoice,
},
},
{ 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

@@ -13,7 +13,7 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
data: {
donasiId: id,
nominal: data.nominal,
donasiMaster_BankId: data.bankId,
masterBankId: data.bankId,
authorId: data.authorId,
},
select: {
@@ -48,7 +48,7 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
reason: (error as Error).message,
});
}
}
}
async function GET(request: Request, { params }: { params: { id: string } }) {
try {
@@ -65,6 +65,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
createdAt: true,
donasiMaster_BankId: true,
donasiMaster_StatusInvoiceId: true,
MasterBank: true,
Donasi: {
select: {
id: true,
@@ -137,13 +138,14 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
message: "Status tidak ditemukan",
});
}
const update = await prisma.donasi_Invoice.update({
where: {
id: id,
},
data: {
donasiMaster_StatusInvoiceId: checkStatus.id,
imageId: data.fileId,
imageId: data || null,
},
select: {
id: true,
@@ -162,6 +164,8 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
},
});
console.log("[UPDATE INVOICE]", update);
return NextResponse.json({
status: 200,
success: true,

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 }
);
}
}