feat: post en delete toegevoegd voor class students en teachers
This commit is contained in:
parent
441b77b8cd
commit
d65bb1f4a6
3 changed files with 94 additions and 0 deletions
|
@ -1,7 +1,11 @@
|
||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import {
|
import {
|
||||||
|
addClassStudent,
|
||||||
|
addClassTeacher,
|
||||||
createClass,
|
createClass,
|
||||||
deleteClass,
|
deleteClass,
|
||||||
|
deleteClassStudent,
|
||||||
|
deleteClassTeacher,
|
||||||
getAllClasses,
|
getAllClasses,
|
||||||
getClass,
|
getClass,
|
||||||
getClassStudents,
|
getClassStudents,
|
||||||
|
@ -73,3 +77,43 @@ export async function getTeacherInvitationsHandler(req: Request, res: Response):
|
||||||
|
|
||||||
res.json({ invitations });
|
res.json({ invitations });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function deleteClassStudentHandler(req: Request, res: Response): Promise<void> {
|
||||||
|
const classId = req.params.id;
|
||||||
|
const username = req.params.username;
|
||||||
|
requireFields({ classId, username });
|
||||||
|
|
||||||
|
const cls = await deleteClassStudent(classId, username);
|
||||||
|
|
||||||
|
res.json({ class: cls });
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteClassTeacherHandler(req: Request, res: Response): Promise<void> {
|
||||||
|
const classId = req.params.id;
|
||||||
|
const username = req.params.username;
|
||||||
|
requireFields({ classId, username });
|
||||||
|
|
||||||
|
const cls = await deleteClassTeacher(classId, username);
|
||||||
|
|
||||||
|
res.json({ class: cls });
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function addClassStudentHandler(req: Request, res: Response): Promise<void> {
|
||||||
|
const classId = req.params.id;
|
||||||
|
const username = req.body.username;
|
||||||
|
requireFields({ classId, username });
|
||||||
|
|
||||||
|
const cls = await addClassStudent(classId, username);
|
||||||
|
|
||||||
|
res.json({ class: cls });
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function addClassTeacherHandler(req: Request, res: Response): Promise<void> {
|
||||||
|
const classId = req.params.id;
|
||||||
|
const username = req.body.username;
|
||||||
|
requireFields({ classId, username });
|
||||||
|
|
||||||
|
const cls = await addClassTeacher(classId, username);
|
||||||
|
|
||||||
|
res.json({ class: cls });
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import {
|
import {
|
||||||
|
addClassStudentHandler,
|
||||||
|
addClassTeacherHandler,
|
||||||
createClassHandler,
|
createClassHandler,
|
||||||
deleteClassHandler,
|
deleteClassHandler,
|
||||||
|
deleteClassStudentHandler,
|
||||||
|
deleteClassTeacherHandler,
|
||||||
getAllClassesHandler,
|
getAllClassesHandler,
|
||||||
getClassHandler,
|
getClassHandler,
|
||||||
getClassStudentsHandler, getClassTeachersHandler,
|
getClassStudentsHandler, getClassTeachersHandler,
|
||||||
|
@ -24,8 +28,16 @@ router.get('/:id/teacher-invitations', getTeacherInvitationsHandler);
|
||||||
|
|
||||||
router.get('/:id/students', getClassStudentsHandler);
|
router.get('/:id/students', getClassStudentsHandler);
|
||||||
|
|
||||||
|
router.post('/:id/students', addClassStudentHandler);
|
||||||
|
|
||||||
|
router.delete('/:id/students/:username', deleteClassStudentHandler);
|
||||||
|
|
||||||
router.get('/:id/teachers', getClassTeachersHandler);
|
router.get('/:id/teachers', getClassTeachersHandler);
|
||||||
|
|
||||||
|
router.post('/:id/teachers', addClassTeacherHandler);
|
||||||
|
|
||||||
|
router.delete('/:id/teachers/:username', deleteClassTeacherHandler);
|
||||||
|
|
||||||
router.use('/:classid/assignments', assignmentRouter);
|
router.use('/:classid/assignments', assignmentRouter);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
|
@ -101,3 +101,41 @@ export async function getClassTeacherInvitations(classId: string, full: boolean)
|
||||||
|
|
||||||
return invitations.map(mapToTeacherInvitationDTOIds);
|
return invitations.map(mapToTeacherInvitationDTOIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function deleteClassStudent(classId: string, username: string): Promise<ClassDTO> {
|
||||||
|
const cls = await fetchClass(classId);
|
||||||
|
|
||||||
|
const classRepository = getClassRepository();
|
||||||
|
classRepository.assign(cls, { students: cls.students.filter((student) => student.username !== username) });
|
||||||
|
|
||||||
|
return mapToClassDTO(cls);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteClassTeacher(classId: string, username: string): Promise<ClassDTO> {
|
||||||
|
const cls = await fetchClass(classId);
|
||||||
|
|
||||||
|
const classRepository = getClassRepository();
|
||||||
|
classRepository.assign(cls, { teachers: cls.teachers.filter((teacher) => teacher.username !== username) });
|
||||||
|
|
||||||
|
return mapToClassDTO(cls);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function addClassStudent(classId: string, username: string): Promise<ClassDTO> {
|
||||||
|
const cls = await fetchClass(classId);
|
||||||
|
const newStudent = await fetchStudent(username);
|
||||||
|
|
||||||
|
const classRepository = getClassRepository();
|
||||||
|
classRepository.assign(cls, { students: [...cls.students, newStudent] });
|
||||||
|
|
||||||
|
return mapToClassDTO(cls);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function addClassTeacher(classId: string, username: string): Promise<ClassDTO> {
|
||||||
|
const cls = await fetchClass(classId);
|
||||||
|
const newTeacher = await fetchTeacher(username);
|
||||||
|
|
||||||
|
const classRepository = getClassRepository();
|
||||||
|
classRepository.assign(cls, { teachers: [...cls.teachers, newTeacher] });
|
||||||
|
|
||||||
|
return mapToClassDTO(cls);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue