feat(backend): Question- en AnswerRepository aangemaakt.

Ook functie toegevoegd om submissies te verwijderen.
This commit is contained in:
Gerald Schmittinger 2025-02-26 00:39:39 +01:00
parent 2837618fd5
commit 71843dad65
5 changed files with 73 additions and 2 deletions

View file

@ -0,0 +1,26 @@
import {DwengoEntityRepository} from "../dwengo-entity-repository";
import {Answer} from "../../entities/questions/answer.entity";
import {Question} from "../../entities/questions/question.entity";
import {Teacher} from "../../entities/users/teacher.entity";
export class AnswerRepository extends DwengoEntityRepository<Answer> {
public createAnswer(answer: {toQuestion: Question, author: Teacher, content: string}): Promise<Answer> {
let answerEntity = new Answer();
answerEntity.toQuestion = answer.toQuestion;
answerEntity.author = answer.author;
answerEntity.content = answer.content;
return this.insert(answerEntity);
}
public findAllAnswersToQuestion(question: Question): Promise<Answer[]> {
return this.findAll({
where: { toQuestion: question },
orderBy: { sequenceNumber: "ASC" }
});
}
public removeAnswerByQuestionAndSequenceNumber(question: Question, sequenceNumber: number): Promise<void> {
return this.deleteWhere({
toQuestion: question,
sequenceNumber: sequenceNumber
});
}
}

View file

@ -0,0 +1,36 @@
import {DwengoEntityRepository} from "../dwengo-entity-repository";
import {Question} from "../../entities/questions/question.entity";
import {LearningObjectIdentifier} from "../../entities/content/learning-object-identifier";
import {Student} from "../../entities/users/student.entity";
export class QuestionRepository extends DwengoEntityRepository<Question> {
public createQuestion(question: {loId: LearningObjectIdentifier, author: Student, content: string}): Promise<Question> {
let questionEntity = new Question();
questionEntity.learningObjectHruid = question.loId.hruid;
questionEntity.learningObjectLanguage = question.loId.language;
questionEntity.learningObjectVersion = question.loId.version;
questionEntity.author = question.author;
questionEntity.content = question.content;
return this.insert(questionEntity);
}
public findAllQuestionsAboutLearningObject(loId: LearningObjectIdentifier): Promise<Question[]> {
return this.findAll({
where: {
learningObjectHruid: loId.hruid,
learningObjectLanguage: loId.language,
learningObjectVersion: loId.version
},
orderBy: {
sequenceNumber: "ASC"
}
});
}
public removeQuestionByLearningObjectAndSequenceNumber(loId: LearningObjectIdentifier, sequenceNumber: number): Promise<void> {
return this.deleteWhere({
learningObjectHruid: loId.hruid,
learningObjectLanguage: loId.language,
learningObjectVersion: loId.version,
sequenceNumber: sequenceNumber
})
}
}