Compare commits

..

3 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
8 changed files with 262 additions and 38 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

@@ -13,40 +13,11 @@ async function GET(req: Request, { params }: { params: { id: string } }) {
const skipData = Number(page) * takeData - takeData;
const fixStatus = _.startCase(status || "");
console.log("[FIX STATUS]", fixStatus);
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 {
if (status === null) {
fixData = await prisma.donasi_Invoice.findMany({
take: page ? takeData : undefined,
skip: page ? skipData : undefined,
@@ -67,8 +38,59 @@ async function GET(req: Request, { params }: { params: { id: string } }) {
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(

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

@@ -42,11 +42,23 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
},
});
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: data,
data: {
donasi: data,
donatur: successInvoice,
},
},
{ status: 200 }
);

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,