55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
import { NextResponse } from "next/server"
|
|
|
|
import { auth } from "@/auth"
|
|
import { prisma } from "@/lib/prisma"
|
|
import { isHostOrCoHost } from "@/lib/meeting-auth"
|
|
|
|
export async function POST(
|
|
_request: Request,
|
|
{ params }: { params: Promise<{ meetingUuid: string; participantId: string }> }
|
|
) {
|
|
const { meetingUuid, participantId } = await params
|
|
|
|
const session = await auth()
|
|
if (!session?.user?.id) {
|
|
return NextResponse.json({ error: "No autenticado" }, { status: 401 })
|
|
}
|
|
|
|
const meeting = await prisma.meeting.findUnique({
|
|
where: { uuid: meetingUuid },
|
|
})
|
|
|
|
if (!meeting) {
|
|
return NextResponse.json(
|
|
{ error: "Reunión no encontrada" },
|
|
{ status: 404 }
|
|
)
|
|
}
|
|
|
|
const userId = Number(session.user.id)
|
|
if (!(await isHostOrCoHost(meeting, userId))) {
|
|
return NextResponse.json(
|
|
{ error: "No tienes permiso para admitir participantes" },
|
|
{ status: 403 }
|
|
)
|
|
}
|
|
|
|
const participant = await prisma.meetingParticipant.findUnique({
|
|
where: { id: Number(participantId) },
|
|
})
|
|
|
|
if (!participant || participant.meetingId !== meeting.id) {
|
|
return NextResponse.json(
|
|
{ error: "Participante no encontrado" },
|
|
{ status: 404 }
|
|
)
|
|
}
|
|
|
|
const updated = await prisma.meetingParticipant.update({
|
|
where: { id: participant.id },
|
|
data: { status: "admitted", admittedAt: new Date() },
|
|
})
|
|
|
|
return NextResponse.json({ id: updated.id, status: updated.status })
|
|
}
|