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,127 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { z } from 'zod';
|
||||
import { db } from '@/lib/db';
|
||||
import { getSession } from '@/lib/auth';
|
||||
|
||||
export async function GET(
|
||||
_request: Request,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
|
||||
}
|
||||
|
||||
const { id: classGroupId } = await params;
|
||||
|
||||
const enrollments = await db.enrollment.findMany({
|
||||
where: {
|
||||
classGroupId,
|
||||
endDate: null,
|
||||
student: { deletedAt: null },
|
||||
},
|
||||
include: {
|
||||
student: true,
|
||||
schoolYear: { select: { id: true, label: true } },
|
||||
},
|
||||
orderBy: { student: { lastName: 'asc' } },
|
||||
});
|
||||
|
||||
const students = enrollments.map((e) => ({
|
||||
...e.student,
|
||||
enrollmentId: e.id,
|
||||
schoolYearId: e.schoolYearId,
|
||||
schoolYear: e.schoolYear,
|
||||
startDate: e.startDate,
|
||||
}));
|
||||
|
||||
return NextResponse.json(students);
|
||||
} catch (error) {
|
||||
console.error('Class students GET error:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
|
||||
}
|
||||
|
||||
if (
|
||||
session.user?.role !== 'SUPER_ADMIN' &&
|
||||
session.user?.role !== 'SCHOOL_ADMIN' &&
|
||||
session.user?.role !== 'TEACHER'
|
||||
) {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
}
|
||||
|
||||
const { id: classGroupId } = await params;
|
||||
|
||||
const body = await request.json();
|
||||
const schema = z.object({
|
||||
studentId: z.string().min(1),
|
||||
schoolYearId: z.string().min(1),
|
||||
startDate: z
|
||||
.string()
|
||||
.optional()
|
||||
.transform((v) => (v ? new Date(v) : new Date())),
|
||||
});
|
||||
|
||||
const parsed = schema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Validation failed', details: parsed.error.issues },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const { studentId, schoolYearId, startDate } = parsed.data;
|
||||
|
||||
// Check if already enrolled
|
||||
const existing = await db.enrollment.findFirst({
|
||||
where: {
|
||||
studentId,
|
||||
classGroupId,
|
||||
endDate: null,
|
||||
},
|
||||
});
|
||||
|
||||
if (existing) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Student already enrolled in this class' },
|
||||
{ status: 409 }
|
||||
);
|
||||
}
|
||||
|
||||
const enrollment = await db.enrollment.create({
|
||||
data: {
|
||||
studentId,
|
||||
classGroupId,
|
||||
schoolYearId,
|
||||
startDate,
|
||||
},
|
||||
include: {
|
||||
student: true,
|
||||
classGroup: true,
|
||||
schoolYear: { select: { id: true, label: true } },
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(enrollment, { status: 201 });
|
||||
} catch (error) {
|
||||
console.error('Class students POST error:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { z } from 'zod';
|
||||
import { db } from '@/lib/db';
|
||||
import { getSession } from '@/lib/auth';
|
||||
|
||||
const createClassSchema = z.object({
|
||||
schoolId: z.string().min(1),
|
||||
schoolYearId: z.string().min(1),
|
||||
name: z.string().min(1),
|
||||
gradeLevel: z.number().int().min(1).max(13),
|
||||
schoolType: z
|
||||
.enum(['ELEMENTARY', 'MIDDLE', 'GYMNASIUM', 'OTHER'])
|
||||
.default('ELEMENTARY'),
|
||||
teacherIds: z.array(z.string()).optional(),
|
||||
});
|
||||
|
||||
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 schoolId = searchParams.get('schoolId');
|
||||
const schoolYearId = searchParams.get('schoolYearId');
|
||||
|
||||
const where: Record<string, unknown> = {};
|
||||
if (schoolId) where.schoolId = schoolId;
|
||||
if (schoolYearId) where.schoolYearId = schoolYearId;
|
||||
|
||||
// If teacher role, only show their assigned classes
|
||||
if (session.user?.role === 'TEACHER' && session.userId) {
|
||||
where.teachers = { some: { userId: session.userId } };
|
||||
}
|
||||
|
||||
const classes = await db.classGroup.findMany({
|
||||
where,
|
||||
orderBy: { name: 'asc' },
|
||||
include: {
|
||||
school: { select: { id: true, name: true } },
|
||||
schoolYear: { select: { id: true, label: true } },
|
||||
teachers: {
|
||||
include: {
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
email: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
_count: {
|
||||
select: {
|
||||
enrollments: {
|
||||
where: { endDate: null },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const result = classes.map((cls) => ({
|
||||
...cls,
|
||||
studentCount: cls._count.enrollments,
|
||||
teacherList: cls.teachers.map((t) => ({
|
||||
...t.user,
|
||||
teacherRole: t.role,
|
||||
})),
|
||||
}));
|
||||
|
||||
return NextResponse.json(result);
|
||||
} catch (error) {
|
||||
console.error('Classes 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 });
|
||||
}
|
||||
|
||||
if (
|
||||
session.user?.role !== 'SUPER_ADMIN' &&
|
||||
session.user?.role !== 'SCHOOL_ADMIN' &&
|
||||
session.user?.role !== 'TEACHER'
|
||||
) {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const parsed = createClassSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Validation failed', details: parsed.error.issues },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const { teacherIds, ...classData } = parsed.data;
|
||||
|
||||
const classGroup = await db.classGroup.create({
|
||||
data: {
|
||||
...classData,
|
||||
teachers: teacherIds
|
||||
? {
|
||||
create: teacherIds.map((userId) => ({
|
||||
userId,
|
||||
role: 'SUBJECT_TEACHER' as const,
|
||||
})),
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
include: {
|
||||
school: { select: { id: true, name: true } },
|
||||
schoolYear: { select: { id: true, label: true } },
|
||||
teachers: {
|
||||
include: {
|
||||
user: {
|
||||
select: { id: true, firstName: true, lastName: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(classGroup, { status: 201 });
|
||||
} catch (error) {
|
||||
console.error('Classes POST error:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function PUT(request: Request) {
|
||||
try {
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
|
||||
}
|
||||
|
||||
if (
|
||||
session.user?.role !== 'SUPER_ADMIN' &&
|
||||
session.user?.role !== 'SCHOOL_ADMIN' &&
|
||||
session.user?.role !== 'TEACHER'
|
||||
) {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const updateSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
name: z.string().min(1).optional(),
|
||||
gradeLevel: z.number().int().min(1).max(13).optional(),
|
||||
schoolType: z
|
||||
.enum(['ELEMENTARY', 'MIDDLE', 'GYMNASIUM', 'OTHER'])
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const parsed = updateSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Validation failed', details: parsed.error.issues },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const { id, ...updateData } = parsed.data;
|
||||
|
||||
const classGroup = await db.classGroup.update({
|
||||
where: { id },
|
||||
data: updateData,
|
||||
include: {
|
||||
school: { select: { id: true, name: true } },
|
||||
schoolYear: { select: { id: true, label: true } },
|
||||
teachers: {
|
||||
include: {
|
||||
user: {
|
||||
select: { id: true, firstName: true, lastName: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(classGroup);
|
||||
} catch (error) {
|
||||
console.error('Classes PUT error:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user