feat: question route als subroute van learning objects
This commit is contained in:
parent
3e2c73320b
commit
3dd1edc95d
6 changed files with 310 additions and 49 deletions
38
backend/src/interfaces/answer.ts
Normal file
38
backend/src/interfaces/answer.ts
Normal 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
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue