feat: student send join req

This commit is contained in:
Gabriellvl 2025-03-29 12:21:48 +01:00
parent 70d4c80093
commit 3093a6c131
12 changed files with 347 additions and 169 deletions

View file

@ -1,10 +1,18 @@
import { Request, Response } from 'express';
import { createTeacher, deleteTeacher, getAllTeachers, getClassesByTeacher, getStudentsByTeacher, getTeacher } from '../services/teachers.js';
import {
createTeacher,
deleteTeacher,
getAllTeachers,
getClassesByTeacher,
getStudentsByTeacher,
getTeacher,
getTeacherQuestions
} from '../services/teachers.js';
import { ClassDTO } from '../interfaces/class.js';
import { StudentDTO } from '../interfaces/student.js';
import { QuestionDTO, QuestionId } from '../interfaces/question.js';
import { TeacherDTO } from '../interfaces/teacher.js';
import { MISSING_FIELDS_ERROR, MISSING_USERNAME_ERROR, NAME_NOT_FOUND_ERROR } from './users';
import {requireFields} from "./error-helper";
export async function getAllTeachersHandler(req: Request, res: Response): Promise<void> {
const full = req.query.full === 'true';
@ -21,18 +29,11 @@ export async function getAllTeachersHandler(req: Request, res: Response): Promis
export async function getTeacherHandler(req: Request, res: Response): Promise<void> {
const username = req.params.username;
if (!username) {
res.status(400).json(MISSING_USERNAME_ERROR);
return;
}
requireFields({ username });
const user = await getTeacher(username);
if (!user) {
res.status(404).json(NAME_NOT_FOUND_ERROR(username));
return;
}
res.status(201).json(user);
}
@ -41,7 +42,6 @@ export async function createTeacherHandler(req: Request, res: Response) {
const userData = req.body as TeacherDTO;
if (!userData.username || !userData.firstName || !userData.lastName) {
res.status(400).json(MISSING_FIELDS_ERROR);
return;
}
@ -53,13 +53,11 @@ export async function deleteTeacherHandler(req: Request, res: Response) {
const username = req.params.username;
if (!username) {
res.status(400).json(MISSING_USERNAME_ERROR);
return;
}
const deletedUser = await deleteTeacher(username);
if (!deletedUser) {
res.status(404).json(NAME_NOT_FOUND_ERROR(username));
return;
}
@ -71,7 +69,6 @@ export async function getTeacherClassHandler(req: Request, res: Response): Promi
const full = req.query.full === 'true';
if (!username) {
res.status(400).json(MISSING_USERNAME_ERROR);
return;
}
@ -85,7 +82,6 @@ export async function getTeacherStudentHandler(req: Request, res: Response): Pro
const full = req.query.full === 'true';
if (!username) {
res.status(400).json(MISSING_USERNAME_ERROR);
return;
}
@ -99,11 +95,10 @@ export async function getTeacherQuestionHandler(req: Request, res: Response): Pr
const full = req.query.full === 'true';
if (!username) {
res.status(400).json(MISSING_USERNAME_ERROR);
return;
}
const questions: QuestionDTO[] | QuestionId[] = await getQuestionsByTeacher(username, full);
const questions: QuestionDTO[] | QuestionId[] = await getTeacherQuestions(username, full);
res.json({ questions });
}