feat: DELETE op assignment geimplementeerd
This commit is contained in:
		
							parent
							
								
									d65bb1f4a6
								
							
						
					
					
						commit
						2ec5e02061
					
				
					 3 changed files with 26 additions and 3 deletions
				
			
		|  | @ -1,5 +1,5 @@ | |||
| import { Request, Response } from 'express'; | ||||
| import { createAssignment, getAllAssignments, getAssignment, getAssignmentsSubmissions } from '../services/assignments.js'; | ||||
| import { createAssignment, deleteAssignment, getAllAssignments, getAssignment, getAssignmentsSubmissions } from '../services/assignments.js'; | ||||
| import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment'; | ||||
| import {requireFields} from "./error-helper"; | ||||
| import {BadRequestException} from "../exceptions/bad-request-exception"; | ||||
|  | @ -42,6 +42,18 @@ export async function getAssignmentHandler(req: Request, res: Response): Promise | |||
|     res.json({ assignment }); | ||||
| } | ||||
| 
 | ||||
| export async function deleteAssignmentHandler(req: Request, res: Response): Promise<void> { | ||||
|     const id = Number(req.params.id); | ||||
|     const classid = req.params.classid; | ||||
|     requireFields({ id, classid }); | ||||
| 
 | ||||
|     if (isNaN(id)) { | ||||
|         throw new BadRequestException("Assignment id should be a number"); | ||||
|     } | ||||
| 
 | ||||
|     const assignment = await deleteAssignment(classid, id);  | ||||
| } | ||||
| 
 | ||||
| export async function getAssignmentsSubmissionsHandler(req: Request, res: Response): Promise<void> { | ||||
|     const classid = req.params.classid; | ||||
|     const assignmentNumber = Number(req.params.id); | ||||
|  |  | |||
|  | @ -1,6 +1,7 @@ | |||
| import express from 'express'; | ||||
| import { | ||||
|     createAssignmentHandler, | ||||
|     deleteAssignmentHandler, | ||||
|     getAllAssignmentsHandler, | ||||
|     getAssignmentHandler, | ||||
|     getAssignmentsSubmissionsHandler, | ||||
|  | @ -9,14 +10,14 @@ import groupRouter from './groups.js'; | |||
| 
 | ||||
| const router = express.Router({ mergeParams: true }); | ||||
| 
 | ||||
| // Root endpoint used to search objects
 | ||||
| router.get('/', getAllAssignmentsHandler); | ||||
| 
 | ||||
| router.post('/', createAssignmentHandler); | ||||
| 
 | ||||
| // Information about an assignment with id 'id'
 | ||||
| router.get('/:id', getAssignmentHandler); | ||||
| 
 | ||||
| router.delete('/:id', deleteAssignmentHandler); | ||||
| 
 | ||||
| router.get('/:id/submissions', getAssignmentsSubmissionsHandler); | ||||
| 
 | ||||
| router.get('/:id/questions', (_req, res) => { | ||||
|  |  | |||
|  | @ -57,6 +57,16 @@ export async function getAssignment(classid: string, id: number): Promise<Assign | |||
|     return mapToAssignmentDTO(assignment); | ||||
| } | ||||
| 
 | ||||
| export async function deleteAssignment(classid: string, id: number): Promise<AssignmentDTO> { | ||||
|     const assignment = await fetchAssignment(classid, id); | ||||
|     const cls = await fetchClass(classid); | ||||
| 
 | ||||
|     const assignmentRepository = getAssignmentRepository(); | ||||
|     await assignmentRepository.deleteByClassAndId(cls, id); | ||||
| 
 | ||||
|     return mapToAssignmentDTO(assignment); | ||||
| } | ||||
| 
 | ||||
| export async function getAssignmentsSubmissions( | ||||
|     classid: string, | ||||
|     assignmentNumber: number, | ||||
|  |  | |||
		Reference in a new issue
	
	 Adriaan Jacquet
						Adriaan Jacquet