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
				
			
		|  | @ -31,4 +31,13 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> { | |||
|             onBehalfOf: group, | ||||
|         }, {orderBy: {submissionNumber: "DESC"}}) | ||||
|     } | ||||
| 
 | ||||
|     public deleteSubmissionByLearningObjectAndSubmissionNumber(loId: LearningObjectIdentifier, submissionNumber: number): Promise<void> { | ||||
|         return this.deleteWhere({ | ||||
|             learningObjectHruid: loId.hruid, | ||||
|             learningObjectLanguage: loId.language, | ||||
|             learningObjectVersion: loId.version, | ||||
|             submissionNumber: submissionNumber | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  |  | |||
							
								
								
									
										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 | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | @ -15,7 +15,7 @@ export class Answer { | |||
|     sequenceNumber!: number; | ||||
| 
 | ||||
|     @Property({type: "datetime"}) | ||||
|     timestamp!: Date; | ||||
|     timestamp: Date = new Date(); | ||||
| 
 | ||||
|     @Property({type: "text"}) | ||||
|     content!: string; | ||||
|  |  | |||
|  | @ -20,7 +20,7 @@ export class Question { | |||
|     author!: Student; | ||||
| 
 | ||||
|     @Property({type: "datetime"}) | ||||
|     timestamp!: Date; | ||||
|     timestamp: Date = new Date(); | ||||
| 
 | ||||
|     @Property({type: "text"}) | ||||
|     content!: string; | ||||
|  |  | |||
		Reference in a new issue
	
	 Gerald Schmittinger
						Gerald Schmittinger