API Mobile Event

Add:
- api/mobile/event/[id]/check-participants : untuk cek keikut sertaan peserta

Fix:
- api/mobile/event/route : tambah get berdasarkan kategory
- mobile/event/[id]/participants/route: clear code

### No Issue
This commit is contained in:
2025-09-15 17:22:37 +08:00
parent c89ad88d2d
commit 836d12bf2e
3 changed files with 234 additions and 65 deletions

View File

@@ -0,0 +1,48 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
export {GET}
async function GET(request: Request, { params }: { params: { id: string } }) {
try {
const { id } = params;
const { searchParams } = new URL(request.url);
const userId = searchParams.get("userId");
let fixData
const checkParticipant = await prisma.event_Peserta.findFirst({
where: {
userId: userId as any,
eventId: id,
},
});
if (checkParticipant !== null) {
fixData = true;
} else {
fixData = false;
}
return NextResponse.json(
{
success: true,
message: "Success get participants",
data: fixData,
},
{ status: 200 }
);
} catch (error) {
return NextResponse.json(
{
success: false,
message: "Error get participants",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -1,14 +1,13 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
import { NextResponse } from "next/server";
export { POST , GET};
export { GET, POST };
async function POST(request: Request, { params }: { params: { id: string } }) {
try {
const { id } = params;
const { userId } = await request.json();
const createJoin = await prisma.event_Peserta.create({
data: {
eventId: id,
@@ -49,6 +48,7 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
async function GET(request: Request, { params }: { params: { id: string } }) {
try {
const { id } = params;
const data = await prisma.event_Peserta.findMany({
where: {
eventId: id,
@@ -63,6 +63,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
username: true,
Profile: {
select: {
id: true,
name: true,
imageId: true,
},