feat: endpoints voor /, /:id en /:id/students in routes/class.ts zijn geimplementeerd
This commit is contained in:
parent
123fdf0fa1
commit
241fe0103f
7 changed files with 95 additions and 34 deletions
|
@ -1,5 +1,22 @@
|
|||
import { getClassRepository } from "../data/repositories";
|
||||
import { Class } from "../entities/classes/class.entity";
|
||||
import { ClassDTO, mapToClassDTO } from "../interfaces/classes";
|
||||
import { mapToStudentDTO, StudentDTO } from "../interfaces/students";
|
||||
|
||||
export async function getAllClasses(full: boolean): Promise<ClassDTO[] | string[]> {
|
||||
const classRepository = getClassRepository();
|
||||
const classes = await classRepository.find({}, { populate: ["students", "teachers"] });
|
||||
|
||||
if (!classes) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (full) {
|
||||
return classes.map(mapToClassDTO);
|
||||
} else {
|
||||
return classes.map((cls) => cls.classId);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getClass(classId: string): Promise<ClassDTO | null> {
|
||||
const classRepository = getClassRepository();
|
||||
|
@ -9,4 +26,19 @@ export async function getClass(classId: string): Promise<ClassDTO | null> {
|
|||
else {
|
||||
return mapToClassDTO(cls);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getClassStudents(classId: string, full: boolean): Promise<StudentDTO[] | string[]> {
|
||||
const classRepository = getClassRepository();
|
||||
const cls = await classRepository.findById(classId);
|
||||
|
||||
if (!cls) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (full) {
|
||||
return cls.students.map(mapToStudentDTO);
|
||||
} else {
|
||||
return cls.students.map((student) => student.username);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue