fix event

deskripsi:
- fix riwayat event
This commit is contained in:
2025-02-21 11:40:15 +08:00
parent e0143c5d8c
commit bb5ca3a0ea
12 changed files with 359 additions and 142 deletions

View File

@@ -0,0 +1,153 @@
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
export { GET };
interface Props {
params: { name: string };
}
async function GET(request: Request, { params }: Props) {
try {
let fixData;
const { name } = params;
const { searchParams } = new URL(request.url);
const page = searchParams.get("page");
const takeData = 5;
const skipData = Number(page) * takeData - takeData;
const userLoginId = await funGetUserIdByToken();
if (!userLoginId) {
return NextResponse.json(
{
success: false,
message: "Gagal mendapatkan data",
reason: "Unauthorized",
},
{
status: 401,
}
);
}
if (!page) {
if (name == "saya") {
fixData = await prisma.event.findMany({
orderBy: {
tanggal: "desc",
},
where: {
authorId: userLoginId,
eventMaster_StatusId: "1",
isArsip: true,
},
select: {
id: true,
title: true,
tanggal: true,
deskripsi: true,
active: true,
authorId: true,
Author: {
select: {
Profile: true,
},
},
},
});
} else if (name === "semua") {
fixData = await prisma.event.findMany({
orderBy: {
tanggal: "desc",
},
where: {
eventMaster_StatusId: "1",
isArsip: true,
},
select: {
id: true,
title: true,
tanggal: true,
deskripsi: true,
active: true,
authorId: true,
Author: {
select: {
Profile: true,
},
},
},
});
}
} else {
if (name == "saya") {
fixData = await prisma.event.findMany({
take: takeData,
skip: skipData,
orderBy: {
tanggal: "desc",
},
where: {
authorId: userLoginId,
eventMaster_StatusId: "1",
isArsip: true,
},
select: {
id: true,
title: true,
tanggal: true,
deskripsi: true,
active: true,
authorId: true,
Author: {
select: {
Profile: true,
},
},
},
});
} else if (name === "semua") {
fixData = await prisma.event.findMany({
take: takeData,
skip: skipData,
orderBy: {
tanggal: "desc",
},
where: {
eventMaster_StatusId: "1",
isArsip: true,
},
select: {
id: true,
title: true,
tanggal: true,
deskripsi: true,
active: true,
authorId: true,
Author: {
select: {
Profile: true,
},
},
},
});
}
}
return NextResponse.json({
success: true,
message: "Berhasil mendapatkan data",
data: fixData,
});
} catch (error) {
backendLogger.error("Error get riwayat", error);
return NextResponse.json(
{
success: false,
message: "Error get data",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -1,16 +1,13 @@
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import { Event_DetailMain } from "@/app_modules/event";
import { Event_countTotalPesertaById } from "@/app_modules/event/fun/count/count_total_peserta_by_id";
export default async function Page() {
const userLoginId = await funGetUserIdByToken();
// const totalPeserta = await Event_countTotalPesertaById(eventId);
return (
<>
<Event_DetailMain
userLoginId={userLoginId as string}
// totalPeserta={totalPeserta as any}
/>
</>
);

View File

@@ -1,15 +1,9 @@
import { Event_DetailRiwayat } from "@/app_modules/event";
import { Event_countTotalPesertaById } from "@/app_modules/event/fun/count/count_total_peserta_by_id";
export default async function Page({ params }: { params: { id: string } }) {
let eventId = params.id;
const totalPeserta = await Event_countTotalPesertaById(eventId);
export default async function Page() {
return (
<>
<Event_DetailRiwayat
totalPeserta={totalPeserta as any}
/>
<Event_DetailRiwayat />
</>
);
}

View File

@@ -1,32 +1,9 @@
import { Event_Riwayat } from "@/app_modules/event";
import { event_getListRiwayatSaya } from "@/app_modules/event/fun/get/riwayat/get_list_riwayat_saya";
import { event_getListSemuaRiwayat } from "@/app_modules/event/fun/get/riwayat/get_list_semua_riwayat";
export default async function Page({ params }: { params: { id: string } }) {
let statusRiwayatId = params.id;
const dataSemuaRiwayat = await event_getListSemuaRiwayat({ page: 1 });
const dataRiwayatSaya = await event_getListRiwayatSaya({ page: 1 });
if (statusRiwayatId == "1") {
return (
<>
<Event_Riwayat
statusId={statusRiwayatId}
dataSemuaRiwayat={dataSemuaRiwayat as any}
/>
</>
);
}
if (statusRiwayatId == "2") {
return (
<>
<Event_Riwayat
statusId={statusRiwayatId}
dataRiwayatSaya={dataRiwayatSaya as any}
/>
</>
);
}
export default async function Page() {
return (
<>
<Event_Riwayat />
</>
);
}