Merge remote-tracking branch 'origin/feat/user-routes' into feat/user-routes

# Conflicts:
#	backend/src/controllers/students.ts
#	backend/src/services/students.ts
This commit is contained in:
Gabriellvl 2025-03-24 15:27:16 +01:00
commit d2cf5b95a9
11 changed files with 37 additions and 40 deletions

View file

@ -3,7 +3,7 @@ import {
getGroupRepository,
getQuestionRepository,
getStudentRepository,
getSubmissionRepository
getSubmissionRepository,
} from '../data/repositories.js';
import { AssignmentDTO } from '../interfaces/assignment.js';
import { ClassDTO, mapToClassDTO } from '../interfaces/class.js';
@ -11,7 +11,7 @@ import { GroupDTO, mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js
import { mapToStudent, mapToStudentDTO, StudentDTO } from '../interfaces/student.js';
import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js';
import { getAllAssignments } from './assignments.js';
import {mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId} from "../interfaces/question";
import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question';
export async function getAllStudents(full: boolean): Promise<StudentDTO[] | string[]> {
const studentRepository = getStudentRepository();

View file

@ -14,8 +14,9 @@ export async function getAllTeachers(full: boolean): Promise<TeacherDTO[]> {
const teacherRepository = getTeacherRepository();
const users = await teacherRepository.findAll();
if (full)
if (full) {
return users.map(mapToTeacherDTO);
}
return users.map((user) => user.username);
}
@ -73,17 +74,19 @@ async function fetchClassesByTeacher(username: string): Promise<ClassDTO[]> {
export async function getClassesByTeacher(username: string, full: boolean): Promise<ClassDTO[] | string[]> {
const classes = await fetchClassesByTeacher(username);
if (full)
if (full) {
return classes;
}
return classes.map((cls) => cls.id);
}
export async function getStudentsByTeacher(username: string, full: boolean) {
const classes = await getClassesByTeacher(username, false);
const students = (await Promise.all(classes.map(async (id) => getClassStudents(id)))).flat();
if (full)
return students
const students = (await Promise.all(classes.map(async (id) => getClassStudents(id)))).flat();
if (full) {
return students;
}
return students.map((student) => student.username);
}
@ -102,9 +105,9 @@ export async function getTeacherQuestions(username: string, full: boolean): Prom
const questionRepository = getQuestionRepository();
const questions = await questionRepository.findAllByLearningObjects(learningObjects);
if (full)
if (full) {
return questions.map(mapToQuestionDTO);
}
return questions.map(mapToQuestionId);
}