
# Conflicts: # backend/src/controllers/classes.ts # backend/src/controllers/students.ts # backend/src/data/users/teacher-repository.ts # backend/src/interfaces/assignment.ts # backend/src/interfaces/teacher.ts # backend/src/routes/classes.ts # backend/src/services/assignments.ts # backend/src/services/class.ts # backend/src/services/students.ts # backend/src/util/translation-helper.ts
72 lines
2 KiB
TypeScript
72 lines
2 KiB
TypeScript
import { Request, Response } from 'express';
|
|
import { getAllClasses, getClass, getClassStudents, getClassStudentsIds, getClassTeacherInvitations } from '../services/class.js';
|
|
import { ClassDTO } from '../interfaces/classes.js';
|
|
|
|
export async function getAllClassesHandler(
|
|
req: Request,
|
|
res: Response,
|
|
): Promise<void> {
|
|
const full = req.query.full === "true";
|
|
const classes = await getAllClasses(full);
|
|
|
|
res.json({
|
|
classes: classes
|
|
});
|
|
}
|
|
|
|
export async function getClassHandler(
|
|
req: Request,
|
|
res: Response,
|
|
): Promise<void> {
|
|
try {
|
|
const classId = req.params.id;
|
|
const cls = await getClass(classId);
|
|
|
|
if (!cls) {
|
|
res.status(404).json({ error: "Student not found" });
|
|
return;
|
|
} else {
|
|
cls.endpoints = {
|
|
self: `${req.baseUrl}/${req.params.id}`,
|
|
invitations: `${req.baseUrl}/${req.params.id}/invitations`,
|
|
assignments: `${req.baseUrl}/${req.params.id}/assignments`,
|
|
students: `${req.baseUrl}/${req.params.id}/students`,
|
|
}
|
|
|
|
res.json(cls);
|
|
}
|
|
} catch (error) {
|
|
console.error('Error fetching learning objects:', error);
|
|
res.status(500).json({ error: 'Internal server error' });
|
|
}
|
|
}
|
|
|
|
export async function getClassStudentsHandler(
|
|
req: Request,
|
|
res: Response,
|
|
): Promise<void> {
|
|
const classId = req.params.id;
|
|
const full = req.query.full === "true";
|
|
|
|
let students = full
|
|
? await getClassStudents(classId)
|
|
: await getClassStudentsIds(classId);
|
|
|
|
res.json({
|
|
students: students,
|
|
});
|
|
}
|
|
|
|
export async function getTeacherInvitationsHandler(
|
|
req: Request,
|
|
res: Response,
|
|
): Promise<void> {
|
|
const classId = req.params.id;
|
|
const full = req.query.full === "true"; // TODO: not implemented yet
|
|
|
|
const invitations = await getClassTeacherInvitations(classId, full);
|
|
|
|
res.json({
|
|
invitations: invitations,
|
|
});
|
|
}
|