From 6c3dbc99bb1afb79fa867505e52656c49bada1b6 Mon Sep 17 00:00:00 2001 From: Gabriellvl Date: Sun, 6 Apr 2025 17:18:13 +0200 Subject: [PATCH] refactor: joinrequests uit classdto --- backend/src/interfaces/class.ts | 1 - backend/src/services/classes.ts | 5 +++++ backend/src/services/teachers.ts | 4 ++-- common/src/interfaces/class.ts | 1 - 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/backend/src/interfaces/class.ts b/backend/src/interfaces/class.ts index 7b07fcf2..76fa5fd5 100644 --- a/backend/src/interfaces/class.ts +++ b/backend/src/interfaces/class.ts @@ -10,7 +10,6 @@ export function mapToClassDTO(cls: Class): ClassDTO { displayName: cls.displayName, teachers: cls.teachers.map((teacher) => teacher.username), students: cls.students.map((student) => student.username), - joinRequests: [], // TODO }; } diff --git a/backend/src/services/classes.ts b/backend/src/services/classes.ts index d4e4defa..826c0f16 100644 --- a/backend/src/services/classes.ts +++ b/backend/src/services/classes.ts @@ -67,6 +67,11 @@ export async function getClassStudents(classId: string, full: boolean): Promise< return cls.students.map((student) => student.username); } +export async function getClassStudentsDTO(classId: string): Promise { + const cls = await fetchClass(classId); + return cls.students.map(mapToStudentDTO); +} + export async function getClassTeachers(classId: string, full: boolean): Promise { const cls = await fetchClass(classId); diff --git a/backend/src/services/teachers.ts b/backend/src/services/teachers.ts index 1b7643fb..6449f16f 100644 --- a/backend/src/services/teachers.ts +++ b/backend/src/services/teachers.ts @@ -22,7 +22,7 @@ import { Question } from '../entities/questions/question.entity.js'; import { ClassJoinRequestRepository } from '../data/classes/class-join-request-repository.js'; import { Student } from '../entities/users/student.entity.js'; import { NotFoundException } from '../exceptions/not-found-exception.js'; -import { getClassStudents } from './classes.js'; +import {getClassStudents, getClassStudentsDTO} from './classes.js'; import { TeacherDTO } from '@dwengo-1/common/interfaces/teacher'; import { ClassDTO } from '@dwengo-1/common/interfaces/class'; import { StudentDTO } from '@dwengo-1/common/interfaces/student'; @@ -99,7 +99,7 @@ export async function getStudentsByTeacher(username: string, full: boolean): Pro const classIds: string[] = classes.map((cls) => cls.id); - const students: StudentDTO[] = (await Promise.all(classIds.map(async (id) => getClassStudents(id)))).flat(); + const students: StudentDTO[] = (await Promise.all(classIds.map(async (id) => await getClassStudentsDTO(id)))).flat(); if (full) { return students; } diff --git a/common/src/interfaces/class.ts b/common/src/interfaces/class.ts index c35c2dfc..d71e15e6 100644 --- a/common/src/interfaces/class.ts +++ b/common/src/interfaces/class.ts @@ -3,5 +3,4 @@ export interface ClassDTO { displayName: string; teachers: string[]; students: string[]; - joinRequests: string[]; }