fix ( event )
deskripsi: - fix API: detail, check-peserta, peserta
This commit is contained in:
71
src/app/api/event/peserta/[id]/route.ts
Normal file
71
src/app/api/event/peserta/[id]/route.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
context: { params: { id: string } }
|
||||
) {
|
||||
const method = request.method;
|
||||
if (method !== "GET") {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Method not allowed" },
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
let fixData;
|
||||
const { id } = context.params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const page = searchParams.get("page");
|
||||
const takeData = 10;
|
||||
const skipData = Number(page) * takeData - takeData;
|
||||
|
||||
fixData = await prisma.event_Peserta.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
eventId: id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
active: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
userId: true,
|
||||
isPresent: true,
|
||||
User: {
|
||||
select: {
|
||||
Profile: true,
|
||||
},
|
||||
},
|
||||
Event: true,
|
||||
eventId: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
||||
console.log("server", fixData)
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Success get data",
|
||||
data: fixData,
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
backendLogger.error("Error get list data:", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Failed get data",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -37,5 +37,26 @@ export const apiGetEventCekPeserta = async ({
|
||||
);
|
||||
|
||||
return await response.json().catch(() => null);
|
||||
|
||||
};
|
||||
|
||||
export const apiGetEventPesertaById = async ({
|
||||
id,
|
||||
page,
|
||||
}: {
|
||||
id: string;
|
||||
page: string;
|
||||
}) => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const response = await fetch(`/api/event/peserta/${id}?page=${page}`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
@@ -39,6 +39,7 @@ export default function Event_DetailMain({
|
||||
});
|
||||
|
||||
if (respone) {
|
||||
console.log(respone.data)
|
||||
setIsJoinSuccess(respone.data);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,21 +1,50 @@
|
||||
"use client"
|
||||
"use client";
|
||||
|
||||
import { Stack } from '@mantine/core';
|
||||
import ComponentEvent_ListPeserta from '../../component/detail/list_peserta';
|
||||
import { MODEL_EVENT_PESERTA } from '../../model/interface';
|
||||
import { useParams } from 'next/navigation';
|
||||
import ComponentEvent_ListPesertaNew from '../../component/detail/list_peserta_new';
|
||||
import { Stack } from "@mantine/core";
|
||||
import ComponentEvent_ListPeserta from "../../component/detail/list_peserta";
|
||||
import { MODEL_EVENT_PESERTA } from "../../model/interface";
|
||||
import { useParams } from "next/navigation";
|
||||
import ComponentEvent_ListPesertaNew from "../../component/detail/list_peserta_new";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { apiGetEventPesertaById } from "../../_lib/api_event";
|
||||
import { useState } from "react";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
|
||||
// function Event_DaftarPeserta({ totalPeserta, eventId, isNewPeserta }: {
|
||||
// totalPeserta?: number;
|
||||
// eventId?: string;
|
||||
// isNewPeserta?: boolean | null;
|
||||
// }) {
|
||||
function Event_DaftarPeserta() {
|
||||
function Event_DaftarPeserta() {
|
||||
const params = useParams<{ id: string }>();
|
||||
|
||||
const [data, setData] = useState<MODEL_EVENT_PESERTA[] | null>(null);
|
||||
const [activePage, setActivePage] = useState(1);
|
||||
|
||||
useShallowEffect(() => {
|
||||
onLoadDataPeserta();
|
||||
}, []);
|
||||
|
||||
async function onLoadDataPeserta() {
|
||||
try {
|
||||
const respone = await apiGetEventPesertaById({
|
||||
id: params.id,
|
||||
page: `${activePage}`,
|
||||
});
|
||||
|
||||
if (respone) {
|
||||
console.log(respone.data);
|
||||
setData(respone.data);
|
||||
}
|
||||
} catch (error) {
|
||||
clientLogger.error("Error get data peserta:", error);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack>
|
||||
<ComponentEvent_ListPesertaNew/>
|
||||
<ComponentEvent_ListPesertaNew />
|
||||
{/* <ComponentEvent_ListPeserta eventId={params.id} total={totalPeserta as any} isNewPeserta={isNewPeserta} /> */}
|
||||
</Stack>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user