feat: question route als subroute van learning objects

This commit is contained in:
Gabriellvl 2025-03-13 15:02:11 +01:00
parent 3e2c73320b
commit 3dd1edc95d
6 changed files with 310 additions and 49 deletions

View file

@ -0,0 +1,38 @@
import {mapToUserDTO, UserDTO} from "./user.js";
import {mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId} from "./question.js";
import {Answer} from "../entities/questions/answer.entity.js";
export interface AnswerDTO {
author: UserDTO;
toQuestion: QuestionDTO;
sequenceNumber: number;
timestamp: string;
content: string;
}
/**
* Convert a Question entity to a DTO format.
*/
export function mapToAnswerDTO(answer: Answer): AnswerDTO {
return {
author: mapToUserDTO(answer.author),
toQuestion: mapToQuestionDTO(answer.toQuestion),
sequenceNumber: answer.sequenceNumber,
timestamp: answer.timestamp.toISOString(),
content: answer.content,
};
}
export interface AnswerId {
author: string;
toQuestion: QuestionId;
sequenceNumber: number;
}
export function mapToAnswerId(answer: AnswerDTO): AnswerId {
return {
author: answer.author.username,
toQuestion: mapToQuestionId(answer.toQuestion),
sequenceNumber: answer.sequenceNumber
}
}