Compare commits

..

7 Commits

Author SHA1 Message Date
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
7fe5826f5c test 2025-10-27 11:27:59 +08:00
c47decf246 New github 2 2025-10-27 11:22:14 +08:00
4ef93e0509 New gitwibu 2025-10-27 11:18:59 +08:00
3052dabbce New gitwibu 2025-10-27 11:17:57 +08:00
nabillah
4fc0ebf7ee New gitwibu 2025-10-27 11:15:17 +08:00
nabillah
577ee38220 Mobile API: Event
Add:
- src/app/api/mobile/admin/event/[id]/participants/
- src/app/api/mobile/admin/master/type-of-event/
2025-10-24 16:39:33 +08:00
9 changed files with 679 additions and 135 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,134 @@
import _ from "lodash";
import { NextResponse } from "next/server";
export { GET };
async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const category = searchParams.get("category");
const page = searchParams.get("page");
const search = searchParams.get("search");
const takeData = 10;
const skipData = Number(page) * takeData - takeData;
console.log("[CATEGORY]", category);
let fixData;
try {
if (category === "dashboard") {
const publish = await prisma.donasi.count({
where: {
DonasiMaster_Status: {
name: "Publish",
},
},
});
const review = await prisma.donasi.count({
where: {
DonasiMaster_Status: {
name: "Review",
},
},
});
const reject = await prisma.donasi.count({
where: {
DonasiMaster_Status: {
name: "Reject",
},
},
});
const countCategoryDonation = await prisma.donasiMaster_Kategori.findMany(
{
orderBy: {
createdAt: "asc",
},
where: {
active: true,
},
}
);
const categoryDonation = countCategoryDonation.length;
fixData = {
publish,
review,
reject,
categoryDonation,
};
} else {
const fixCategory = _.startCase(category || "");
const checkStatus = await prisma.donasiMaster_StatusDonasi.findFirst({
where: {
name: fixCategory,
},
});
console.log("[STATUS]", checkStatus);
if (!checkStatus) {
return NextResponse.json(
{
success: false,
message: "Failed to get data donation",
reason: "Status not found",
},
{ status: 500 }
);
}
fixData = await prisma.donasi.findMany({
take: page ? takeData : undefined,
skip: page ? skipData : undefined,
orderBy: {
createdAt: "desc",
},
where: {
DonasiMaster_Status: {
name: checkStatus.name,
},
active: true,
title: {
contains: search || "",
mode: "insensitive",
},
},
select: {
id: true,
title: true,
Author: {
select: {
id: true,
username: true,
},
},
},
});
console.log("[LIST]", fixData);
}
return NextResponse.json(
{
success: true,
message: `Success get data donation ${category}`,
data: fixData,
},
{ status: 200 }
);
} catch (error) {
console.error("Error get data donation:", error);
return NextResponse.json(
{
success: false,
message: "Failed to get data donation",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,53 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
export { GET };
async function GET(request: Request, { params }: { params: { id: string } }) {
try {
const { id } = params;
const data = await prisma.event_Peserta.findMany({
where: {
eventId: id,
},
select: {
eventId: true,
userId: true,
isPresent: true,
User: {
select: {
id: true,
username: true,
nomor: true,
Profile: {
select: {
id: true,
name: true,
imageId: true,
},
},
},
},
},
});
return NextResponse.json(
{
success: true,
message: "Success get participants",
data: data,
},
{ status: 200 }
);
} catch (error) {
return NextResponse.json(
{
success: false,
message: "Error get participants",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,59 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
export { GET, PUT };
async function GET(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
try {
const data = await prisma.eventMaster_TipeAcara.findUnique({
where: {
id: Number(id),
},
});
return NextResponse.json({
success: true,
message: "Success get type of event",
data: data,
});
} catch (error) {
console.error("Error get type of event", error);
return NextResponse.json({
success: false,
message: "Error get type of event",
reason: (error as Error).message,
});
}
}
async function PUT(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
const { data } = await request.json();
try {
const updated = await prisma.eventMaster_TipeAcara.update({
where: {
id: Number(id),
},
data: {
name: data.name,
active: data.active,
},
});
return NextResponse.json({
success: true,
message: "Success update type of event",
data: updated,
});
} catch (error) {
console.error("Error update type of event", error);
return NextResponse.json({
success: false,
message: "Error update type of event",
reason: (error as Error).message,
});
}
}

View File

@@ -0,0 +1,70 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
export { GET, POST };
async function GET(request: Request) {
try {
const data = await prisma.eventMaster_TipeAcara.findMany({
orderBy: {
updatedAt: "desc",
},
});
return NextResponse.json({
success: true,
message: "Success get type of event",
data: data,
});
} catch (error) {
console.error("Error get type of event", error);
return NextResponse.json({
success: false,
message: "Error get type of event",
reason: (error as Error).message,
});
}
}
async function POST(request: Request) {
const { data } = await request.json();
try {
const checkList = await prisma.eventMaster_TipeAcara.count({});
if (!checkList) {
return NextResponse.json(
{
success: false,
message: "Type of event already exists",
},
{ status: 400 }
);
}
const created = await prisma.eventMaster_TipeAcara.create({
data: {
id: checkList + 1,
name: data,
},
});
return NextResponse.json(
{
success: true,
message: "Success create type of event",
},
{ status: 201 }
);
} catch (error) {
console.error("Error create type of event", error);
return NextResponse.json(
{
success: false,
message: "Error create type of event",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -11,8 +11,6 @@ export async function GET(
const { searchParams } = new URL(request.url);
const userId = searchParams.get("userId");
console.log("userId", userId);
const checkDataEvent = await prisma.event.findUnique({
where: {
id: id,
@@ -53,8 +51,6 @@ export async function GET(
},
});
console.log("checkPeserta", checkPeserta);
if (checkPeserta) {
peserta = true;
} else {
@@ -116,33 +112,6 @@ export async function POST(
console.log("id", id);
console.log("data", data);
// const checkEvent = await prisma.event.findUnique({
// where: {
// id: id,
// },
// });
// if (!checkEvent) {
// return NextResponse.json(
// { message: "Event Not Found", response: null },
// { status: 400 }
// );
// }
// const checkPeserta = await prisma.event_Peserta.findFirst({
// where: {
// userId: userId,
// eventId: id,
// },
// });
// if (!checkPeserta) {
// return NextResponse.json(
// { message: "Peserta Not Found", response: null },
// { status: 400 }
// );
// }
if (category === "join_and_confirm") {
const join = await prisma.event_Peserta.create({
data: {
@@ -152,14 +121,13 @@ export async function POST(
},
});
console.log("join", join);
fixData = join;
} else if (category === "confirmation") {
const checkPeserta = await prisma.event_Peserta.findFirst({
where: {
userId: data.userId,
eventId: id,
isPresent: true,
isPresent: false,
},
});
@@ -179,7 +147,6 @@ export async function POST(
},
});
console.log("confirm", confirm);
fixData = confirm;
}

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