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,111 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { db } from '@/lib/db';
|
||||
import { getSession } from '@/lib/auth';
|
||||
|
||||
function isTeacherOrAdmin(role: string | undefined): boolean {
|
||||
return (
|
||||
role === 'TEACHER' ||
|
||||
role === 'SCHOOL_ADMIN' ||
|
||||
role === 'SUPER_ADMIN'
|
||||
);
|
||||
}
|
||||
|
||||
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 (!isTeacherOrAdmin(session.user?.role)) {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
}
|
||||
|
||||
const { id } = await params;
|
||||
const existing = await db.rubric.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
criteria: {
|
||||
orderBy: { order: 'asc' },
|
||||
include: { levels: { orderBy: { order: 'asc' } } },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!existing) {
|
||||
return NextResponse.json({ error: 'Rubric not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
if (
|
||||
session.user?.role === 'SCHOOL_ADMIN' &&
|
||||
session.user.schoolId &&
|
||||
existing.schoolId !== session.user.schoolId
|
||||
) {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
}
|
||||
|
||||
// Create a duplicate with incremented version
|
||||
const { criteria, ...rubricData } = existing;
|
||||
const duplicated = await db.rubric.create({
|
||||
data: {
|
||||
schoolId: rubricData.schoolId,
|
||||
teacherId: session.userId,
|
||||
subjectId: rubricData.subjectId,
|
||||
title: `${rubricData.title} (Kopie)`,
|
||||
description: rubricData.description,
|
||||
type: rubricData.type,
|
||||
maxPoints: rubricData.maxPoints,
|
||||
isPublic: false, // Duplicates start as private
|
||||
version: rubricData.version + 1,
|
||||
criteria: {
|
||||
create: criteria.map((c, ci) => ({
|
||||
name: c.name,
|
||||
description: c.description,
|
||||
weight: c.weight,
|
||||
maxPoints: c.maxPoints,
|
||||
order: c.order ?? ci,
|
||||
levels: {
|
||||
create: c.levels.map((l, li) => ({
|
||||
label: l.label,
|
||||
description: l.description,
|
||||
points: l.points,
|
||||
order: l.order ?? li,
|
||||
})),
|
||||
},
|
||||
})),
|
||||
},
|
||||
},
|
||||
include: {
|
||||
criteria: {
|
||||
orderBy: { order: 'asc' },
|
||||
include: { levels: { orderBy: { order: 'asc' } } },
|
||||
},
|
||||
teacher: { select: { id: true, firstName: true, lastName: true } },
|
||||
subject: { select: { id: true, name: true } },
|
||||
},
|
||||
});
|
||||
|
||||
await db.auditLog.create({
|
||||
data: {
|
||||
userId: session.userId,
|
||||
schoolId: existing.schoolId,
|
||||
action: 'CREATE',
|
||||
entityType: 'Rubric',
|
||||
entityId: duplicated.id,
|
||||
metadata: JSON.stringify({
|
||||
title: duplicated.title,
|
||||
type: 'DUPLICATE',
|
||||
sourceRubricId: id,
|
||||
sourceTitle: existing.title,
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(duplicated, { status: 201 });
|
||||
} catch (error) {
|
||||
console.error('Rubric Duplicate POST error:', error);
|
||||
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { z } from 'zod';
|
||||
import { db } from '@/lib/db';
|
||||
import { getSession } from '@/lib/auth';
|
||||
|
||||
function isTeacherOrAdmin(role: string | undefined): boolean {
|
||||
return (
|
||||
role === 'TEACHER' ||
|
||||
role === 'SCHOOL_ADMIN' ||
|
||||
role === 'SUPER_ADMIN'
|
||||
);
|
||||
}
|
||||
|
||||
const levelSchema = z.object({
|
||||
id: z.string().optional(),
|
||||
label: z.string().min(1).max(100),
|
||||
description: z.string().min(1).max(2000),
|
||||
points: z.int().min(0),
|
||||
order: z.int().min(0).default(0),
|
||||
});
|
||||
|
||||
const criterionSchema = z.object({
|
||||
id: z.string().optional(),
|
||||
name: z.string().min(1).max(200),
|
||||
description: z.string().max(1000).optional().nullable(),
|
||||
weight: z.number().min(0).default(1.0),
|
||||
maxPoints: z.int().min(1),
|
||||
order: z.int().min(0).default(0),
|
||||
levels: z.array(levelSchema).min(1),
|
||||
});
|
||||
|
||||
const updateRubricSchema = z.object({
|
||||
title: z.string().min(1).max(200).optional(),
|
||||
description: z.string().max(2000).optional().nullable(),
|
||||
type: z.enum(['ANALYTIC', 'HOLISTIC']).optional(),
|
||||
subjectId: z.string().optional().nullable(),
|
||||
maxPoints: z.int().min(1).optional(),
|
||||
isPublic: z.boolean().optional(),
|
||||
criteria: z.array(criterionSchema).min(1).optional(),
|
||||
});
|
||||
|
||||
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 });
|
||||
}
|
||||
if (!isTeacherOrAdmin(session.user?.role)) {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
}
|
||||
|
||||
const { id } = await params;
|
||||
const rubric = await db.rubric.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
criteria: {
|
||||
orderBy: { order: 'asc' },
|
||||
include: { levels: { orderBy: { order: 'asc' } } },
|
||||
},
|
||||
teacher: { select: { id: true, firstName: true, lastName: true } },
|
||||
subject: { select: { id: true, name: true } },
|
||||
},
|
||||
});
|
||||
|
||||
if (!rubric) {
|
||||
return NextResponse.json({ error: 'Rubric not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
if (
|
||||
session.user?.role === 'SCHOOL_ADMIN' &&
|
||||
session.user.schoolId &&
|
||||
rubric.schoolId !== session.user.schoolId
|
||||
) {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
}
|
||||
|
||||
return NextResponse.json(rubric);
|
||||
} catch (error) {
|
||||
console.error('Rubric GET error:', error);
|
||||
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function PUT(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
|
||||
}
|
||||
if (!isTeacherOrAdmin(session.user?.role)) {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
}
|
||||
|
||||
const { id } = await params;
|
||||
const body = await request.json();
|
||||
const parsed = updateRubricSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Validation failed', details: parsed.error.issues },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const existing = await db.rubric.findUnique({ where: { id } });
|
||||
if (!existing) {
|
||||
return NextResponse.json({ error: 'Rubric not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
if (
|
||||
session.user?.role === 'SCHOOL_ADMIN' &&
|
||||
session.user.schoolId &&
|
||||
existing.schoolId !== session.user.schoolId
|
||||
) {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
}
|
||||
|
||||
// Only the owner or admin can update
|
||||
if (existing.teacherId !== session.userId && session.user?.role !== 'SCHOOL_ADMIN' && session.user?.role !== 'SUPER_ADMIN') {
|
||||
return NextResponse.json({ error: 'Only the owner can edit this rubric' }, { status: 403 });
|
||||
}
|
||||
|
||||
const { criteria, subjectId, ...rest } = parsed.data;
|
||||
|
||||
// Update scalar fields
|
||||
const updateData: Record<string, unknown> = {};
|
||||
if (rest.title !== undefined) updateData.title = rest.title;
|
||||
if (rest.description !== undefined) updateData.description = rest.description;
|
||||
if (rest.type !== undefined) updateData.type = rest.type;
|
||||
if (rest.maxPoints !== undefined) updateData.maxPoints = rest.maxPoints;
|
||||
if (rest.isPublic !== undefined) updateData.isPublic = rest.isPublic;
|
||||
if (subjectId !== undefined) updateData.subjectId = subjectId ?? null;
|
||||
|
||||
// Handle nested criteria update
|
||||
if (criteria) {
|
||||
// Delete existing criteria (cascade will delete levels)
|
||||
await db.rubricCriterion.deleteMany({ where: { rubricId: id } });
|
||||
|
||||
// Create new criteria with levels
|
||||
updateData.criteria = {
|
||||
create: criteria.map((c, ci) => ({
|
||||
name: c.name,
|
||||
description: c.description ?? null,
|
||||
weight: c.weight,
|
||||
maxPoints: c.maxPoints,
|
||||
order: c.order ?? ci,
|
||||
levels: {
|
||||
create: c.levels.map((l, li) => ({
|
||||
label: l.label,
|
||||
description: l.description,
|
||||
points: l.points,
|
||||
order: l.order ?? li,
|
||||
})),
|
||||
},
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
const updated = await db.rubric.update({
|
||||
where: { id },
|
||||
data: updateData,
|
||||
include: {
|
||||
criteria: {
|
||||
orderBy: { order: 'asc' },
|
||||
include: { levels: { orderBy: { order: 'asc' } } },
|
||||
},
|
||||
teacher: { select: { id: true, firstName: true, lastName: true } },
|
||||
subject: { select: { id: true, name: true } },
|
||||
},
|
||||
});
|
||||
|
||||
await db.auditLog.create({
|
||||
data: {
|
||||
userId: session.userId,
|
||||
schoolId: existing.schoolId,
|
||||
action: 'UPDATE',
|
||||
entityType: 'Rubric',
|
||||
entityId: id,
|
||||
metadata: JSON.stringify({ title: updated.title, updatedFields: Object.keys(rest) }),
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(updated);
|
||||
} catch (error) {
|
||||
console.error('Rubric PUT error:', error);
|
||||
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(
|
||||
_request: Request,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
|
||||
}
|
||||
if (!isTeacherOrAdmin(session.user?.role)) {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
}
|
||||
|
||||
const { id } = await params;
|
||||
const existing = await db.rubric.findUnique({ where: { id } });
|
||||
if (!existing) {
|
||||
return NextResponse.json({ error: 'Rubric not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
if (
|
||||
session.user?.role === 'SCHOOL_ADMIN' &&
|
||||
session.user.schoolId &&
|
||||
existing.schoolId !== session.user.schoolId
|
||||
) {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
}
|
||||
|
||||
// Only the owner or admin can delete
|
||||
if (existing.teacherId !== session.userId && session.user?.role !== 'SCHOOL_ADMIN' && session.user?.role !== 'SUPER_ADMIN') {
|
||||
return NextResponse.json({ error: 'Only the owner can delete this rubric' }, { status: 403 });
|
||||
}
|
||||
|
||||
// Cascade will delete criteria and levels
|
||||
await db.rubric.delete({ where: { id } });
|
||||
|
||||
await db.auditLog.create({
|
||||
data: {
|
||||
userId: session.userId,
|
||||
schoolId: existing.schoolId,
|
||||
action: 'DELETE',
|
||||
entityType: 'Rubric',
|
||||
entityId: id,
|
||||
metadata: JSON.stringify({ title: existing.title, type: existing.type }),
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
console.error('Rubric DELETE error:', error);
|
||||
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { z } from 'zod';
|
||||
import { db } from '@/lib/db';
|
||||
import { getSession } from '@/lib/auth';
|
||||
|
||||
function isTeacherOrAdmin(role: string | undefined): boolean {
|
||||
return (
|
||||
role === 'TEACHER' ||
|
||||
role === 'SCHOOL_ADMIN' ||
|
||||
role === 'SUPER_ADMIN'
|
||||
);
|
||||
}
|
||||
|
||||
const levelSchema = z.object({
|
||||
id: z.string().optional(), // for updates
|
||||
label: z.string().min(1).max(100),
|
||||
description: z.string().min(1).max(2000),
|
||||
points: z.int().min(0),
|
||||
order: z.int().min(0).default(0),
|
||||
});
|
||||
|
||||
const criterionSchema = z.object({
|
||||
id: z.string().optional(), // for updates
|
||||
name: z.string().min(1).max(200),
|
||||
description: z.string().max(1000).optional().nullable(),
|
||||
weight: z.number().min(0).default(1.0),
|
||||
maxPoints: z.int().min(1),
|
||||
order: z.int().min(0).default(0),
|
||||
levels: z.array(levelSchema).min(1),
|
||||
});
|
||||
|
||||
const createRubricSchema = z.object({
|
||||
schoolId: z.string().min(1),
|
||||
title: z.string().min(1).max(200),
|
||||
description: z.string().max(2000).optional().nullable(),
|
||||
type: z.enum(['ANALYTIC', 'HOLISTIC']).default('ANALYTIC'),
|
||||
subjectId: z.string().optional().nullable(),
|
||||
maxPoints: z.int().min(1).default(100),
|
||||
isPublic: z.boolean().default(false),
|
||||
criteria: z.array(criterionSchema).min(1),
|
||||
});
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
|
||||
}
|
||||
if (!isTeacherOrAdmin(session.user?.role)) {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const schoolIdParam = searchParams.get('schoolId');
|
||||
const teacherId = searchParams.get('teacherId');
|
||||
const subjectId = searchParams.get('subjectId');
|
||||
|
||||
let schoolId: string | undefined;
|
||||
if (session.user?.role === 'SCHOOL_ADMIN') {
|
||||
schoolId = session.user.schoolId ?? undefined;
|
||||
} else {
|
||||
schoolId = schoolIdParam ?? session.user?.schoolId ?? undefined;
|
||||
}
|
||||
|
||||
if (!schoolId) {
|
||||
return NextResponse.json([]);
|
||||
}
|
||||
|
||||
const where: Record<string, unknown> = {
|
||||
OR: [
|
||||
{ schoolId, teacherId: session.userId },
|
||||
{ schoolId, isPublic: true },
|
||||
],
|
||||
};
|
||||
|
||||
if (teacherId) {
|
||||
where.teacherId = teacherId;
|
||||
}
|
||||
if (subjectId && subjectId !== 'all') {
|
||||
where.subjectId = subjectId;
|
||||
}
|
||||
|
||||
// If teacherId filter is set, override the OR to a simple AND
|
||||
if (teacherId) {
|
||||
const simpleWhere: Record<string, unknown> = { schoolId, teacherId };
|
||||
if (subjectId && subjectId !== 'all') simpleWhere.subjectId = subjectId;
|
||||
|
||||
const rubrics = await db.rubric.findMany({
|
||||
where: simpleWhere,
|
||||
orderBy: { updatedAt: 'desc' },
|
||||
include: {
|
||||
criteria: {
|
||||
orderBy: { order: 'asc' },
|
||||
include: { levels: { orderBy: { order: 'asc' } } },
|
||||
},
|
||||
teacher: { select: { id: true, firstName: true, lastName: true } },
|
||||
subject: { select: { id: true, name: true } },
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(rubrics);
|
||||
}
|
||||
|
||||
const rubrics = await db.rubric.findMany({
|
||||
where,
|
||||
orderBy: { updatedAt: 'desc' },
|
||||
include: {
|
||||
criteria: {
|
||||
orderBy: { order: 'asc' },
|
||||
include: { levels: { orderBy: { order: 'asc' } } },
|
||||
},
|
||||
teacher: { select: { id: true, firstName: true, lastName: true } },
|
||||
subject: { select: { id: true, name: true } },
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(rubrics);
|
||||
} catch (error) {
|
||||
console.error('Rubrics 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 (!isTeacherOrAdmin(session.user?.role)) {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const parsed = createRubricSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Validation failed', details: parsed.error.issues },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const { schoolId, criteria, subjectId, ...rest } = parsed.data;
|
||||
|
||||
// Verify school exists
|
||||
const school = await db.school.findUnique({ where: { id: schoolId } });
|
||||
if (!school) {
|
||||
return NextResponse.json({ error: 'School not found' }, { status: 404 });
|
||||
}
|
||||
if (
|
||||
session.user?.role === 'SCHOOL_ADMIN' &&
|
||||
session.user.schoolId &&
|
||||
school.id !== session.user.schoolId
|
||||
) {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
}
|
||||
|
||||
// Verify subject if provided
|
||||
if (subjectId) {
|
||||
const subject = await db.subject.findUnique({ where: { id: subjectId } });
|
||||
if (!subject) {
|
||||
return NextResponse.json({ error: 'Subject not found' }, { status: 404 });
|
||||
}
|
||||
}
|
||||
|
||||
const rubric = await db.rubric.create({
|
||||
data: {
|
||||
schoolId,
|
||||
teacherId: session.userId,
|
||||
subjectId: subjectId ?? null,
|
||||
...rest,
|
||||
criteria: {
|
||||
create: criteria.map((c, ci) => ({
|
||||
name: c.name,
|
||||
description: c.description ?? null,
|
||||
weight: c.weight,
|
||||
maxPoints: c.maxPoints,
|
||||
order: c.order ?? ci,
|
||||
levels: {
|
||||
create: c.levels.map((l, li) => ({
|
||||
label: l.label,
|
||||
description: l.description,
|
||||
points: l.points,
|
||||
order: l.order ?? li,
|
||||
})),
|
||||
},
|
||||
})),
|
||||
},
|
||||
},
|
||||
include: {
|
||||
criteria: {
|
||||
orderBy: { order: 'asc' },
|
||||
include: { levels: { orderBy: { order: 'asc' } } },
|
||||
},
|
||||
teacher: { select: { id: true, firstName: true, lastName: true } },
|
||||
subject: { select: { id: true, name: true } },
|
||||
},
|
||||
});
|
||||
|
||||
await db.auditLog.create({
|
||||
data: {
|
||||
userId: session.userId,
|
||||
schoolId,
|
||||
action: 'CREATE',
|
||||
entityType: 'Rubric',
|
||||
entityId: rubric.id,
|
||||
metadata: JSON.stringify({ title: rubric.title, type: rubric.type, criteriaCount: criteria.length }),
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(rubric, { status: 201 });
|
||||
} catch (error) {
|
||||
console.error('Rubrics POST error:', error);
|
||||
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user