feat: verbinding student submissions
This commit is contained in:
		
							parent
							
								
									788ca54742
								
							
						
					
					
						commit
						d8b97f3aea
					
				
					 4 changed files with 42 additions and 5 deletions
				
			
		|  | @ -3,6 +3,7 @@ import { | ||||||
|     getStudentAssignments, |     getStudentAssignments, | ||||||
|     getStudentClasses, |     getStudentClasses, | ||||||
|     getStudentGroups, |     getStudentGroups, | ||||||
|  |     getStudentSubmissions, | ||||||
|     StudentService, |     StudentService, | ||||||
| } from '../services/students.js'; | } from '../services/students.js'; | ||||||
| import { ClassDTO } from '../interfaces/class.js'; | import { ClassDTO } from '../interfaces/class.js'; | ||||||
|  | @ -101,3 +102,16 @@ export async function getStudentGroupsHandler( | ||||||
|         groups: groups, |         groups: groups, | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | export async function getStudentSubmissionsHandler( | ||||||
|  |     req: Request, | ||||||
|  |     res: Response, | ||||||
|  | ): Promise<void> { | ||||||
|  |     const username = req.params.id; | ||||||
|  | 
 | ||||||
|  |     const submissions = await getStudentSubmissions(username); | ||||||
|  | 
 | ||||||
|  |     res.json({ | ||||||
|  |         submissions: submissions, | ||||||
|  |     }); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -55,6 +55,14 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> { | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public findAllSubmissionsForStudent( | ||||||
|  |         student: Student, | ||||||
|  |     ): Promise<Submission[]> { | ||||||
|  |         return this.find( | ||||||
|  |             { submitter: student }, | ||||||
|  |         ); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public deleteSubmissionByLearningObjectAndSubmissionNumber( |     public deleteSubmissionByLearningObjectAndSubmissionNumber( | ||||||
|         loId: LearningObjectIdentifier, |         loId: LearningObjectIdentifier, | ||||||
|         submissionNumber: number |         submissionNumber: number | ||||||
|  |  | ||||||
|  | @ -7,6 +7,7 @@ import { | ||||||
|     getStudentClassesHandler, |     getStudentClassesHandler, | ||||||
|     getStudentGroupsHandler, |     getStudentGroupsHandler, | ||||||
|     getStudentHandler, |     getStudentHandler, | ||||||
|  |     getStudentSubmissionsHandler, | ||||||
| } from '../controllers/students.js'; | } from '../controllers/students.js'; | ||||||
| import { getStudentGroups } from '../services/students.js'; | import { getStudentGroups } from '../services/students.js'; | ||||||
| const router = express.Router(); | const router = express.Router(); | ||||||
|  | @ -25,11 +26,7 @@ router.get('/:username', getStudentHandler); | ||||||
| router.get('/:id/classes', getStudentClassesHandler); | router.get('/:id/classes', getStudentClassesHandler); | ||||||
| 
 | 
 | ||||||
| // The list of submissions a student has made
 | // The list of submissions a student has made
 | ||||||
| router.get('/:id/submissions', (req, res) => { | router.get('/:id/submissions', getStudentSubmissionsHandler); | ||||||
|     res.json({ |  | ||||||
|         submissions: ['0'], |  | ||||||
|     }); |  | ||||||
| }); |  | ||||||
| 
 | 
 | ||||||
| // The list of assignments a student has
 | // The list of assignments a student has
 | ||||||
| router.get('/:id/assignments', getStudentAssignmentsHandler); | router.get('/:id/assignments', getStudentAssignmentsHandler); | ||||||
|  |  | ||||||
|  | @ -2,12 +2,14 @@ import { | ||||||
|     getClassRepository, |     getClassRepository, | ||||||
|     getGroupRepository, |     getGroupRepository, | ||||||
|     getStudentRepository, |     getStudentRepository, | ||||||
|  |     getSubmissionRepository, | ||||||
| } from '../data/repositories.js'; | } from '../data/repositories.js'; | ||||||
| import { Class } from '../entities/classes/class.entity.js'; | import { Class } from '../entities/classes/class.entity.js'; | ||||||
| import { Student } from '../entities/users/student.entity.js'; | import { Student } from '../entities/users/student.entity.js'; | ||||||
| import { AssignmentDTO } from '../interfaces/assignment.js'; | import { AssignmentDTO } from '../interfaces/assignment.js'; | ||||||
| import { ClassDTO, mapToClassDTO } from '../interfaces/class.js'; | import { ClassDTO, mapToClassDTO } from '../interfaces/class.js'; | ||||||
| import { GroupDTO, mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js'; | import { GroupDTO, mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js'; | ||||||
|  | import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js'; | ||||||
| import { getAllAssignments } from './assignments.js'; | import { getAllAssignments } from './assignments.js'; | ||||||
| import { UserService } from './users.js'; | import { UserService } from './users.js'; | ||||||
| 
 | 
 | ||||||
|  | @ -74,3 +76,19 @@ export async function getStudentGroups(username: string, full: boolean): Promise | ||||||
| 
 | 
 | ||||||
|     return groups.map(mapToGroupDTOId); |     return groups.map(mapToGroupDTOId); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | export async function getStudentSubmissions( | ||||||
|  |     username: string | ||||||
|  | ): Promise<SubmissionDTO[]> { | ||||||
|  |     const studentRepository = getStudentRepository(); | ||||||
|  |     const student = await studentRepository.findByUsername(username); | ||||||
|  | 
 | ||||||
|  |     if (!student) { | ||||||
|  |         return []; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     const submissionRepository = getSubmissionRepository(); | ||||||
|  |     const submissions = await submissionRepository.findAllSubmissionsForStudent(student); | ||||||
|  | 
 | ||||||
|  |     return submissions.map(mapToSubmissionDTO); | ||||||
|  | } | ||||||
		Reference in a new issue
	
	 Adriaan Jacquet
						Adriaan Jacquet