2025SELab2-project-Dwengo/backend/src/interfaces/class.ts
2025-03-13 17:45:28 +00:00

41 lines
1.1 KiB
TypeScript

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;
displayName: string;
teachers: string[];
students: string[];
joinRequests: string[];
endpoints?: {
self: string;
invitations: string;
assignments: string;
students: string;
};
}
export function mapToClassDTO(cls: Class): ClassDTO {
return {
id: cls.classId!,
displayName: cls.displayName,
teachers: cls.teachers.map((teacher) => teacher.username),
students: cls.students.map((student) => student.username),
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;
}