fix: questionId map in teacher
This commit is contained in:
parent
38f423cb33
commit
e99df80ba0
3 changed files with 22 additions and 12 deletions
|
@ -10,15 +10,19 @@ export interface QuestionDTO {
|
||||||
content: string;
|
content: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function getLearningObjectIdentifier(question: Question): LearningObjectIdentifier {
|
||||||
* Convert a Question entity to a DTO format.
|
return {
|
||||||
*/
|
|
||||||
export function mapToQuestionDTO(question: Question): QuestionDTO {
|
|
||||||
const learningObjectIdentifier = {
|
|
||||||
hruid: question.learningObjectHruid,
|
hruid: question.learningObjectHruid,
|
||||||
language: question.learningObjectLanguage,
|
language: question.learningObjectLanguage,
|
||||||
version: question.learningObjectVersion,
|
version: question.learningObjectVersion,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a Question entity to a DTO format.
|
||||||
|
*/
|
||||||
|
export function mapToQuestionDTO(question: Question): QuestionDTO {
|
||||||
|
const learningObjectIdentifier = getLearningObjectIdentifier(question);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
learningObjectIdentifier,
|
learningObjectIdentifier,
|
||||||
|
@ -34,9 +38,11 @@ export interface QuestionId {
|
||||||
sequenceNumber: number;
|
sequenceNumber: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mapToQuestionId(question: QuestionDTO): QuestionId {
|
export function mapToQuestionDTOId(question: Question): QuestionId {
|
||||||
|
const learningObjectIdentifier = getLearningObjectIdentifier(question);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
learningObjectIdentifier: question.learningObjectIdentifier,
|
learningObjectIdentifier,
|
||||||
sequenceNumber: question.sequenceNumber!,
|
sequenceNumber: question.sequenceNumber!,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,12 @@ import {
|
||||||
getTeacherRepository,
|
getTeacherRepository,
|
||||||
} from '../data/repositories.js';
|
} from '../data/repositories.js';
|
||||||
import { ClassDTO, mapToClassDTO } from '../interfaces/class.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 { mapToTeacher, mapToTeacherDTO, TeacherDTO } from '../interfaces/teacher.js';
|
||||||
import { Teacher } from '../entities/users/teacher.entity.js';
|
import { Teacher } from '../entities/users/teacher.entity.js';
|
||||||
import { fetchStudent } from './students.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
|
// Fetch all questions related to these learning objects
|
||||||
const questionRepository: QuestionRepository = getQuestionRepository();
|
const questionRepository: QuestionRepository = getQuestionRepository();
|
||||||
const questions: Question[] = await questionRepository.findAllByLearningObjects(learningObjects);
|
const questions: Question[] = await questionRepository.findAllByLearningObjects(learningObjects);
|
||||||
const questionsDTO: QuestionDTO[] = questions.map(mapToQuestionDTO);
|
|
||||||
|
|
||||||
if (full) {
|
if (full) {
|
||||||
return questionsDTO;
|
return questions.map(mapToQuestionDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
return questionsDTO.map(mapToQuestionId);
|
return questions.map(mapToQuestionDTOId);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getJoinRequestsByClass(classId: string): Promise<StudentRequestDTO[]> {
|
export async function getJoinRequestsByClass(classId: string): Promise<StudentRequestDTO[]> {
|
||||||
|
|
|
@ -189,7 +189,7 @@ describe('Student controllers', () => {
|
||||||
expect(result.requests.length).toBeGreaterThan(0);
|
expect(result.requests.length).toBeGreaterThan(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Get join request by student', async () => {
|
it('Get join request by student and class', async () => {
|
||||||
req = {
|
req = {
|
||||||
params: { username: 'PinkFloyd', classId: 'id02' },
|
params: { username: 'PinkFloyd', classId: 'id02' },
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue