Initial commit: ExaMetra v1.0.0 — Free & open-source competence & grading platform
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
This commit is contained in:
commit
0c1f739989
156 files changed
+51090
No files matched your search
@@ -0,0 +1,57 @@
|
||||
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 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { z } from 'zod';
|
||||
import { db } from '@/lib/db';
|
||||
import { getSession } from '@/lib/auth';
|
||||
|
||||
const entrySchema = z.object({
|
||||
studentId: z.string().min(1),
|
||||
competencyId: z.string().min(1),
|
||||
teacherId: z.string().min(1),
|
||||
classGroupId: z.string().min(1),
|
||||
date: z.string().transform((v) => new Date(v)),
|
||||
masteryLevelValue: z.number().int().min(1),
|
||||
note: z.string().optional(),
|
||||
});
|
||||
|
||||
const bulkEntrySchema = z.array(entrySchema);
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const studentId = searchParams.get('studentId');
|
||||
const classGroupId = searchParams.get('classGroupId');
|
||||
const competencyId = searchParams.get('competencyId');
|
||||
const startDate = searchParams.get('startDate');
|
||||
const endDate = searchParams.get('endDate');
|
||||
|
||||
const where: Record<string, unknown> = {};
|
||||
if (studentId) where.studentId = studentId;
|
||||
if (classGroupId) where.classGroupId = classGroupId;
|
||||
if (competencyId) where.competencyId = competencyId;
|
||||
|
||||
if (startDate || endDate) {
|
||||
const dateFilter: Record<string, unknown> = {};
|
||||
if (startDate) dateFilter.gte = new Date(startDate);
|
||||
if (endDate) dateFilter.lte = new Date(endDate);
|
||||
where.date = dateFilter;
|
||||
}
|
||||
|
||||
const entries = await db.learningProgressEntry.findMany({
|
||||
where,
|
||||
orderBy: { date: 'desc' },
|
||||
include: {
|
||||
student: { select: { id: true, firstName: true, lastName: true } },
|
||||
competency: {
|
||||
select: {
|
||||
id: true,
|
||||
code: true,
|
||||
title: true,
|
||||
category: { select: { id: true, name: true, color: true } },
|
||||
},
|
||||
},
|
||||
teacher: { select: { id: true, firstName: true, lastName: true } },
|
||||
classGroup: { select: { id: true, name: true } },
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(entries);
|
||||
} catch (error) {
|
||||
console.error('LearningProgress GET error:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
|
||||
// Support both single entry and bulk (array) entries
|
||||
const isBulk = Array.isArray(body);
|
||||
|
||||
if (isBulk) {
|
||||
const parsed = bulkEntrySchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Validation failed', details: parsed.error.issues },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const entries = await db.learningProgressEntry.createMany({
|
||||
data: parsed.data,
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{ created: entries.count },
|
||||
{ status: 201 }
|
||||
);
|
||||
} else {
|
||||
const parsed = entrySchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Validation failed', details: parsed.error.issues },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const entry = await db.learningProgressEntry.create({
|
||||
data: parsed.data,
|
||||
include: {
|
||||
student: { select: { id: true, firstName: true, lastName: true } },
|
||||
competency: {
|
||||
select: { id: true, code: true, title: true },
|
||||
},
|
||||
teacher: { select: { id: true, firstName: true, lastName: true } },
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(entry, { status: 201 });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('LearningProgress POST error:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user