fix: juiste responsecodes en messages toegevoegd

This commit is contained in:
Adriaan Jacquet 2025-03-23 19:49:41 +01:00
parent 59e8f2fcf2
commit 1664642940
9 changed files with 61 additions and 17 deletions

View file

@ -28,6 +28,11 @@ export async function getGroupHandler(req: Request<GroupParams>, res: Response):
const group = await getGroup(classId, assignmentId, groupId, full);
if (!group) {
res.status(404).json({ error: 'Group not found' });
return;
}
res.json(group);
}

View file

@ -76,10 +76,10 @@ export async function getQuestionAnswersHandler(req: Request, res: Response): Pr
return;
}
const answers = getAnswersByQuestion(questionId, full);
const answers = await getAnswersByQuestion(questionId, full);
if (!answers) {
res.status(404).json({ error: `Questions not found.` });
res.status(404).json({ error: `Questions not found` });
} else {
res.json({ answers: answers });
}
@ -96,7 +96,7 @@ export async function createQuestionHandler(req: Request, res: Response): Promis
const question = await createQuestion(questionDTO);
if (!question) {
res.status(400).json({ error: 'Could not add question' });
res.status(400).json({ error: 'Could not create question' });
} else {
res.json(question);
}

View file

@ -58,6 +58,14 @@ export async function createStudentHandler(req: Request, res: Response) {
}
const newUser = await createStudent(userData);
if (!newUser) {
res.status(500).json({
error: 'Something went wrong while creating student'
});
return;
}
res.status(201).json(newUser);
}

View file

@ -94,6 +94,11 @@ export async function getTeacherClassHandler(req: Request, res: Response): Promi
const classes = await getClassesByTeacher(username, full);
if (!classes) {
res.status(404).json({ error: 'Teacher not found' });
return;
}
res.json({ classes: classes });
}
@ -108,6 +113,11 @@ export async function getTeacherStudentHandler(req: Request, res: Response): Pro
const students = await getStudentsByTeacher(username, full);
if (!students) {
res.status(404).json({ error: 'Teacher not found' });
return;
}
res.json({ students: students });
}
@ -122,5 +132,10 @@ export async function getTeacherQuestionHandler(req: Request, res: Response): Pr
const questions = await getQuestionsByTeacher(username, full);
if (!questions) {
res.status(404).json({ error: 'Teacher not found' });
return;
}
res.json({ questions: questions });
}