feat(backend): Question- en AnswerRepository aangemaakt.
Ook functie toegevoegd om submissies te verwijderen.
This commit is contained in:
parent
2837618fd5
commit
71843dad65
5 changed files with 73 additions and 2 deletions
26
backend/src/data/questions/answer-repository.ts
Normal file
26
backend/src/data/questions/answer-repository.ts
Normal 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
|
||||
});
|
||||
}
|
||||
}
|
36
backend/src/data/questions/question-repository.ts
Normal file
36
backend/src/data/questions/question-repository.ts
Normal 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
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue