fix: questionId map in teacher

This commit is contained in:
Gabriellvl 2025-04-01 17:56:33 +02:00
parent 38f423cb33
commit e99df80ba0
3 changed files with 22 additions and 12 deletions

View file

@ -10,15 +10,19 @@ export interface QuestionDTO {
content: string;
}
/**
* Convert a Question entity to a DTO format.
*/
export function mapToQuestionDTO(question: Question): QuestionDTO {
const learningObjectIdentifier = {
function getLearningObjectIdentifier(question: Question): LearningObjectIdentifier {
return {
hruid: question.learningObjectHruid,
language: question.learningObjectLanguage,
version: question.learningObjectVersion,
};
}
/**
* Convert a Question entity to a DTO format.
*/
export function mapToQuestionDTO(question: Question): QuestionDTO {
const learningObjectIdentifier = getLearningObjectIdentifier(question);
return {
learningObjectIdentifier,
@ -34,9 +38,11 @@ export interface QuestionId {
sequenceNumber: number;
}
export function mapToQuestionId(question: QuestionDTO): QuestionId {
export function mapToQuestionDTOId(question: Question): QuestionId {
const learningObjectIdentifier = getLearningObjectIdentifier(question);
return {
learningObjectIdentifier: question.learningObjectIdentifier,
learningObjectIdentifier,
sequenceNumber: question.sequenceNumber!,
};
}

View file

@ -6,7 +6,12 @@ import {
getTeacherRepository,
} from '../data/repositories.js';
import { ClassDTO, mapToClassDTO } from '../interfaces/class.js';
import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js';
import {
mapToQuestionDTO,
mapToQuestionDTOId,
QuestionDTO,
QuestionId
} from '../interfaces/question.js';
import { mapToTeacher, mapToTeacherDTO, TeacherDTO } from '../interfaces/teacher.js';
import { Teacher } from '../entities/users/teacher.entity.js';
import { fetchStudent } from './students.js';
@ -115,13 +120,12 @@ export async function getTeacherQuestions(username: string, full: boolean): Prom
// Fetch all questions related to these learning objects
const questionRepository: QuestionRepository = getQuestionRepository();
const questions: Question[] = await questionRepository.findAllByLearningObjects(learningObjects);
const questionsDTO: QuestionDTO[] = questions.map(mapToQuestionDTO);
if (full) {
return questionsDTO;
return questions.map(mapToQuestionDTO);
}
return questionsDTO.map(mapToQuestionId);
return questions.map(mapToQuestionDTOId);
}
export async function getJoinRequestsByClass(classId: string): Promise<StudentRequestDTO[]> {

View file

@ -189,7 +189,7 @@ describe('Student controllers', () => {
expect(result.requests.length).toBeGreaterThan(0);
});
it('Get join request by student', async () => {
it('Get join request by student and class', async () => {
req = {
params: { username: 'PinkFloyd', classId: 'id02' },
};