(request: NextRequest)
| 9 | import { logger } from '@/util/logger' |
| 10 | |
| 11 | export async function PATCH(request: NextRequest) { |
| 12 | try { |
| 13 | // Check admin authentication |
| 14 | const authResult = await checkAdminAuth() |
| 15 | if (authResult instanceof NextResponse) { |
| 16 | return authResult |
| 17 | } |
| 18 | |
| 19 | const body = await request.json() |
| 20 | const { id, is_public } = body |
| 21 | |
| 22 | // Validate request body |
| 23 | if (!id || typeof is_public !== 'boolean') { |
| 24 | return NextResponse.json( |
| 25 | { error: 'Missing or invalid required fields: id, is_public' }, |
| 26 | { status: 400 }, |
| 27 | ) |
| 28 | } |
| 29 | |
| 30 | // Update the eval result visibility |
| 31 | const [updatedResult] = await db |
| 32 | .update(schema.gitEvalResults) |
| 33 | .set({ is_public }) |
| 34 | .where(eq(schema.gitEvalResults.id, id)) |
| 35 | .returning() |
| 36 | |
| 37 | if (!updatedResult) { |
| 38 | return NextResponse.json( |
| 39 | { error: 'Eval result not found' }, |
| 40 | { status: 404 }, |
| 41 | ) |
| 42 | } |
| 43 | |
| 44 | logger.info( |
| 45 | { |
| 46 | evalResultId: id, |
| 47 | is_public, |
| 48 | adminUserId: authResult.id, |
| 49 | }, |
| 50 | 'Updated eval result visibility', |
| 51 | ) |
| 52 | |
| 53 | return NextResponse.json(updatedResult) |
| 54 | } catch (error) { |
| 55 | logger.error({ error }, 'Error updating eval result visibility') |
| 56 | return NextResponse.json( |
| 57 | { error: 'Internal server error' }, |
| 58 | { status: 500 }, |
| 59 | ) |
| 60 | } |
| 61 | } |
nothing calls this directly
no test coverage detected