Donation
Add: - api/mobile/donation/[id]/fundrising/ - api/mobile/donation/[id]/invoice/ - api/mobile/donation/[id]/news/ Fix: - api/mobile/donation/[id]/route.ts - api/mobile/donation/route.ts ### No Issue
This commit is contained in:
103
src/app/api/mobile/donation/[id]/fundrising/route.ts
Normal file
103
src/app/api/mobile/donation/[id]/fundrising/route.ts
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { prisma } from "@/lib";
|
||||||
|
|
||||||
|
export async function GET(
|
||||||
|
request: Request,
|
||||||
|
{ params }: { params: { id: string } }
|
||||||
|
) {
|
||||||
|
let fixData;
|
||||||
|
try {
|
||||||
|
const { id } = params;
|
||||||
|
const user = await prisma.user.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
username: true,
|
||||||
|
nomor: true,
|
||||||
|
Profile: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
email: true,
|
||||||
|
imageId: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// Donasi: {
|
||||||
|
// orderBy: {
|
||||||
|
// createdAt: "desc",
|
||||||
|
// },
|
||||||
|
// where: {
|
||||||
|
// donasiMaster_StatusDonasiId: "1",
|
||||||
|
// },
|
||||||
|
// select: {
|
||||||
|
// id: true,
|
||||||
|
// title: true,
|
||||||
|
// target: true,
|
||||||
|
// active: true,
|
||||||
|
// createdAt: true,
|
||||||
|
// updatedAt: true,
|
||||||
|
// publishTime: true,
|
||||||
|
// catatan: true,
|
||||||
|
// authorId: true,
|
||||||
|
// progres: true,
|
||||||
|
// terkumpul: 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 donasi = await prisma.donasi.findMany({
|
||||||
|
where: {
|
||||||
|
authorId: id,
|
||||||
|
donasiMaster_StatusDonasiId: "1",
|
||||||
|
active: true,
|
||||||
|
},
|
||||||
|
orderBy: {
|
||||||
|
publishTime: "desc",
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
imageId: true,
|
||||||
|
title: true,
|
||||||
|
publishTime: true,
|
||||||
|
progres: true,
|
||||||
|
terkumpul: true,
|
||||||
|
DonasiMaster_Durasi: {
|
||||||
|
select: {
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
fixData = {
|
||||||
|
user,
|
||||||
|
donasi,
|
||||||
|
};
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
success: true,
|
||||||
|
message: "Data berhasil diambil",
|
||||||
|
data: fixData,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
return NextResponse.json({
|
||||||
|
success: false,
|
||||||
|
message: "Terjadi kesalahan saat mengambil data",
|
||||||
|
reason: error as Error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
186
src/app/api/mobile/donation/[id]/invoice/route.ts
Normal file
186
src/app/api/mobile/donation/[id]/invoice/route.ts
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
import _ from "lodash";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
|
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({
|
||||||
|
data: {
|
||||||
|
donasiId: id,
|
||||||
|
nominal: data.nominal,
|
||||||
|
donasiMaster_BankId: data.bankId,
|
||||||
|
authorId: data.authorId,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
DonasiMaster_StatusInvoice: {
|
||||||
|
select: {
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Donasi: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
authorId: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 201,
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil membuat invoice",
|
||||||
|
data: create,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR]", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 500,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal membuat invoice",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
try {
|
||||||
|
const { id } = params;
|
||||||
|
const data = await prisma.donasi_Invoice.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
authorId: true,
|
||||||
|
nominal: true,
|
||||||
|
donasiId: true,
|
||||||
|
createdAt: true,
|
||||||
|
donasiMaster_BankId: true,
|
||||||
|
donasiMaster_StatusInvoiceId: true,
|
||||||
|
Donasi: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
target: true,
|
||||||
|
active: true,
|
||||||
|
createdAt: true,
|
||||||
|
updatedAt: true,
|
||||||
|
publishTime: true,
|
||||||
|
catatan: true,
|
||||||
|
progres: true,
|
||||||
|
terkumpul: true,
|
||||||
|
authorId: 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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DonasiMaster_Bank: true,
|
||||||
|
DonasiMaster_StatusInvoice: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
return NextResponse.json({
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
success: true,
|
||||||
|
message: "Data berhasil diambil",
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
return NextResponse.json({
|
||||||
|
success: false,
|
||||||
|
message: "Terjadi kesalahan saat mengambil data",
|
||||||
|
reason: (error as Error).message || error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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("[ID]", id);
|
||||||
|
console.log("[DATA]", data);
|
||||||
|
console.log("[STATUS]", fixStatus);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const checkStatus = await prisma.donasiMaster_StatusInvoice.findFirst({
|
||||||
|
where: {
|
||||||
|
name: fixStatus,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!checkStatus) {
|
||||||
|
return NextResponse.json({
|
||||||
|
success: false,
|
||||||
|
message: "Status tidak ditemukan",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const update = await prisma.donasi_Invoice.update({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
donasiMaster_StatusInvoiceId: checkStatus.id,
|
||||||
|
imageId: data.fileId,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
DonasiMaster_StatusInvoice: {
|
||||||
|
select: {
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Donasi: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
authorId: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("[UPDATE]", update);
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 200,
|
||||||
|
success: true,
|
||||||
|
message: "Data berhasil diperbarui",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 500,
|
||||||
|
success: false,
|
||||||
|
message: "Terjadi kesalahan saat memperbarui data",
|
||||||
|
reason: (error as Error).message || error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
123
src/app/api/mobile/donation/[id]/news/route.ts
Normal file
123
src/app/api/mobile/donation/[id]/news/route.ts
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import { prisma } from "@/lib";
|
||||||
|
import _ from "lodash";
|
||||||
|
|
||||||
|
export { POST, GET };
|
||||||
|
|
||||||
|
async function POST(
|
||||||
|
request: NextRequest,
|
||||||
|
{ params }: { params: { id: string } }
|
||||||
|
) {
|
||||||
|
const { id } = params;
|
||||||
|
const { data } = await request.json();
|
||||||
|
console.log("[ID]", id);
|
||||||
|
console.log("[DATA]", data);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (data && data?.imageId) {
|
||||||
|
const createWithFile = await prisma.donasi_Kabar.create({
|
||||||
|
data: {
|
||||||
|
title: data.title,
|
||||||
|
deskripsi: data.deskripsi,
|
||||||
|
donasiId: id,
|
||||||
|
imageId: data.imageId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!createWithFile)
|
||||||
|
return NextResponse.json({ status: 400, message: "Gagal disimpan" });
|
||||||
|
} else {
|
||||||
|
const create = await prisma.donasi_Kabar.create({
|
||||||
|
data: {
|
||||||
|
title: data.title,
|
||||||
|
deskripsi: data.deskripsi,
|
||||||
|
donasiId: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("[CREATE]", create);
|
||||||
|
|
||||||
|
if (!create)
|
||||||
|
return NextResponse.json({ status: 400, message: "Gagal disimpan" });
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 200,
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil membuat kabar",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("[ERROR CREATE NEWS]", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 500,
|
||||||
|
success: false,
|
||||||
|
message: "Error Create Donation News",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function GET(
|
||||||
|
request: NextRequest,
|
||||||
|
{ params }: { params: { id: string } }
|
||||||
|
) {
|
||||||
|
const { id } = params;
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
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({
|
||||||
|
where: {
|
||||||
|
donasiId: id,
|
||||||
|
active: true,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
deskripsi: true,
|
||||||
|
createdAt: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else if (category === "get-one") {
|
||||||
|
const data = await prisma.donasi_Kabar.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
Donasi: {
|
||||||
|
select: {
|
||||||
|
authorId: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const authorId = data?.Donasi?.authorId;
|
||||||
|
|
||||||
|
fixData = {
|
||||||
|
..._.omit(data, ["Donasi"]),
|
||||||
|
authorId: authorId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 200,
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil mengambil kabar",
|
||||||
|
data: fixData,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("[ERROR GET NEWS]", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 500,
|
||||||
|
success: false,
|
||||||
|
message: "Error Get Donation News",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,7 +22,19 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
id: id,
|
id: id,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
Author: true,
|
Author: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
username: true,
|
||||||
|
Profile: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
imageId: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
imageDonasi: true,
|
imageDonasi: true,
|
||||||
CeritaDonasi: true,
|
CeritaDonasi: true,
|
||||||
DonasiMaster_Ketegori: true,
|
DonasiMaster_Ketegori: true,
|
||||||
@@ -192,9 +204,7 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
|||||||
if (!deleteImageDonasi) {
|
if (!deleteImageDonasi) {
|
||||||
console.log("[DELETE IMAGE DONASI]", deleteImageDonasi);
|
console.log("[DELETE IMAGE DONASI]", deleteImageDonasi);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (category === "edit-story") {
|
} else if (category === "edit-story") {
|
||||||
|
|
||||||
if (data && data.newImageId) {
|
if (data && data.newImageId) {
|
||||||
await prisma.donasi_Cerita.update({
|
await prisma.donasi_Cerita.update({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import prisma from "@/lib/prisma";
|
|
||||||
|
|
||||||
export { POST };
|
export { POST };
|
||||||
|
|
||||||
@@ -10,7 +10,6 @@ async function POST(request: Request) {
|
|||||||
const category = searchParams.get("category");
|
const category = searchParams.get("category");
|
||||||
let fixData;
|
let fixData;
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// CODE HERE
|
// CODE HERE
|
||||||
|
|
||||||
@@ -93,3 +92,105 @@ async function POST(request: Request) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GET ALL DATA DONASI
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
const category = searchParams.get("category");
|
||||||
|
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({
|
||||||
|
orderBy: {
|
||||||
|
publishTime: "desc",
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
donasiMaster_StatusDonasiId: "1",
|
||||||
|
active: true,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
imageId: true,
|
||||||
|
title: true,
|
||||||
|
publishTime: true,
|
||||||
|
progres: true,
|
||||||
|
terkumpul: true,
|
||||||
|
DonasiMaster_Durasi: {
|
||||||
|
select: {
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
fixData = data.map((v: any) => ({
|
||||||
|
..._.omit(v, ["DonasiMaster_Durasi"]),
|
||||||
|
durasiDonasi: v.DonasiMaster_Durasi.name,
|
||||||
|
}));
|
||||||
|
} else if (category === "my-donation") {
|
||||||
|
const data = await prisma.donasi_Invoice.findMany({
|
||||||
|
orderBy: {
|
||||||
|
createdAt: "desc",
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
authorId: authorId,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
nominal: true,
|
||||||
|
donasiMaster_StatusInvoiceId: true,
|
||||||
|
DonasiMaster_StatusInvoice: {
|
||||||
|
select: {
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Donasi: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
publishTime: true,
|
||||||
|
progres: true,
|
||||||
|
imageId: true,
|
||||||
|
DonasiMaster_Durasi: {
|
||||||
|
select: {
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
fixData = data.map((v: any) => ({
|
||||||
|
..._.omit(v, ["DonasiMaster_StatusInvoice", "Donasi"]),
|
||||||
|
statusInvoice: v.DonasiMaster_StatusInvoice.name,
|
||||||
|
donasiId: v.Donasi.id,
|
||||||
|
title: v.Donasi.title,
|
||||||
|
publishTime: v.Donasi.publishTime,
|
||||||
|
progres: v.Donasi.progres,
|
||||||
|
imageId: v.Donasi.imageId,
|
||||||
|
durasiDonasi: v.Donasi.DonasiMaster_Durasi.name,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json(
|
||||||
|
{ success: true, message: "Data berhasil diambil", data: fixData },
|
||||||
|
{ status: 200 }
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("[ERROR]", error);
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "Gagal mendapatkan data, coba lagi nanti ",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
},
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user