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,151 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { z } from 'zod';
|
||||
import { db } from '@/lib/db';
|
||||
import { getSession } from '@/lib/auth';
|
||||
|
||||
const resultSchema = z.object({
|
||||
studentId: z.string().min(1),
|
||||
score: z.number().nullable().optional(),
|
||||
masteryLevelValue: z.number().int().nullable().optional(),
|
||||
note: z.string().optional(),
|
||||
});
|
||||
|
||||
const bulkResultSchema = z.array(resultSchema);
|
||||
|
||||
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: assessmentId } = await params;
|
||||
|
||||
const results = await db.assessmentResult.findMany({
|
||||
where: { assessmentId },
|
||||
include: {
|
||||
student: {
|
||||
select: { id: true, firstName: true, lastName: true },
|
||||
},
|
||||
assessment: {
|
||||
select: { id: true, title: true, maxScore: true },
|
||||
},
|
||||
},
|
||||
orderBy: { student: { lastName: 'asc' } },
|
||||
});
|
||||
|
||||
return NextResponse.json(results);
|
||||
} catch (error) {
|
||||
console.error('Assessment results 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: assessmentId } = await params;
|
||||
|
||||
const body = await request.json();
|
||||
const isBulk = Array.isArray(body);
|
||||
|
||||
if (isBulk) {
|
||||
const parsed = bulkResultSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Validation failed', details: parsed.error.issues },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Upsert each result (assessmentId + studentId is unique)
|
||||
const results: Array<{ id: string; studentId: string; score: number | null; masteryLevelValue: number | null; note: string | null; assessmentId: string }> = [];
|
||||
for (const item of parsed.data) {
|
||||
const result = await db.assessmentResult.upsert({
|
||||
where: {
|
||||
assessmentId_studentId: {
|
||||
assessmentId,
|
||||
studentId: item.studentId,
|
||||
},
|
||||
},
|
||||
update: {
|
||||
score: item.score ?? null,
|
||||
masteryLevelValue: item.masteryLevelValue ?? null,
|
||||
note: item.note ?? null,
|
||||
},
|
||||
create: {
|
||||
assessmentId,
|
||||
studentId: item.studentId,
|
||||
score: item.score ?? null,
|
||||
masteryLevelValue: item.masteryLevelValue ?? null,
|
||||
note: item.note ?? null,
|
||||
},
|
||||
});
|
||||
results.push(result);
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{ created: results.length },
|
||||
{ status: 201 }
|
||||
);
|
||||
} else {
|
||||
const parsed = resultSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Validation failed', details: parsed.error.issues },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const result = await db.assessmentResult.upsert({
|
||||
where: {
|
||||
assessmentId_studentId: {
|
||||
assessmentId,
|
||||
studentId: parsed.data.studentId,
|
||||
},
|
||||
},
|
||||
update: {
|
||||
score: parsed.data.score ?? null,
|
||||
masteryLevelValue: parsed.data.masteryLevelValue ?? null,
|
||||
note: parsed.data.note ?? null,
|
||||
},
|
||||
create: {
|
||||
assessmentId,
|
||||
studentId: parsed.data.studentId,
|
||||
score: parsed.data.score ?? null,
|
||||
masteryLevelValue: parsed.data.masteryLevelValue ?? null,
|
||||
note: parsed.data.note ?? null,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(result, { status: 201 });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Assessment results POST error:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { z } from 'zod';
|
||||
import { db } from '@/lib/db';
|
||||
import { getSession } from '@/lib/auth';
|
||||
|
||||
const competencyLinkSchema = z.object({
|
||||
competencyId: z.string().min(1),
|
||||
weight: z.number().default(1.0),
|
||||
});
|
||||
|
||||
const createAssessmentSchema = z.object({
|
||||
classGroupId: z.string().min(1),
|
||||
subjectId: z.string().min(1),
|
||||
teacherId: z.string().min(1),
|
||||
title: z.string().min(1),
|
||||
date: z.string().transform((v) => new Date(v)),
|
||||
type: z.enum(['TEST', 'ORAL', 'PROJECT', 'HOMEWORK', 'OTHER']).default('TEST'),
|
||||
maxScore: z.number().nullable().optional(),
|
||||
weight: z.number().default(1.0),
|
||||
competencyLinks: z.array(competencyLinkSchema).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 classGroupId = searchParams.get('classGroupId');
|
||||
const subjectId = searchParams.get('subjectId');
|
||||
|
||||
const where: Record<string, unknown> = {};
|
||||
if (classGroupId) where.classGroupId = classGroupId;
|
||||
if (subjectId) where.subjectId = subjectId;
|
||||
|
||||
const assessments = await db.assessment.findMany({
|
||||
where,
|
||||
orderBy: { date: 'desc' },
|
||||
include: {
|
||||
classGroup: { select: { id: true, name: true } },
|
||||
subject: { select: { id: true, name: true } },
|
||||
teacher: { select: { id: true, firstName: true, lastName: true } },
|
||||
assessmentCompetencyLinks: {
|
||||
include: {
|
||||
competency: {
|
||||
select: { id: true, code: true, title: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
_count: {
|
||||
select: { assessmentResults: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(assessments);
|
||||
} catch (error) {
|
||||
console.error('Assessments 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 = createAssessmentSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Validation failed', details: parsed.error.issues },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const { competencyLinks, ...assessmentData } = parsed.data;
|
||||
|
||||
const assessment = await db.assessment.create({
|
||||
data: {
|
||||
classGroupId: assessmentData.classGroupId,
|
||||
subjectId: assessmentData.subjectId,
|
||||
teacherId: assessmentData.teacherId,
|
||||
title: assessmentData.title,
|
||||
date: assessmentData.date,
|
||||
type: assessmentData.type,
|
||||
maxScore: assessmentData.maxScore ?? null,
|
||||
weight: assessmentData.weight,
|
||||
assessmentCompetencyLinks: competencyLinks
|
||||
? {
|
||||
create: competencyLinks.map((link) => ({
|
||||
competencyId: link.competencyId,
|
||||
weight: link.weight,
|
||||
})),
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
include: {
|
||||
classGroup: { select: { id: true, name: true } },
|
||||
subject: { select: { id: true, name: true } },
|
||||
teacher: { select: { id: true, firstName: true, lastName: true } },
|
||||
assessmentCompetencyLinks: {
|
||||
include: {
|
||||
competency: { select: { id: true, code: true, title: true } },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(assessment, { status: 201 });
|
||||
} catch (error) {
|
||||
console.error('Assessments POST error:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user