feat: endpoints voor /, /:id en /:id/students in routes/class.ts zijn geimplementeerd

This commit is contained in:
Adriaan Jacquet 2025-03-05 16:31:27 +01:00
parent 123fdf0fa1
commit 241fe0103f
7 changed files with 95 additions and 34 deletions

View file

@ -1,26 +1,26 @@
import { getClassRepository, getStudentRepository } from "../data/repositories";
import { Class } from "../entities/classes/class.entity";
import { Student } from "../entities/users/student.entity";
import { ClassDTO, mapToClassDTO } from "../interfaces/classes";
import { StudentDTO } from "../interfaces/students";
import { StudentDTO, mapToStudentDTO } from "../interfaces/students";
export async function getAllStudents(): Promise<StudentDTO[]> {
// TODO
return [];
const studentRepository = getStudentRepository();
const students = await studentRepository.find({});
return students.map(mapToStudentDTO);
}
export async function getStudent(username: string): Promise<StudentDTO | null> {
const studentRepository = getStudentRepository();
const student = await studentRepository.findByUsername(username);
if (!student) return null;
else {
return {
id: student.username,
username: student.username,
firstName: student.firstName,
lastName: student.lastName,
}
if (!student) {
return null;
}
return mapToStudentDTO(student);
}
async function fetchStudentClasses(username: string): Promise<Class[]> {