Donation Mobile API

Fix:
- api/mobile/donation/[id]/[status]/route.ts
- api/mobile/donation/[id]/invoice/route.ts
- api/mobile/donation/[id]/news/route.ts
- api/mobile/donation/route.ts

### No Issue
This commit is contained in:
nabillah
2025-10-09 16:46:30 +08:00
parent b69b745a13
commit e7530a093b
4 changed files with 107 additions and 21 deletions

View File

@@ -19,8 +19,6 @@ async function GET(
},
});
console.log("[CHECK STATUS]", checkStatus);
if (!checkStatus)
return NextResponse.json({
status: 400,

View File

@@ -7,8 +7,6 @@ export { POST, GET, PUT };
async function POST(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
const { data } = await request.json();
console.log("[ID]", id);
console.log("[DATA]", data);
try {
const create = await prisma.donasi_Invoice.create({
@@ -126,10 +124,6 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
const status = searchParams.get("status");
const fixStatus = _.startCase(status as string);
console.log("[ID]", id);
console.log("[DATA]", data);
console.log("[STATUS]", fixStatus);
try {
const checkStatus = await prisma.donasiMaster_StatusInvoice.findFirst({
where: {
@@ -168,8 +162,6 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
},
});
console.log("[UPDATE]", update);
return NextResponse.json({
status: 200,
success: true,

View File

@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib";
import _ from "lodash";
export { POST, GET };
export { POST, GET, PUT, DELETE };
async function POST(
request: NextRequest,
@@ -10,8 +10,7 @@ async function POST(
) {
const { id } = params;
const { data } = await request.json();
console.log("[ID]", id);
console.log("[DATA]", data);
try {
if (data && data?.imageId) {
@@ -35,8 +34,6 @@ async function POST(
},
});
console.log("[CREATE]", create);
if (!create)
return NextResponse.json({ status: 400, message: "Gagal disimpan" });
}
@@ -66,12 +63,12 @@ async function GET(
const category = searchParams.get("category");
let fixData;
console.log("[CATEGORY]", category);
console.log("[ID]", id);
try {
if (category === "get-all") {
fixData = await prisma.donasi_Kabar.findMany({
orderBy: {
updatedAt: "desc",
},
where: {
donasiId: id,
active: true,
@@ -121,3 +118,105 @@ async function GET(
});
}
}
async function PUT(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
const { data } = await request.json();
try {
if (data && data.newImageId) {
const updateWithImage = await prisma.donasi_Kabar.update({
where: {
id: id,
},
data: {
title: data.title,
deskripsi: data.deskripsi,
imageId: data.newImageId,
},
});
if (!updateWithImage)
return NextResponse.json({
status: 400,
success: false,
message: "Gagal Update",
});
} else {
const updateData = await prisma.donasi_Kabar.update({
where: {
id: id,
},
data: {
title: data.title,
deskripsi: data.deskripsi,
},
});
if (!updateData)
return NextResponse.json({
status: 400,
success: false,
message: "Gagal Update",
});
}
return NextResponse.json({
status: 200,
success: true,
message: "Berhasil Update",
});
} catch (error) {
console.error("[ERROR UPDATE NEWS]", error);
return NextResponse.json({
status: 500,
success: false,
message: "Error Update Donation News",
reason: (error as Error).message,
});
}
}
async function DELETE(
request: Request,
{ params }: { params: { id: string } }
) {
const { id } = params;
try {
const deleteData = await prisma.donasi_Kabar.delete({
where: {
id: id,
},
select: {
imageId: true,
},
});
const deleteImage = await fetch(
`https://wibu-storage.wibudev.com/api/files/${deleteData?.imageId}/delete`,
{
method: "DELETE",
headers: {
Authorization: `Bearer ${process.env.WS_APIKEY}`,
},
}
);
if (!deleteImage) {
console.log("[FAILED DELETE IMAGE]", deleteImage);
}
return NextResponse.json({
status: 200,
success: true,
message: "Berhasil Delete",
});
} catch (error) {
console.error("[ERROR DELETE NEWS]", error);
return NextResponse.json({
status: 500,
success: false,
message: "Error Delete Donation News",
reason: (error as Error).message,
});
}
}

View File

@@ -100,9 +100,6 @@ export async function GET(request: Request) {
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({