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, | ||||
|     getStudentClasses, | ||||
|     getStudentGroups, | ||||
|     getStudentSubmissions, | ||||
|     StudentService, | ||||
| } from '../services/students.js'; | ||||
| import { ClassDTO } from '../interfaces/class.js'; | ||||
|  | @ -101,3 +102,16 @@ export async function getStudentGroupsHandler( | |||
|         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( | ||||
|         loId: LearningObjectIdentifier, | ||||
|         submissionNumber: number | ||||
|  |  | |||
|  | @ -7,6 +7,7 @@ import { | |||
|     getStudentClassesHandler, | ||||
|     getStudentGroupsHandler, | ||||
|     getStudentHandler, | ||||
|     getStudentSubmissionsHandler, | ||||
| } from '../controllers/students.js'; | ||||
| import { getStudentGroups } from '../services/students.js'; | ||||
| const router = express.Router(); | ||||
|  | @ -25,11 +26,7 @@ router.get('/:username', getStudentHandler); | |||
| router.get('/:id/classes', getStudentClassesHandler); | ||||
| 
 | ||||
| // The list of submissions a student has made
 | ||||
| router.get('/:id/submissions', (req, res) => { | ||||
|     res.json({ | ||||
|         submissions: ['0'], | ||||
|     }); | ||||
| }); | ||||
| router.get('/:id/submissions', getStudentSubmissionsHandler); | ||||
| 
 | ||||
| // The list of assignments a student has
 | ||||
| router.get('/:id/assignments', getStudentAssignmentsHandler); | ||||
|  |  | |||
|  | @ -2,12 +2,14 @@ import { | |||
|     getClassRepository, | ||||
|     getGroupRepository, | ||||
|     getStudentRepository, | ||||
|     getSubmissionRepository, | ||||
| } from '../data/repositories.js'; | ||||
| import { Class } from '../entities/classes/class.entity.js'; | ||||
| import { Student } from '../entities/users/student.entity.js'; | ||||
| import { AssignmentDTO } from '../interfaces/assignment.js'; | ||||
| import { ClassDTO, mapToClassDTO } from '../interfaces/class.js'; | ||||
| import { GroupDTO, mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js'; | ||||
| import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js'; | ||||
| import { getAllAssignments } from './assignments.js'; | ||||
| import { UserService } from './users.js'; | ||||
| 
 | ||||
|  | @ -74,3 +76,19 @@ export async function getStudentGroups(username: string, full: boolean): Promise | |||
| 
 | ||||
|     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