Round 23: Report Card Generator, Seating Chart, School Library, Parent Portal Enhancement

- Report Card Generator: Professional report cards with PDF export
  - Subject grades table with competency levels
  - Competency radar chart, teacher comments
  - Template management, batch generation
  - Status workflow: draft → review → published → archived

- Seating Chart View: Visual classroom layout
  - Grid-based classroom with desk positions
  - Multiple layout templates (rows, groups, U-shape, circle)
  - Click-to-assign student placement
  - Randomize and smart arrange features
  - Student info popover

- School Library View: Book lending system
  - Book catalog with search and filter
  - Checkout system with due dates and renewals
  - Overdue tracking with notifications
  - Reservation queue system
  - Statistics dashboard with charts

- Enhanced Parent Portal: Comprehensive dashboard
  - Child overview with multiple children selector
  - Academic progress with competency radar chart
  - Attendance & illness with approval
  - Communication, schedule, and reports tabs

- Bug fixes: i18n breadcrumb keys for new views
- Styling: Gradient headers, animations, hover effects across all new views
- 200+ i18n keys added, 15+ API routes, 3+ Prisma models
This commit is contained in:
Mustafa Cetin committed 2026-07-29 23:42:26 +00:00
1 parent 490bd0650f
commit 6e5af13778
28 files changed
+10252 -494

No files matched your search

+199
View File
@@ -0,0 +1,199 @@
import { NextResponse } from 'next/server';
import { z } from 'zod';
import { db } from '@/lib/db';
import { getSession } from '@/lib/auth';
const createReportCardSchema = z.object({
studentId: z.string().min(1),
classGroupId: z.string().min(1),
schoolYearId: z.string().min(1),
period: z.string().min(1),
includesGrades: z.boolean().default(false),
teacherComments: z.string().optional(),
attendanceSummary: z.string().optional(),
overallAssessment: z.string().optional(),
templateId: z.string().optional(),
sections: z
.array(
z.object({
competencyCategoryId: z.string().optional(),
generatedText: z.string().min(1),
order: z.number().int().default(0),
})
)
.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 studentId = searchParams.get('studentId');
const classGroupId = searchParams.get('classGroupId');
const schoolYearId = searchParams.get('schoolYearId');
const status = searchParams.get('status');
const period = searchParams.get('period');
const templateId = searchParams.get('templateId');
const where: Record<string, unknown> = {};
if (studentId) where.studentId = studentId;
if (classGroupId) where.classGroupId = classGroupId;
if (schoolYearId) where.schoolYearId = schoolYearId;
if (status) where.status = status;
if (period) where.period = period;
if (templateId) where.templateId = templateId;
// Role-based filtering
if (session.user?.role === 'STUDENT') {
// Students can only see their own published reports
const student = await db.student.findFirst({
where: { userId: session.userId },
});
if (student) {
where.studentId = student.id;
where.status = 'PUBLISHED';
} else {
return NextResponse.json([]);
}
} else if (session.user?.role === 'PARENT') {
// Parents can only see their children's published reports
const parentLinks = await db.parentStudentLink.findMany({
where: { parentId: session.userId },
});
const childIds = parentLinks.map((l) => l.studentId);
where.studentId = { in: childIds };
where.status = 'PUBLISHED';
} else if (session.user?.role === 'TEACHER') {
// Teachers see reports for their classes
if (!classGroupId) {
const teacherClasses = await db.classGroupTeacher.findMany({
where: { userId: session.userId },
});
const classIds = teacherClasses.map((c) => c.classGroupId);
where.classGroupId = { in: classIds };
}
}
const reports = await db.report.findMany({
where,
orderBy: { generatedAt: 'desc' },
include: {
student: { select: { id: true, firstName: true, lastName: true, avatarUrl: true } },
classGroup: { select: { id: true, name: true, gradeLevel: true } },
schoolYear: { select: { id: true, label: true } },
generatedByUser: { select: { id: true, firstName: true, lastName: true } },
sections: {
orderBy: { order: 'asc' },
include: {
competencyCategory: { select: { id: true, name: true, color: true } },
},
},
template: { select: { id: true, name: true, layout: true } },
},
});
return NextResponse.json(reports);
} catch (error) {
console.error('ReportCards 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 !== 'VICE_PRINCIPAL' &&
session.user?.role !== 'TEACHER'
) {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
}
const body = await request.json();
const parsed = createReportCardSchema.safeParse(body);
if (!parsed.success) {
return NextResponse.json(
{ error: 'Validation failed', details: parsed.error.issues },
{ status: 400 }
);
}
const { sections, ...reportData } = parsed.data;
// If attendance summary not provided, try to compute it
let attendanceSummary = reportData.attendanceSummary;
if (!attendanceSummary) {
const attendanceRecords = await db.attendanceRecord.findMany({
where: {
studentId: reportData.studentId,
session: {
classGroupId: reportData.classGroupId,
date: { gte: new Date(new Date().getFullYear(), 0, 1) },
},
},
include: { session: true },
});
const summary = {
present: attendanceRecords.filter((r) => r.status === 'PRESENT').length,
absent: attendanceRecords.filter((r) => r.status === 'ABSENT').length,
excused: attendanceRecords.filter((r) => r.status === 'EXCUSED').length,
late: attendanceRecords.filter((r) => r.status === 'LATE').length,
total: attendanceRecords.length,
};
attendanceSummary = JSON.stringify(summary);
}
const report = await db.report.create({
data: {
studentId: reportData.studentId,
classGroupId: reportData.classGroupId,
schoolYearId: reportData.schoolYearId,
period: reportData.period,
generatedByUserId: session.userId,
includesGrades: reportData.includesGrades,
status: 'DRAFT',
teacherComments: reportData.teacherComments,
attendanceSummary,
overallAssessment: reportData.overallAssessment,
templateId: reportData.templateId,
sections: sections
? {
create: sections.map((s) => ({
competencyCategoryId: s.competencyCategoryId ?? null,
generatedText: s.generatedText,
order: s.order,
})),
}
: undefined,
},
include: {
student: { select: { id: true, firstName: true, lastName: true, avatarUrl: true } },
classGroup: { select: { id: true, name: true } },
schoolYear: { select: { id: true, label: true } },
generatedByUser: { select: { id: true, firstName: true, lastName: true } },
sections: {
orderBy: { order: 'asc' },
include: {
competencyCategory: { select: { id: true, name: true } },
},
},
template: { select: { id: true, name: true, layout: true } },
},
});
return NextResponse.json(report, { status: 201 });
} catch (error) {
console.error('ReportCards POST error:', error);
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
}
}