feat: POST method voor class geimplementeerd

This commit is contained in:
Adriaan Jacquet 2025-03-13 15:11:29 +01:00
parent a1aaf342d7
commit 79422ab854
8 changed files with 85 additions and 8 deletions

View file

@ -1,4 +1,7 @@
import { Collection } from '@mikro-orm/core';
import { Class } from '../entities/classes/class.entity.js';
import { Student } from '../entities/users/student.entity.js';
import { Teacher } from '../entities/users/teacher.entity.js';
export interface ClassDTO {
id: string;
@ -16,7 +19,7 @@ export interface ClassDTO {
export function mapToClassDTO(cls: Class): ClassDTO {
return {
id: cls.classId,
id: cls.classId!,
displayName: cls.displayName,
teachers: cls.teachers.map((teacher) => {
return teacher.username;
@ -27,3 +30,16 @@ export function mapToClassDTO(cls: Class): ClassDTO {
joinRequests: [], // TODO
};
}
export function mapToClass(
classData: ClassDTO,
students: Collection<Student>,
teachers: Collection<Teacher>
): Class {
const cls = new Class();
cls.displayName = classData.displayName;
cls.students = students;
cls.teachers = teachers;
return cls;
}