Features: - 15+ views: Dashboard, Classes, Progress, Flower, Matrix, Assessments, Grading, Reports, Attendance, Calendar, Lesson Plans, Analytics, Parent Communication, Behavior Tracking, Settings - 34+ API endpoints - 30+ Prisma models - 700+ i18n keys (German + English) - Keyboard shortcuts (Cmd+K, Cmd+1-9, Cmd+/) - Batch deletion, drag-and-drop seating, custom color palette - Demo accounts (admin, teacher, student, parent) - Dark mode, responsive design, print styles - CSV/PDF export, notification system, onboarding tour - Zero emojis — all replaced with Lucide icons - MIT License
58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { z } from 'zod';
|
|
import { db } from '@/lib/db';
|
|
import { getSession } from '@/lib/auth';
|
|
|
|
const batchDeleteSchema = z.object({
|
|
ids: z.array(z.string()).min(1).max(200),
|
|
});
|
|
|
|
export async function DELETE(req: NextRequest) {
|
|
const session = await getSession();
|
|
if (!session?.user) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
}
|
|
if (session.user.role !== 'TEACHER' && session.user.role !== 'SCHOOL_ADMIN' && session.user.role !== 'SUPER_ADMIN') {
|
|
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
|
}
|
|
|
|
let body: unknown;
|
|
try {
|
|
body = await req.json();
|
|
} catch {
|
|
return NextResponse.json({ error: 'Invalid JSON' }, { status: 400 });
|
|
}
|
|
|
|
const parsed = batchDeleteSchema.safeParse(body);
|
|
if (!parsed.success) {
|
|
return NextResponse.json({ error: parsed.error.issues.map((i) => i.message).join(', ') }, { status: 400 });
|
|
}
|
|
|
|
const { ids } = parsed.data;
|
|
|
|
try {
|
|
const result = await db.learningProgressEntry.deleteMany({
|
|
where: {
|
|
id: { in: ids },
|
|
teacherId: session.userId,
|
|
},
|
|
});
|
|
|
|
// Audit log
|
|
await db.auditLog.create({
|
|
data: {
|
|
userId: session.userId,
|
|
schoolId: session.user.schoolId,
|
|
action: 'BATCH_DELETE',
|
|
entityType: 'LearningProgressEntry',
|
|
metadata: JSON.stringify({ count: result.count, ids }),
|
|
},
|
|
});
|
|
|
|
return NextResponse.json({ deleted: result.count });
|
|
} catch (error) {
|
|
console.error('Batch delete error:', error);
|
|
return NextResponse.json({ error: 'Failed to delete entries' }, { status: 500 });
|
|
}
|
|
}
|