feat: werken aan delete voor assignment
This commit is contained in:
		
							parent
							
								
									da5cb7d02d
								
							
						
					
					
						commit
						c79a295e68
					
				
					 3 changed files with 14 additions and 19 deletions
				
			
		|  | @ -2,13 +2,7 @@ import { Request, Response } from 'express'; | ||||||
| import { createAssignment, getAllAssignments, getAssignment, getAssignmentsSubmissions } from '../services/assignments.js'; | import { createAssignment, getAllAssignments, getAssignment, getAssignmentsSubmissions } from '../services/assignments.js'; | ||||||
| import { AssignmentDTO } from '../interfaces/assignment.js'; | import { AssignmentDTO } from '../interfaces/assignment.js'; | ||||||
| 
 | 
 | ||||||
| // Typescript is annoy with with parameter forwarding from class.ts
 | export async function getAllAssignmentsHandler(req: Request, res: Response): Promise<void> { | ||||||
| interface AssignmentParams { |  | ||||||
|     classid: string; |  | ||||||
|     id: string; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export async function getAllAssignmentsHandler(req: Request<AssignmentParams>, res: Response): Promise<void> { |  | ||||||
|     const classid = req.params.classid; |     const classid = req.params.classid; | ||||||
|     const full = req.query.full === 'true'; |     const full = req.query.full === 'true'; | ||||||
| 
 | 
 | ||||||
|  | @ -19,7 +13,7 @@ export async function getAllAssignmentsHandler(req: Request<AssignmentParams>, r | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function createAssignmentHandler(req: Request<AssignmentParams>, res: Response): Promise<void> { | export async function createAssignmentHandler(req: Request, res: Response): Promise<void> { | ||||||
|     const classid = req.params.classid; |     const classid = req.params.classid; | ||||||
|     const assignmentData = req.body as AssignmentDTO; |     const assignmentData = req.body as AssignmentDTO; | ||||||
| 
 | 
 | ||||||
|  | @ -40,7 +34,7 @@ export async function createAssignmentHandler(req: Request<AssignmentParams>, re | ||||||
|     res.status(201).json(assignment); |     res.status(201).json(assignment); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function getAssignmentHandler(req: Request<AssignmentParams>, res: Response): Promise<void> { | export async function getAssignmentHandler(req: Request, res: Response): Promise<void> { | ||||||
|     const id = +req.params.id; |     const id = +req.params.id; | ||||||
|     const classid = req.params.classid; |     const classid = req.params.classid; | ||||||
| 
 | 
 | ||||||
|  | @ -59,7 +53,7 @@ export async function getAssignmentHandler(req: Request<AssignmentParams>, res: | ||||||
|     res.json(assignment); |     res.json(assignment); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function getAssignmentsSubmissionsHandler(req: Request<AssignmentParams>, res: Response): Promise<void> { | export async function getAssignmentsSubmissionsHandler(req: Request, res: Response): Promise<void> { | ||||||
|     const classid = req.params.classid; |     const classid = req.params.classid; | ||||||
|     const assignmentNumber = +req.params.id; |     const assignmentNumber = +req.params.id; | ||||||
|     const full = req.query.full === 'true'; |     const full = req.query.full === 'true'; | ||||||
|  |  | ||||||
|  | @ -1,30 +1,31 @@ | ||||||
| import { getAssignmentRepository, getClassRepository, getGroupRepository, getQuestionRepository, getSubmissionRepository } from '../data/repositories.js'; | import { getAssignmentRepository, getClassRepository, getGroupRepository, getQuestionRepository, getSubmissionRepository } from '../data/repositories.js'; | ||||||
| import { Assignment } from '../entities/assignments/assignment.entity.js'; | import { Assignment } from '../entities/assignments/assignment.entity.js'; | ||||||
|  | import { NotFoundException } from '../exceptions/not-found-exception.js'; | ||||||
| import { AssignmentDTO, mapToAssignment, mapToAssignmentDTO, mapToAssignmentDTOId } from '../interfaces/assignment.js'; | import { AssignmentDTO, mapToAssignment, mapToAssignmentDTO, mapToAssignmentDTOId } from '../interfaces/assignment.js'; | ||||||
| import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js'; | import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js'; | ||||||
| import { mapToSubmissionDTO, mapToSubmissionDTOId, SubmissionDTO, SubmissionDTOId } from '../interfaces/submission.js'; | import { mapToSubmissionDTO, mapToSubmissionDTOId, SubmissionDTO, SubmissionDTOId } from '../interfaces/submission.js'; | ||||||
|  | import { fetchClass } from './classes.js'; | ||||||
| 
 | 
 | ||||||
| export async function fetchAssignment(classid: string, assignmentNumber: number): Promise<Assignment | null> { | export async function fetchAssignment(classid: string, assignmentNumber: number): Promise<Assignment> { | ||||||
|     const classRepository = getClassRepository(); |     const classRepository = getClassRepository(); | ||||||
|     const cls = await classRepository.findById(classid); |     const cls = await classRepository.findById(classid); | ||||||
| 
 | 
 | ||||||
|     if (!cls) { |     if (!cls) { | ||||||
|         return null; |         throw new NotFoundException('Could not find assignment\'s class'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const assignmentRepository = getAssignmentRepository(); |     const assignmentRepository = getAssignmentRepository(); | ||||||
|     const assignment = await assignmentRepository.findByClassAndId(cls, assignmentNumber); |     const assignment = await assignmentRepository.findByClassAndId(cls, assignmentNumber); | ||||||
| 
 | 
 | ||||||
|  |     if (!assignment) { | ||||||
|  |         throw new NotFoundException('Could not find assignment'); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     return assignment; |     return assignment; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function getAllAssignments(classid: string, full: boolean): Promise<AssignmentDTO[]> { | export async function getAllAssignments(classid: string, full: boolean): Promise<AssignmentDTO[]> { | ||||||
|     const classRepository = getClassRepository(); |     const cls = await fetchClass(classid); | ||||||
|     const cls = await classRepository.findById(classid); |  | ||||||
| 
 |  | ||||||
|     if (!cls) { |  | ||||||
|         return []; |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     const assignmentRepository = getAssignmentRepository(); |     const assignmentRepository = getAssignmentRepository(); | ||||||
|     const assignments = await assignmentRepository.findAllAssignmentsInClass(cls); |     const assignments = await assignmentRepository.findAllAssignmentsInClass(cls); | ||||||
|  |  | ||||||
|  | @ -8,7 +8,7 @@ import { getLogger } from '../logging/initalize.js'; | ||||||
| 
 | 
 | ||||||
| const logger = getLogger(); | const logger = getLogger(); | ||||||
| 
 | 
 | ||||||
| async function fetchClass(classid: string): Promise<Class> { | export async function fetchClass(classid: string): Promise<Class> { | ||||||
|     const classRepository = getClassRepository(); |     const classRepository = getClassRepository(); | ||||||
|     const cls = await classRepository.findById(classid); |     const cls = await classRepository.findById(classid); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Adriaan Jacquet
						Adriaan Jacquet