Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | import { and, eq } from 'drizzle-orm' import { NextResponse } from 'next/server' import { db, schema } from '@/db' import { withAuth } from '@/lib/auth/withAuth' /** * POST /api/debug/archive-practice-students * * Bulk archive or unarchive all practice students for the current user. * Used by e2e tests to ensure a clean slate without deleting data. * * Body: { archive: boolean } * * Admin-only (via route-policy.csv: /api/debug/* → admin). */ export const POST = withAuth(async (request, { userId }) => { const body = await request.json() const { archive } = body if (typeof archive !== 'boolean') { return NextResponse.json({ error: 'archive must be a boolean' }, { status: 400 }) } const updated = await db .update(schema.players) .set({ isArchived: archive }) .where( and( eq(schema.players.userId, userId), eq(schema.players.isPracticeStudent, true), eq(schema.players.isArchived, !archive) ) ) .returning({ id: schema.players.id }) return NextResponse.json({ archived: archive, count: updated.length, }) }) |