2025SELab2-project-Dwengo/backend/src/interfaces/question.ts
2025-04-02 19:48:42 +02:00

36 lines
1.2 KiB
TypeScript

import { Question } from '../entities/questions/question.entity.js';
import { mapToStudentDTO } from './student.js';
import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question';
import { LearningObjectIdentifier } from '@dwengo-1/common/interfaces/learning-content';
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,
sequenceNumber: question.sequenceNumber!,
author: mapToStudentDTO(question.author),
timestamp: question.timestamp.toISOString(),
content: question.content,
};
}
export function mapToQuestionDTOId(question: Question): QuestionId {
const learningObjectIdentifier = getLearningObjectIdentifier(question);
return {
learningObjectIdentifier,
sequenceNumber: question.sequenceNumber!,
};
}