API Detail Publish Event Data Peserta

This commit is contained in:
2025-02-13 01:16:46 +08:00
parent 8a1afe7375
commit 4c81fe753a
10 changed files with 467 additions and 206 deletions

View File

@@ -1,11 +1,83 @@
import backendLogger from "@/util/backendLogger"; import backendLogger from "@/util/backendLogger";
import _ from "lodash";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
export async function GET(req: Request, export async function GET(request: Request,
{ params }: { params: { id: string } }) { { params }: { params: { id: string } }) {
try { const { searchParams } = new URL(request.url);
const search = searchParams.get('search');
const page = searchParams.get('page');
const takeData = 10;
const skipData = Number(page) * takeData - takeData;
try {
let fixData;
const { id } = params;
const eventId = id
if (!page) {
fixData = await prisma.event_Peserta.findMany({
where: {
eventId: eventId,
User: {
username: {
contains: search ? search : "",
}
}
},
select: {
isPresent: true,
User: {
include: {
Profile: true,
},
},
},
});
} else {
const data = await prisma.event_Peserta.findMany({
skip: skipData,
take: takeData,
where: {
eventId: eventId,
User: {
username: {
contains: search ? search : "",
}
}
},
select: {
isPresent: true,
User: {
include: {
Profile: true,
},
},
},
});
const nCount = await prisma.event_Peserta.count({
where: {
eventId: eventId,
},
});
fixData = {
data: data,
nPage: _.ceil(nCount / takeData),
};
}
return NextResponse.json({
success: true,
message: "Success get data event detail",
data: fixData,
},
{ status: 200 }
)
} catch (error) { } catch (error) {
backendLogger.error("Error get data event detail >>", error); backendLogger.error("Error get data event detail >>", error);
return NextResponse.json({ return NextResponse.json({

View File

@@ -0,0 +1,103 @@
import backendLogger from "@/util/backendLogger";
import _ from "lodash";
import { NextResponse } from "next/server";
export async function GET(request: Request,
{ params }: { params: { id: string } }
) {
const { searchParams } = new URL(request.url);
const search = searchParams.get('search');
const page = searchParams.get('page');
const takeData = 10;
const skipData = Number(page) * takeData - takeData;
try {
let fixData;
const { id } = params;
const komentarId = id
if (!page) {
fixData = await prisma.forum_ReportKomentar.findMany({
orderBy: {
createdAt: "desc"
},
where: {
forum_KomentarId: komentarId,
},
select: {
id: true,
isActive: true,
createdAt: true,
deskripsi: true,
ForumMaster_KategoriReport: true,
User: {
select: {
Profile: {
select: {
id: true,
name: true,
},
},
},
},
},
});
} else {
const data = await prisma.forum_ReportKomentar.findMany({
take: takeData,
skip: skipData,
orderBy: {
createdAt: "desc"
},
where: {
forum_KomentarId: komentarId,
},
select: {
id: true,
isActive: true,
createdAt: true,
deskripsi: true,
ForumMaster_KategoriReport: true,
User: {
select: {
Profile: {
select: {
id: true,
name: true,
},
},
},
},
},
});
const nCount = await prisma.forum_ReportKomentar.count({
where: {
forum_KomentarId: komentarId,
}
})
fixData = {
data: data,
nPage: _.ceil(nCount / takeData)
}
}
return NextResponse.json({
success: true,
message: "Success get detail data report komentar",
data: fixData
},
{ status: 200 }
)
} catch (error) {
backendLogger.error("Error get detail data report komentar >>", error);
return NextResponse.json({
success: false,
message: "Error get detail data report komentar",
reason: (error as Error).message
}, { status: 500 })
}
}

View File

@@ -4,112 +4,115 @@ import _ from "lodash";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
export async function GET(request: Request, export async function GET(request: Request,
{ params }: { params: { id: string } }) { { params }: { params: { id: string } }) {
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
const search = searchParams.get('search'); const search = searchParams.get('search');
const page = searchParams.get('page'); const page = searchParams.get('page');
const takeData = 10; const takeData = 10;
const skipData = Number(page) * takeData - takeData; const skipData = Number(page) * takeData - takeData;
try { try {
let fixData; let fixData;
const { id } = params; const { id } = params;
const postingId = id const postingId = id
if (!page) { if (!page) {
fixData = await prisma.forum_ReportPosting.findMany({ fixData = await prisma.forum_ReportPosting.findMany({
orderBy: { orderBy: {
createdAt: "desc", createdAt: "desc",
}, },
where: { where: {
forum_PostingId: postingId, forum_PostingId: postingId,
},
},
select: {
id: true,
deskripsi: true,
createdAt: true,
User: {
select: {
id: true,
username: true,
Profile: {
select: { select: {
id: true, name: true,
deskripsi: true,
createdAt: true,
User: {
select: {
id: true,
username: true,
Profile: {
select: {
name: true,
},
},
},
},
ForumMaster_KategoriReport: {
select: {
id: true,
title: true,
deskripsi: true,
},
},
},
});
} else {
const data = await prisma.forum_ReportPosting.findMany({
take: takeData,
skip: skipData,
orderBy: {
createdAt: "desc",
},
where: {
forum_PostingId: postingId,
}, },
},
},
},
ForumMaster_KategoriReport: {
select: {
id: true,
title: true,
deskripsi: true,
},
},
},
});
} else {
const data = await prisma.forum_ReportPosting.findMany({
take: takeData,
skip: skipData,
orderBy: {
createdAt: "desc",
},
where: {
forum_PostingId: postingId,
},
select: {
id: true,
deskripsi: true,
createdAt: true,
User: {
select: {
id: true,
username: true,
Profile: {
select: { select: {
id: true, name: true,
deskripsi: true,
createdAt: true,
User: {
select: {
id: true,
username: true,
Profile: {
select: {
name: true,
},
},
},
},
ForumMaster_KategoriReport: {
select: {
id: true,
title: true,
deskripsi: true,
},
},
}, },
}); },
const nCount = await prisma.forum_ReportPosting.count({ },
where: { },
isActive: true, ForumMaster_KategoriReport: {
} select: {
}) id: true,
title: true,
deskripsi: true,
fixData = { },
data: data, },
nCount: _.ceil(nCount / takeData) },
} });
const nCount = await prisma.forum_ReportPosting.count({
where: {
isActive: true,
} }
return NextResponse.json({ })
success: true,
message: "Success get data forum posting",
data: fixData fixData = {
}, data: data,
{ status: 200 } nPage: _.ceil(nCount / takeData)
) }
} catch (error) {
backendLogger.error("Error get data forum posting >>", error);
return NextResponse.json({
success: false,
message: "Error get data forum posting",
},
{ status: 500 }
)
} }
return NextResponse.json({
success: true,
message: "Success get data forum report posting",
data: fixData
},
{ status: 200 }
)
} catch (error) {
backendLogger.error("Error get data forum report posting >>", error);
return NextResponse.json({
success: false,
message: "Error get data forum report posting",
},
{ status: 500 }
)
}
} }

View File

@@ -1,13 +1,10 @@
import { AdminEvent_UiDetailPeserta } from "@/app_modules/admin/event/_ui"; import { AdminEvent_UiDetailPeserta } from "@/app_modules/admin/event/_ui";
import { adminEvent_getListPesertaById } from "@/app_modules/admin/event/fun/get/get_list_peserta_by_id";
export default async function Page({ params }: { params: { id: string } }) { export default async function Page(){
const eventId = params.id;
const dataPeserta = await adminEvent_getListPesertaById({ eventId, page: 1 });
return ( return (
<> <>
<AdminEvent_UiDetailPeserta dataPeserta={dataPeserta} eventId={eventId} /> <AdminEvent_UiDetailPeserta />
</> </>
); );
} }

View File

@@ -5,7 +5,8 @@ export {
apiGetAdminEventByStatus as apiGetDataEventByStatus, apiGetAdminEventByStatus as apiGetDataEventByStatus,
apiGetAdminEventRiwayat, apiGetAdminEventRiwayat,
apiGetAdminEventTipeAcara, apiGetAdminEventTipeAcara,
apiGetAdminDetailEventById apiGetAdminDetailEventById,
apiGetAdminDetailEventPesertaById
}; };
const apiGetAdminEventStatusCountDashboard = async ({ const apiGetAdminEventStatusCountDashboard = async ({
@@ -150,3 +151,31 @@ const apiGetAdminDetailEventById = async ({ id }: { id: string }) => {
return await response.json().catch(() => null); return await response.json().catch(() => null);
} }
const apiGetAdminDetailEventPesertaById = async ({
page,
search,
id
}: {
page: string;
search: string;
id: string
}) => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const isPage = page ? `?page=${page}` : "";
const isSearch = search ? `&search=${search}` : "";
const response = await fetch(`/api/admin/event/${id}/peserta${isPage}${isSearch}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
})
return await response.json().catch(() => null);
}

View File

@@ -6,21 +6,13 @@ import { AdminEvent_ViewDetailPeserta } from "../_view";
import { MODEL_EVENT_PESERTA } from "@/app_modules/event/_lib/interface"; import { MODEL_EVENT_PESERTA } from "@/app_modules/event/_lib/interface";
import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component"; import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component";
export function AdminEvent_UiDetailPeserta({ export function AdminEvent_UiDetailPeserta() {
dataPeserta,
eventId,
}: {
dataPeserta: any;
eventId: string
}) {
return ( return (
<> <>
<Stack> <Stack>
<AdminGlobal_ComponentBackButton /> <AdminGlobal_ComponentBackButton />
<ComponentAdminGlobal_TitlePage name="Detail Peserta" /> <ComponentAdminGlobal_TitlePage name="Detail Peserta" />
<AdminEvent_ViewDetailPeserta <AdminEvent_ViewDetailPeserta
dataPeserta={dataPeserta as any}
eventId={eventId}
/> />
</Stack> </Stack>
</> </>

View File

@@ -10,6 +10,8 @@ import {
ScrollArea, ScrollArea,
Stack, Stack,
Table, Table,
Text,
TextInput,
Title, Title,
} from "@mantine/core"; } from "@mantine/core";
import { useState } from "react"; import { useState } from "react";
@@ -17,32 +19,68 @@ import { adminEvent_getListPesertaById } from "../fun";
import _ from "lodash"; import _ from "lodash";
import ComponentAdminGlobal_IsEmptyData from "../../_admin_global/is_empty_data"; import ComponentAdminGlobal_IsEmptyData from "../../_admin_global/is_empty_data";
import { AdminColor } from "@/app_modules/_global/color/color_pallet"; import { AdminColor } from "@/app_modules/_global/color/color_pallet";
import { useShallowEffect } from "@mantine/hooks";
import { clientLogger } from "@/util/clientLogger";
import { apiGetAdminDetailEventPesertaById } from "../_lib/api_fecth_admin_event";
import { useParams } from "next/navigation";
import { IconSearch } from "@tabler/icons-react";
import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
export function AdminEvent_ViewDetailPeserta({ export function AdminEvent_ViewDetailPeserta() {
dataPeserta, const params = useParams<{ id: string }>();
eventId, const [data, setData] = useState<MODEL_EVENT_PESERTA[] | null>(null);
}: { const [isNPage, setNPage] = useState<number>(1);
dataPeserta: any;
eventId: string;
}) {
const [data, setData] = useState<MODEL_EVENT_PESERTA[]>(dataPeserta.data);
const [isNPage, setNPage] = useState(dataPeserta.nPage);
const [isActivePage, setActivePage] = useState(1); const [isActivePage, setActivePage] = useState(1);
const [isSearch, setSearch] = useState("");
useShallowEffect(() => {
loadInitialData();
}, [isActivePage, isSearch])
async function onPageClick(p: any) { const loadInitialData = async () => {
setActivePage(p); try {
const loadData = await adminEvent_getListPesertaById({ const response = await apiGetAdminDetailEventPesertaById({
eventId: eventId, id: params.id,
page: p, page: `${isActivePage}`,
}); search: isSearch,
setData(loadData.data as any); })
setNPage(loadData.nPage);
if (response?.success && response?.data.data) {
setData(response.data.data)
setNPage(response.data.nPage || 1)
} else {
console.error("Invalid data format recieved:", response);
setData([]);
}
} catch (error) {
clientLogger.error("Invalid data format recieved:", error);
setData([]);
}
} }
const tableRow = _.isEmpty(data) const onSearch = async (searchTerm: string) => {
? [] setSearch(searchTerm);
: data.map((e, i) => ( setActivePage(1);
}
const onPageClick = (page: number) => {
setActivePage(page);
}
const renderTableBody = () => {
if (!Array.isArray(data) || data.length === 0) {
return (
<tr>
<td colSpan={12}>
<Center>
<Text color={"gray"}>Tidak ada data</Text>
</Center>
</td>
</tr>
);
}
return data?.map((e, i) => (
<tr key={i}> <tr key={i}>
<td> <td>
<Center c={AdminColor.white}>{e?.User?.username}</Center> <Center c={AdminColor.white}>{e?.User?.username}</Center>
@@ -67,65 +105,81 @@ export function AdminEvent_ViewDetailPeserta({
</td> </td>
</tr> </tr>
)); ));
}
return ( return (
<> <>
<Stack spacing={"xs"} h={"100%"}> <Stack spacing={"xs"} h={"100%"}>
<Paper bg={AdminColor.softBlue} <ComponentAdminGlobal_TitlePage
p={"xs"} name="Daftar Peserta"
style={{ borderRadius: "6px" }}> color={AdminColor.softBlue}
<Title c={AdminColor.white} order={4}>Daftar Peserta</Title> component={
</Paper> <TextInput
<Paper p={"md"} bg={AdminColor.softBlue} shadow="lg" h={"75vh"}> disabled={!data}
<ScrollArea w={"100%"} h={"90%"}> icon={<IconSearch size={20} />}
<Table radius={"xl"}
verticalSpacing={"md"} placeholder="Masukan username"
horizontalSpacing={"md"}
p={"md"}
w={"100%"}
>
<thead>
<tr>
<th>
<Center c={AdminColor.white}>Username</Center>
</th>
<th>
<Center c={AdminColor.white}>Name</Center>
</th>
<th>
<Center c={AdminColor.white}>Nomor</Center>
</th>
<th>
<Center c={AdminColor.white}>Email</Center>
</th>
<th>
<Center c={AdminColor.white}>Konfirmasi Kehadiran</Center>
</th>
</tr>
</thead>
<tbody>{tableRow}</tbody>
</Table>
{_.isEmpty(data) ? (
<ComponentAdminGlobal_IsEmptyData
text="Tidak ada peserta"
marginTop={100}
/>
) : (
""
)}
</ScrollArea>
<Center mt={"xl"}>
<Pagination
value={isActivePage}
total={isNPage}
onChange={(val) => { onChange={(val) => {
onPageClick(val); onSearch(val.currentTarget.value);
}} }}
/> />
</Center> }
</Paper> />
{!data ? (
<CustomSkeleton height={"80vh"} width="100%" />
): (
<Paper p={"md"} bg={AdminColor.softBlue} shadow="lg" h={"75vh"}>
<ScrollArea w={"100%"} h={"90%"}>
<Table
verticalSpacing={"md"}
horizontalSpacing={"md"}
p={"md"}
w={"100%"}
>
<thead>
<tr>
<th>
<Center c={AdminColor.white}>Username</Center>
</th>
<th>
<Center c={AdminColor.white}>Name</Center>
</th>
<th>
<Center c={AdminColor.white}>Nomor</Center>
</th>
<th>
<Center c={AdminColor.white}>Email</Center>
</th>
<th>
<Center c={AdminColor.white}>Konfirmasi Kehadiran</Center>
</th>
</tr>
</thead>
<tbody>{renderTableBody()}</tbody>
</Table>
{_.isEmpty(data) ? (
<ComponentAdminGlobal_IsEmptyData
text="Tidak ada peserta"
marginTop={100}
/>
) : (
""
)}
</ScrollArea>
<Center mt={"xl"}>
<Pagination
value={isActivePage}
total={isNPage}
onChange={(val) => {
onPageClick(val);
}}
/>
</Center>
</Paper>
)}
</Stack> </Stack>
{/* <pre>{JSON.stringify(dataPeserta, null, 2)}</pre> */} {/* <pre>{JSON.stringify(dataPeserta, null, 2)}</pre> */}
</> </>

View File

@@ -53,7 +53,7 @@ function AdminEvent_DetailPublish() {
<AdminEvent_ViewDetailData /> <AdminEvent_ViewDetailData />
) : null} ) : null}
{selectPage == "2" ? ( {selectPage == "2" ? (
<AdminEvent_ViewDetailPeserta dataPeserta={{}} eventId={""}/> <AdminEvent_ViewDetailPeserta />
) : null} ) : null}
{selectPage == "3" ? ( {selectPage == "3" ? (
<AdminEvent_DetailDataSponsor /> <AdminEvent_DetailDataSponsor />

View File

@@ -1,10 +1,11 @@
export { export {
apiGetAdminForumPublishCountDasboard, apiGetAdminForumPublishCountDasboard,
apiGetAdminCountForumReportPosting , apiGetAdminCountForumReportPosting,
apiGetAdminCountForumReportKomentar, apiGetAdminCountForumReportKomentar,
apiGetAdminForumReportPosting, apiGetAdminForumReportPosting,
apiGetAdminForumReportKomentar, apiGetAdminForumReportKomentar,
apiGetAdminForumPublish apiGetAdminForumPublish,
apiGetAdminHasilReportPosting
} }
const apiGetAdminForumPublishCountDasboard = async () => { const apiGetAdminForumPublishCountDasboard = async () => {
@@ -58,7 +59,7 @@ const apiGetAdminCountForumReportKomentar = async () => {
return await response.json().catch(() => null); return await response.json().catch(() => null);
} }
const apiGetAdminForumReportPosting = async ({page} : { page?: string}) => { const apiGetAdminForumReportPosting = async ({ page }: { page?: string }) => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json()); const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null); if (!token) return await token.json().catch(() => null);
@@ -75,7 +76,7 @@ const apiGetAdminForumReportPosting = async ({page} : { page?: string}) => {
return await response.json().catch(() => null); return await response.json().catch(() => null);
} }
const apiGetAdminForumReportKomentar = async({ page } : { page?: string}) => { const apiGetAdminForumReportKomentar = async ({ page }: { page?: string }) => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json()); const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null); if (!token) return await token.json().catch(() => null);
@@ -92,12 +93,13 @@ const apiGetAdminForumReportKomentar = async({ page } : { page?: string}) => {
return await response.json().catch(() => null); return await response.json().catch(() => null);
} }
const apiGetAdminForumPublish = async ({ page }: { page?: string }) => { const apiGetAdminForumPublish = async (
{ page }: { page?: string }) => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json()); const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null); if (!token) return await token.json().catch(() => null);
const isPage = page ? `?page=${page}` : ""; const isPage = page ? `?page=${page}` : "";
const response = await fetch(`/api/admin/forum/publish${isPage}`, { const response = await fetch(`/api/admin/forum/publish/${isPage}`, {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -111,10 +113,21 @@ const apiGetAdminForumPublish = async ({ page }: { page?: string }) => {
return await response.json().catch(() => null); return await response.json().catch(() => null);
} }
const apiGetAdminHasilReportPosting = async ({id} : {id: string}) => { const apiGetAdminHasilReportPosting = async ({ page, id }: { page?: string, id: string }) => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json()); const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null); if (!token) return await token.json().catch(() => null);
const isPage = page ? `?page=${page}` : "";
const response = await fetch(`/api/admin/forum/${id}/report_posting${isPage}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
}
})
return await response.json().catch(() => null);
} }

View File

@@ -34,10 +34,8 @@ const middlewareConfig: MiddlewareConfig = {
// ADMIN API // ADMIN API
// >> buat dibawah sini << // >> buat dibawah sini <<
// "/api/admin/collaboration/*", "/api/admin/event/*",
// "/api/admin/investasi/*",
// "/api/admin/event/*",
// "/api/admin/forum/*",
// Akses awal // Akses awal
"/api/get-cookie", "/api/get-cookie",