feat(backend): Assignment-, Group- en SubmissionRepository aangemaakt
This commit is contained in:
		
							parent
							
								
									bd93e5fae3
								
							
						
					
					
						commit
						2837618fd5
					
				
					 8 changed files with 75 additions and 4 deletions
				
			
		
							
								
								
									
										15
									
								
								backend/src/data/assignments/assignment-repository.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								backend/src/data/assignments/assignment-repository.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,15 @@ | ||||||
|  | import {DwengoEntityRepository} from "../dwengo-entity-repository"; | ||||||
|  | import {Assignment} from "../../entities/assignments/assignment.entity"; | ||||||
|  | import {Class} from "../../entities/classes/class.entity"; | ||||||
|  | 
 | ||||||
|  | export class AssignmentRepository extends DwengoEntityRepository<Assignment> { | ||||||
|  |     public findByClassAndId(within: Class, id: number): Promise<Assignment | null> { | ||||||
|  |         return this.findOne({within: within, id: id}); | ||||||
|  |     } | ||||||
|  |     public findAllAssignmentsInClass(within: Class): Promise<Assignment[]> { | ||||||
|  |         return this.findAll({where: {within: within}}); | ||||||
|  |     } | ||||||
|  |     public deleteByClassAndId(within: Class, id: number): Promise<void> { | ||||||
|  |         return this.deleteWhere({within: within, id: id}); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										15
									
								
								backend/src/data/assignments/group-repository.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								backend/src/data/assignments/group-repository.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,15 @@ | ||||||
|  | import {DwengoEntityRepository} from "../dwengo-entity-repository"; | ||||||
|  | import {Group} from "../../entities/assignments/group.entity"; | ||||||
|  | import {Assignment} from "../../entities/assignments/assignment.entity"; | ||||||
|  | 
 | ||||||
|  | export class GroupRepository extends DwengoEntityRepository<Group> { | ||||||
|  |     public findByAssignmentAndGroupNumber(assignment: Assignment, groupNumber: number): Promise<Group | null> { | ||||||
|  |         return this.findOne({assignment: assignment, groupNumber: groupNumber}); | ||||||
|  |     } | ||||||
|  |     public findAllGroupsForAssignment(assignment: Assignment): Promise<Group[]> { | ||||||
|  |         return this.findAll({where: {assignment: assignment}}); | ||||||
|  |     } | ||||||
|  |     public deleteByAssignmentAndGroupNumber(assignment: Assignment, groupNumber: number) { | ||||||
|  |         return this.deleteWhere({assignment: assignment, groupNumber: groupNumber}); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										34
									
								
								backend/src/data/assignments/submission-repository.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								backend/src/data/assignments/submission-repository.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,34 @@ | ||||||
|  | import {DwengoEntityRepository} from "../dwengo-entity-repository"; | ||||||
|  | import {Group} from "../../entities/assignments/group.entity"; | ||||||
|  | import {Submission} from "../../entities/assignments/submission.entity"; | ||||||
|  | import {LearningObjectIdentifier} from "../../entities/content/learning-object-identifier"; | ||||||
|  | import {Student} from "../../entities/users/student.entity"; | ||||||
|  | 
 | ||||||
|  | export class SubmissionRepository extends DwengoEntityRepository<Submission> { | ||||||
|  |     public findSubmissionByLearningObjectAndSubmissionNumber(loId: LearningObjectIdentifier, submissionNumber: number): Promise<Submission | null> { | ||||||
|  |         return this.findOne({ | ||||||
|  |             learningObjectHruid: loId.hruid, | ||||||
|  |             learningObjectLanguage: loId.language, | ||||||
|  |             learningObjectVersion: loId.version, | ||||||
|  |             submissionNumber: submissionNumber | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public findMostRecentSubmissionForStudent(loId: LearningObjectIdentifier, submitter: Student): Promise<Submission | null> { | ||||||
|  |         return this.findOne({ | ||||||
|  |             learningObjectHruid: loId.hruid, | ||||||
|  |             learningObjectLanguage: loId.language, | ||||||
|  |             learningObjectVersion: loId.version, | ||||||
|  |             submitter: submitter, | ||||||
|  |         }, {orderBy: {submissionNumber: "DESC"}}) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public findMostRecentSubmissionForGroup(loId: LearningObjectIdentifier, group: Group): Promise<Submission | null> { | ||||||
|  |         return this.findOne({ | ||||||
|  |             learningObjectHruid: loId.hruid, | ||||||
|  |             learningObjectLanguage: loId.language, | ||||||
|  |             learningObjectVersion: loId.version, | ||||||
|  |             onBehalfOf: group, | ||||||
|  |         }, {orderBy: {submissionNumber: "DESC"}}) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -4,7 +4,7 @@ import {Entity, Enum, ManyToOne, PrimaryKey, Property} from "@mikro-orm/core"; | ||||||
| import {Language} from "../content/language"; | import {Language} from "../content/language"; | ||||||
| 
 | 
 | ||||||
| @Entity() | @Entity() | ||||||
| export class Submission<T> { | export class Submission { | ||||||
|     @PrimaryKey({type: "string"}) |     @PrimaryKey({type: "string"}) | ||||||
|     learningObjectHruid!: string; |     learningObjectHruid!: string; | ||||||
| 
 | 
 | ||||||
|  | @ -14,7 +14,7 @@ export class Submission<T> { | ||||||
|     @PrimaryKey({type: "string"}) |     @PrimaryKey({type: "string"}) | ||||||
|     learningObjectVersion: string = "1"; |     learningObjectVersion: string = "1"; | ||||||
| 
 | 
 | ||||||
|     @Property({type: "integer"}) |     @PrimaryKey({type: "integer"}) | ||||||
|     submissionNumber!: number; |     submissionNumber!: number; | ||||||
| 
 | 
 | ||||||
|     @ManyToOne({entity: () => Student}) |     @ManyToOne({entity: () => Student}) | ||||||
|  | @ -27,5 +27,5 @@ export class Submission<T> { | ||||||
|     onBehalfOf?: Group; |     onBehalfOf?: Group; | ||||||
| 
 | 
 | ||||||
|     @Property({type: "json"}) |     @Property({type: "json"}) | ||||||
|     content!: T; |     content!: string; | ||||||
| } | } | ||||||
|  | @ -0,0 +1,7 @@ | ||||||
|  | import {Language} from "./language"; | ||||||
|  | 
 | ||||||
|  | export class LearningObjectIdentifier { | ||||||
|  |     constructor(public hruid: string, public language: Language, public version: string) { | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import {User} from "./user.entity"; | import {User} from "./user.entity"; | ||||||
| import {Collection, Entity, ManyToMany} from '@mikro-orm/core'; | import {Collection, Entity, ManyToMany} from '@mikro-orm/core'; | ||||||
| import {Class} from "../classes/class.entity"; | import {Class} from "../classes/class.entity"; | ||||||
| import {Group} from "../assigments/group.entity"; | import {Group} from "../assignments/group.entity"; | ||||||
| import {StudentRepository} from "../../data/users/student-repository"; | import {StudentRepository} from "../../data/users/student-repository"; | ||||||
| 
 | 
 | ||||||
| @Entity({repository: () => StudentRepository}) | @Entity({repository: () => StudentRepository}) | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Gerald Schmittinger
						Gerald Schmittinger