Round 14: Self-Assessment, Learning Goals, Portfolio, Homework, Announcements

This commit is contained in:
Mustafa Cetin committed 2026-07-29 10:53:22 +00:00
1 parent d325984786
commit 50c2d13d90
22 files changed
+5232 -2

No files matched your search

+149
View File
@@ -0,0 +1,149 @@
import { NextResponse } from 'next/server';
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 } = await params;
const assessment = await db.selfAssessment.findFirst({
where: { id, deletedAt: null },
include: {
student: {
select: { id: true, firstName: true, lastName: true },
},
competency: {
select: { id: true, code: true, title: true },
},
classGroup: {
select: { id: true, name: true },
},
goal: {
select: { id: true, title: true, status: true },
},
},
});
if (!assessment) {
return NextResponse.json({ error: 'Not found' }, { status: 404 });
}
if (session.user?.role !== 'SUPER_ADMIN' && session.user?.schoolId !== assessment.schoolId) {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
}
return NextResponse.json(assessment);
} catch (error) {
console.error('SelfAssessment GET [id] 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 });
}
const { id } = await params;
const existing = await db.selfAssessment.findFirst({
where: { id, deletedAt: null },
});
if (!existing) {
return NextResponse.json({ error: 'Not found' }, { status: 404 });
}
if (session.user?.role !== 'SUPER_ADMIN' && session.user?.schoolId !== existing.schoolId) {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
}
const body = await request.json();
const {
selfLevel,
confidence,
reflection,
evidence,
goalId,
classGroupId,
} = body;
const updated = await db.selfAssessment.update({
where: { id },
data: {
...(selfLevel !== undefined && { selfLevel }),
...(confidence !== undefined && { confidence: confidence || null }),
...(reflection !== undefined && { reflection }),
...(evidence !== undefined && { evidence }),
...(goalId !== undefined && { goalId: goalId || null }),
...(classGroupId !== undefined && { classGroupId: classGroupId || null }),
},
include: {
student: {
select: { id: true, firstName: true, lastName: true },
},
competency: {
select: { id: true, code: true, title: true },
},
classGroup: {
select: { id: true, name: true },
},
goal: {
select: { id: true, title: true, status: true },
},
},
});
return NextResponse.json(updated);
} catch (error) {
console.error('SelfAssessment PUT [id] 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 });
}
const { id } = await params;
const existing = await db.selfAssessment.findFirst({
where: { id, deletedAt: null },
});
if (!existing) {
return NextResponse.json({ error: 'Not found' }, { status: 404 });
}
if (session.user?.role !== 'SUPER_ADMIN' && session.user?.schoolId !== existing.schoolId) {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
}
// Soft delete
await db.selfAssessment.update({
where: { id },
data: { deletedAt: new Date() },
});
return NextResponse.json({ success: true });
} catch (error) {
console.error('SelfAssessment DELETE [id] error:', error);
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
}
}
+134
View File
@@ -0,0 +1,134 @@
import { NextResponse } from 'next/server';
import { db } from '@/lib/db';
import { getSession } from '@/lib/auth';
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 studentId = searchParams.get('studentId');
const competencyId = searchParams.get('competencyId');
const classGroupId = searchParams.get('classGroupId');
if (!schoolId) {
return NextResponse.json({ error: 'schoolId is required' }, { status: 400 });
}
if (session.user?.role !== 'SUPER_ADMIN' && session.user?.schoolId !== schoolId) {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
}
const where: Record<string, unknown> = {
schoolId,
deletedAt: null,
};
if (studentId) where.studentId = studentId;
if (competencyId) where.competencyId = competencyId;
if (classGroupId) where.classGroupId = classGroupId;
const assessments = await db.selfAssessment.findMany({
where,
orderBy: { createdAt: 'desc' },
include: {
student: {
select: { id: true, firstName: true, lastName: true },
},
competency: {
select: { id: true, code: true, title: true },
},
classGroup: {
select: { id: true, name: true },
},
goal: {
select: { id: true, title: true, status: true },
},
},
});
return NextResponse.json(assessments);
} catch (error) {
console.error('SelfAssessment 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();
const {
schoolId,
studentId,
competencyId,
classGroupId,
selfLevel,
confidence,
reflection,
evidence,
goalId,
isDemo,
} = body;
if (!schoolId || !studentId || !competencyId || selfLevel === undefined) {
return NextResponse.json(
{ error: 'schoolId, studentId, competencyId, and selfLevel are required' },
{ status: 400 }
);
}
if (selfLevel < 1 || selfLevel > 6) {
return NextResponse.json(
{ error: 'selfLevel must be between 1 and 6' },
{ status: 400 }
);
}
if (session.user?.role !== 'SUPER_ADMIN' && session.user?.schoolId !== schoolId) {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
}
const assessment = await db.selfAssessment.create({
data: {
schoolId,
studentId,
competencyId,
classGroupId: classGroupId || null,
selfLevel,
confidence: confidence || null,
reflection: reflection || null,
evidence: evidence || null,
goalId: goalId || null,
isDemo: isDemo ?? false,
},
include: {
student: {
select: { id: true, firstName: true, lastName: true },
},
competency: {
select: { id: true, code: true, title: true },
},
classGroup: {
select: { id: true, name: true },
},
goal: {
select: { id: true, title: true, status: true },
},
},
});
return NextResponse.json(assessment, { status: 201 });
} catch (error) {
console.error('SelfAssessment POST error:', error);
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
}
}