feat: delete op class geimplementeerd
This commit is contained in:
parent
6290d3dd9b
commit
da5cb7d02d
3 changed files with 17 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { createClass, getAllClasses, getClass, getClassStudents, getClassTeacherInvitations } from '../services/classes.js';
|
||||
import { createClass, deleteClass, getAllClasses, getClass, getClassStudents, getClassTeacherInvitations } from '../services/classes.js';
|
||||
import { ClassDTO } from '../interfaces/class.js';
|
||||
import { NotFoundException } from '../exceptions/not-found-exception.js';
|
||||
|
||||
export async function getAllClassesHandler(req: Request, res: Response): Promise<void> {
|
||||
const full = req.query.full === 'true';
|
||||
|
@ -28,7 +29,7 @@ export async function createClassHandler(req: Request, res: Response): Promise<v
|
|||
return;
|
||||
}
|
||||
|
||||
res.status(201).json(cls);
|
||||
res.status(201).json({ cls });
|
||||
}
|
||||
|
||||
export async function getClassHandler(req: Request, res: Response): Promise<void> {
|
||||
|
@ -40,7 +41,14 @@ export async function getClassHandler(req: Request, res: Response): Promise<void
|
|||
return;
|
||||
}
|
||||
|
||||
res.json(cls);
|
||||
res.json({ cls });
|
||||
}
|
||||
|
||||
export async function deleteClassHandler(req: Request, res: Response): Promise<void> {
|
||||
const classId = req.params.id;
|
||||
const cls = await deleteClass(classId);
|
||||
|
||||
res.json({ cls });
|
||||
}
|
||||
|
||||
export async function getClassStudentsHandler(req: Request, res: Response): Promise<void> {
|
||||
|
|
|
@ -15,9 +15,10 @@ router.get('/', getAllClassesHandler);
|
|||
|
||||
router.post('/', createClassHandler);
|
||||
|
||||
// Information about an class with id 'id'
|
||||
router.get('/:id', getClassHandler);
|
||||
|
||||
router.delete('/:id', deleteClassHandler);
|
||||
|
||||
router.get('/:id/teacher-invitations', getTeacherInvitationsHandler);
|
||||
|
||||
router.get('/:id/students', getClassStudentsHandler);
|
||||
|
|
|
@ -64,6 +64,10 @@ export async function createClass(classData: ClassDTO): Promise<ClassDTO | null>
|
|||
export async function deleteClass(classId: string): Promise<ClassDTO> {
|
||||
const cls = await fetchClass(classId);
|
||||
|
||||
if (!cls) {
|
||||
throw new NotFoundException('Could not delete class because it does not exist');
|
||||
}
|
||||
|
||||
const classRepository = getClassRepository();
|
||||
await classRepository.deleteById(classId);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue