|
1 | 1 | import { DisclaimersService } from '@/src/services/disclaimers' |
| 2 | +import { prisma } from '@klicker-uzh/prisma' |
2 | 3 | import { jwtVerify, type JWTPayload } from 'jose' |
3 | 4 | import { NextRequest, NextResponse } from 'next/server' |
4 | 5 |
|
@@ -47,6 +48,37 @@ export async function GET( |
47 | 48 | ) |
48 | 49 | } |
49 | 50 |
|
| 51 | + // check participation |
| 52 | + try { |
| 53 | + const participation = await prisma.participation.findUnique({ |
| 54 | + where: { |
| 55 | + courseId_participantId: { |
| 56 | + courseId: |
| 57 | + ( |
| 58 | + await prisma.chatbot.findUnique({ |
| 59 | + where: { id: chatbotId }, |
| 60 | + select: { courseId: true }, |
| 61 | + }) |
| 62 | + )?.courseId ?? '', |
| 63 | + participantId: participantId, |
| 64 | + }, |
| 65 | + }, |
| 66 | + }) |
| 67 | + |
| 68 | + if (!participation) { |
| 69 | + return NextResponse.json( |
| 70 | + { error: 'No valid participation found for this chatbot' }, |
| 71 | + { status: 403 } |
| 72 | + ) |
| 73 | + } |
| 74 | + } catch (error) { |
| 75 | + console.error('Error checking participation:', error) |
| 76 | + return NextResponse.json( |
| 77 | + { error: 'Error checking participation' }, |
| 78 | + { status: 500 } |
| 79 | + ) |
| 80 | + } |
| 81 | + |
50 | 82 | try { |
51 | 83 | // Get disclaimer for chatbot |
52 | 84 | const disclaimer = |
@@ -114,6 +146,37 @@ export async function POST( |
114 | 146 | ) |
115 | 147 | } |
116 | 148 |
|
| 149 | + // check participation |
| 150 | + try { |
| 151 | + const participation = await prisma.participation.findUnique({ |
| 152 | + where: { |
| 153 | + courseId_participantId: { |
| 154 | + courseId: |
| 155 | + ( |
| 156 | + await prisma.chatbot.findUnique({ |
| 157 | + where: { id: chatbotId }, |
| 158 | + select: { courseId: true }, |
| 159 | + }) |
| 160 | + )?.courseId ?? '', |
| 161 | + participantId: participantId, |
| 162 | + }, |
| 163 | + }, |
| 164 | + }) |
| 165 | + |
| 166 | + if (!participation) { |
| 167 | + return NextResponse.json( |
| 168 | + { error: 'No valid participation found for this chatbot' }, |
| 169 | + { status: 403 } |
| 170 | + ) |
| 171 | + } |
| 172 | + } catch (error) { |
| 173 | + console.error('Error checking participation:', error) |
| 174 | + return NextResponse.json( |
| 175 | + { error: 'Error checking participation' }, |
| 176 | + { status: 500 } |
| 177 | + ) |
| 178 | + } |
| 179 | + |
117 | 180 | try { |
118 | 181 | const body = await req.json() |
119 | 182 | const { action, disclaimerId } = body |
|
0 commit comments