feat: POST method voor class geimplementeerd

This commit is contained in:
Adriaan Jacquet 2025-03-13 15:11:29 +01:00
parent a1aaf342d7
commit 79422ab854
8 changed files with 85 additions and 8 deletions

View file

@ -1,11 +1,14 @@
import { Request, Response } from 'express';
import {
createClass,
getAllClasses,
getClass,
getClassStudents,
getClassStudentsIds,
getClassTeacherInvitations,
} from '../services/class.js';
import { ClassDTO, mapToClass } from '../interfaces/class.js';
import { getClassRepository, getStudentRepository, getTeacherRepository } from '../data/repositories.js';
export async function getAllClassesHandler(
req: Request,
@ -19,6 +22,29 @@ export async function getAllClassesHandler(
});
}
export async function createClassHandler(
req: Request,
res: Response,
): Promise<void> {
const classData = req.body as ClassDTO;
if (!classData.displayName) {
res.status(400).json({
error: 'Missing one or more required fields: displayName',
});
return;
}
const cls = await createClass(classData);
if (!cls) {
res.status(500).json({ error: "Something went wrong while creating class" });
return
}
res.status(201).json({ class: cls });
}
export async function getClassHandler(
req: Request,
res: Response