fix: integratie user + errors gefixt zodat het runt + format
This commit is contained in:
parent
6c4ea0eefb
commit
1b096b411b
55 changed files with 858 additions and 594 deletions
|
@ -1,7 +1,7 @@
|
|||
import { Request, Response } from 'express'
|
||||
import { Request, Response } from 'express';
|
||||
import { getAllAssignments, getAssignment } from '../services/assignments.js';
|
||||
|
||||
// typescript is annoy with with parameter forwarding from class.ts
|
||||
// Typescript is annoy with with parameter forwarding from class.ts
|
||||
interface AssignmentParams {
|
||||
classid: string;
|
||||
id: string;
|
||||
|
@ -9,7 +9,7 @@ interface AssignmentParams {
|
|||
|
||||
export async function getAllAssignmentsHandler(
|
||||
req: Request<AssignmentParams>,
|
||||
res: Response,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
const classid = req.params.classid;
|
||||
const full = req.query.full === 'true';
|
||||
|
@ -23,20 +23,20 @@ export async function getAllAssignmentsHandler(
|
|||
|
||||
export async function getAssignmentHandler(
|
||||
req: Request<AssignmentParams>,
|
||||
res: Response,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
const id = +req.params.id;
|
||||
const classid = req.params.classid;
|
||||
|
||||
if (isNaN(id)) {
|
||||
res.status(400).json({ error: "Assignment id must be a number" });
|
||||
res.status(400).json({ error: 'Assignment id must be a number' });
|
||||
return;
|
||||
}
|
||||
|
||||
const assignment = await getAssignment(classid, id);
|
||||
|
||||
if (!assignment) {
|
||||
res.status(404).json({ error: "Assignment not found" });
|
||||
res.status(404).json({ error: 'Assignment not found' });
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,40 +1,44 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { getAllClasses, getClass, getClassStudents, getClassStudentsIds, getClassTeacherInvitations } from '../services/class.js';
|
||||
import { ClassDTO } from '../interfaces/classes.js';
|
||||
import {
|
||||
getAllClasses,
|
||||
getClass,
|
||||
getClassStudents,
|
||||
getClassStudentsIds,
|
||||
getClassTeacherInvitations,
|
||||
} from '../services/class.js';
|
||||
|
||||
export async function getAllClassesHandler(
|
||||
req: Request,
|
||||
res: Response,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
const full = req.query.full === "true";
|
||||
const full = req.query.full === 'true';
|
||||
const classes = await getAllClasses(full);
|
||||
|
||||
res.json({
|
||||
classes: classes
|
||||
classes: classes,
|
||||
});
|
||||
}
|
||||
|
||||
export async function getClassHandler(
|
||||
req: Request,
|
||||
res: Response,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
try {
|
||||
const classId = req.params.id;
|
||||
const cls = await getClass(classId);
|
||||
|
||||
if (!cls) {
|
||||
res.status(404).json({ error: "Student not found" });
|
||||
res.status(404).json({ error: 'Student not found' });
|
||||
return;
|
||||
} else {
|
||||
cls.endpoints = {
|
||||
self: `${req.baseUrl}/${req.params.id}`,
|
||||
invitations: `${req.baseUrl}/${req.params.id}/invitations`,
|
||||
assignments: `${req.baseUrl}/${req.params.id}/assignments`,
|
||||
students: `${req.baseUrl}/${req.params.id}/students`,
|
||||
}
|
||||
|
||||
res.json(cls);
|
||||
}
|
||||
cls.endpoints = {
|
||||
self: `${req.baseUrl}/${req.params.id}`,
|
||||
invitations: `${req.baseUrl}/${req.params.id}/invitations`,
|
||||
assignments: `${req.baseUrl}/${req.params.id}/assignments`,
|
||||
students: `${req.baseUrl}/${req.params.id}/students`,
|
||||
};
|
||||
|
||||
res.json(cls);
|
||||
} catch (error) {
|
||||
console.error('Error fetching learning objects:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
|
@ -43,12 +47,12 @@ export async function getClassHandler(
|
|||
|
||||
export async function getClassStudentsHandler(
|
||||
req: Request,
|
||||
res: Response,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
const classId = req.params.id;
|
||||
const full = req.query.full === "true";
|
||||
const full = req.query.full === 'true';
|
||||
|
||||
let students = full
|
||||
const students = full
|
||||
? await getClassStudents(classId)
|
||||
: await getClassStudentsIds(classId);
|
||||
|
||||
|
@ -59,10 +63,10 @@ export async function getClassStudentsHandler(
|
|||
|
||||
export async function getTeacherInvitationsHandler(
|
||||
req: Request,
|
||||
res: Response,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
const classId = req.params.id;
|
||||
const full = req.query.full === "true"; // TODO: not implemented yet
|
||||
const full = req.query.full === 'true'; // TODO: not implemented yet
|
||||
|
||||
const invitations = await getClassTeacherInvitations(classId, full);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { getAllGroups, getGroup } from '../services/groups.js';
|
||||
|
||||
// typescript is annoywith with parameter forwarding from class.ts
|
||||
// Typescript is annoywith with parameter forwarding from class.ts
|
||||
interface GroupParams {
|
||||
classid: string;
|
||||
assignmentid: string;
|
||||
|
@ -10,21 +10,21 @@ interface GroupParams {
|
|||
|
||||
export async function getGroupHandler(
|
||||
req: Request<GroupParams>,
|
||||
res: Response,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
const classId = req.params.classid;
|
||||
const full = req.query.full === "true";
|
||||
const full = req.query.full === 'true';
|
||||
const assignmentId = +req.params.assignmentid;
|
||||
|
||||
if (isNaN(assignmentId)) {
|
||||
res.status(400).json({ error: "Assignment id must be a number" });
|
||||
res.status(400).json({ error: 'Assignment id must be a number' });
|
||||
return;
|
||||
}
|
||||
|
||||
const groupId = +req.params.groupid!; // can't be undefined
|
||||
const groupId = +req.params.groupid!; // Can't be undefined
|
||||
|
||||
if (isNaN(groupId)) {
|
||||
res.status(400).json({ error: "Group id must be a number" });
|
||||
res.status(400).json({ error: 'Group id must be a number' });
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -35,15 +35,15 @@ export async function getGroupHandler(
|
|||
|
||||
export async function getAllGroupsHandler(
|
||||
req: Request,
|
||||
res: Response,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
const classId = req.params.classid;
|
||||
const full = req.query.full === "true";
|
||||
const full = req.query.full === 'true';
|
||||
|
||||
const assignmentId = +req.params.assignmentid;
|
||||
|
||||
if (isNaN(assignmentId)) {
|
||||
res.status(400).json({ error: "Assignment id must be a number" });
|
||||
res.status(400).json({ error: 'Assignment id must be a number' });
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import {
|
|||
getLearningObjectsFromPath,
|
||||
} from '../services/learning-objects.js';
|
||||
import { FALLBACK_LANG } from '../config.js';
|
||||
import { FilteredLearningObject } from '../interfaces/learning-path';
|
||||
import { FilteredLearningObject } from '../interfaces/learning-path.js';
|
||||
|
||||
export async function getAllLearningObjects(
|
||||
req: Request,
|
||||
|
|
|
@ -2,43 +2,62 @@ import { Request, Response } from 'express';
|
|||
import {
|
||||
getStudentClasses,
|
||||
getStudentClassIds,
|
||||
StudentService
|
||||
StudentService,
|
||||
} from '../services/students.js';
|
||||
import { ClassDTO } from '../interfaces/classes.js';
|
||||
import { ClassDTO } from '../interfaces/class.js';
|
||||
import { getAllAssignments } from '../services/assignments.js';
|
||||
import {createUserHandler, deleteUserHandler, getAllUsersHandler, getUserHandler} from "./users.js";
|
||||
import { Student } from "../entities/users/student.entity.js";
|
||||
import {
|
||||
createUserHandler,
|
||||
deleteUserHandler,
|
||||
getAllUsersHandler,
|
||||
getUserHandler,
|
||||
} from './users.js';
|
||||
import { Student } from '../entities/users/student.entity.js';
|
||||
|
||||
// TODO: accept arguments (full, ...)
|
||||
// TODO: endpoints
|
||||
export async function getAllStudentsHandler (req: Request, res: Response): Promise<void> {
|
||||
export async function getAllStudentsHandler(
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
await getAllUsersHandler<Student>(req, res, new StudentService());
|
||||
}
|
||||
|
||||
export async function getStudentHandler(req: Request, res: Response): Promise<void> {
|
||||
export async function getStudentHandler(
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
await getUserHandler<Student>(req, res, new StudentService());
|
||||
}
|
||||
|
||||
export async function createStudentHandler(req: Request, res: Response): Promise<void> {
|
||||
export async function createStudentHandler(
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
await createUserHandler<Student>(req, res, new StudentService(), Student);
|
||||
}
|
||||
|
||||
export async function deleteStudentHandler(req: Request, res: Response): Promise<void> {
|
||||
export async function deleteStudentHandler(
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
await deleteUserHandler<Student>(req, res, new StudentService());
|
||||
}
|
||||
|
||||
|
||||
export async function getStudentClassesHandler (
|
||||
export async function getStudentClassesHandler(
|
||||
req: Request,
|
||||
res: Response,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
try {
|
||||
const full = req.query.full === 'true';
|
||||
const username = req.params.id;
|
||||
|
||||
let classes: ClassDTO[] | string[];
|
||||
if (full) classes = await getStudentClasses(username);
|
||||
else classes = await getStudentClassIds(username);
|
||||
if (full) {
|
||||
classes = await getStudentClasses(username);
|
||||
} else {
|
||||
classes = await getStudentClassIds(username);
|
||||
}
|
||||
|
||||
res.json({
|
||||
classes: classes,
|
||||
|
@ -47,7 +66,7 @@ export async function getStudentClassesHandler (
|
|||
classes: `${req.baseUrl}/${req.params.id}/invitations`,
|
||||
questions: `${req.baseUrl}/${req.params.id}/assignments`,
|
||||
students: `${req.baseUrl}/${req.params.id}/students`,
|
||||
}
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching learning objects:', error);
|
||||
|
@ -57,22 +76,26 @@ export async function getStudentClassesHandler (
|
|||
|
||||
// TODO
|
||||
// Might not be fully correct depending on if
|
||||
// a class has an assignment, that all students
|
||||
// have this assignment.
|
||||
// A class has an assignment, that all students
|
||||
// Have this assignment.
|
||||
export async function getStudentAssignmentsHandler(
|
||||
req: Request,
|
||||
res: Response,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
const full = req.query.full === 'true';
|
||||
const username = req.params.id;
|
||||
|
||||
const classes = await getStudentClasses(username);
|
||||
|
||||
const assignments = (await Promise.all(classes.map(async cls => await getAllAssignments(cls.id, full)))).flat();
|
||||
const assignments = (
|
||||
await Promise.all(
|
||||
classes.map(async (cls) => {
|
||||
return await getAllAssignments(cls.id, full);
|
||||
})
|
||||
)
|
||||
).flat();
|
||||
|
||||
res.json({
|
||||
assignments: assignments
|
||||
assignments: assignments,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,92 +1,53 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { TeacherUserService, TeacherService } from '../services/teachers.js';
|
||||
import { ClassDTO } from '../interfaces/class.js';
|
||||
import { StudentDTO } from '../interfaces/student.js';
|
||||
import { QuestionDTO, QuestionId } from '../interfaces/question.js';
|
||||
import {
|
||||
createTeacher,
|
||||
deleteTeacher,
|
||||
getTeacherByUsername,
|
||||
getClassesByTeacher,
|
||||
getClassIdsByTeacher,
|
||||
getAllTeachers,
|
||||
getAllTeachersIds, getStudentsByTeacher, getStudentIdsByTeacher, getQuestionsByTeacher, getQuestionIdsByTeacher
|
||||
} from '../services/teachers.js';
|
||||
import {TeacherDTO} from "../interfaces/teacher";
|
||||
import {ClassDTO} from "../interfaces/class";
|
||||
import {StudentDTO} from "../interfaces/student";
|
||||
import {QuestionDTO, QuestionId} from "../interfaces/question";
|
||||
createUserHandler,
|
||||
deleteUserHandler,
|
||||
getAllUsersHandler,
|
||||
getUserHandler,
|
||||
} from './users.js';
|
||||
import { Teacher } from '../entities/users/teacher.entity.js';
|
||||
|
||||
export async function getTeacherHandler(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const full = req.query.full === 'true';
|
||||
const username = req.query.username as string;
|
||||
export async function getAllTeachersHandler(
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
await getAllUsersHandler<Teacher>(req, res, new TeacherUserService());
|
||||
}
|
||||
|
||||
if (username){
|
||||
const teacher = await getTeacherByUsername(username);
|
||||
if (!teacher){
|
||||
res.status(404).json({ error: `Teacher with username '${username}' not found.` });
|
||||
return;
|
||||
}
|
||||
res.json(teacher);
|
||||
return;
|
||||
}
|
||||
|
||||
let teachers: TeacherDTO[] | string[];
|
||||
|
||||
if (full) teachers = await getAllTeachers();
|
||||
else teachers = await getAllTeachersIds();
|
||||
|
||||
res.json(teachers);
|
||||
} catch (error) {
|
||||
console.error("❌ Error fetching teachers:", error);
|
||||
res.status(500).json({ error: "Internal server error" });
|
||||
}
|
||||
export async function getTeacherHandler(
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
await getUserHandler<Teacher>(req, res, new TeacherUserService());
|
||||
}
|
||||
|
||||
export async function createTeacherHandler(
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
try {
|
||||
const teacherData = req.body as TeacherDTO;
|
||||
|
||||
if (!teacherData.username || !teacherData.firstName || !teacherData.lastName) {
|
||||
res.status(400).json({ error: 'Missing required fields: username, firstName, lastName' });
|
||||
return;
|
||||
}
|
||||
|
||||
const newTeacher = await createTeacher(teacherData);
|
||||
res.status(201).json(newTeacher);
|
||||
} catch (error) {
|
||||
console.error('Error creating teacher:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
await createUserHandler<Teacher>(
|
||||
req,
|
||||
res,
|
||||
new TeacherUserService(),
|
||||
Teacher
|
||||
);
|
||||
}
|
||||
|
||||
export async function deleteTeacherHandler(
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
try {
|
||||
const username = req.params.username as string;
|
||||
|
||||
if (!username) {
|
||||
res.status(400).json({ error: 'Missing required field: username' });
|
||||
return;
|
||||
}
|
||||
|
||||
const deletedTeacher = await deleteTeacher(username);
|
||||
|
||||
if (!deletedTeacher) {
|
||||
res.status(400).json({ error: `Did not find teacher with username ${username}` });
|
||||
return;
|
||||
}
|
||||
|
||||
res.status(201).json(deletedTeacher);
|
||||
} catch (error) {
|
||||
console.error('Error deleting teacher:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
await deleteUserHandler<Teacher>(req, res, new TeacherUserService());
|
||||
}
|
||||
|
||||
export async function getTeacherClassHandler(req: Request, res: Response): Promise<void> {
|
||||
export async function getTeacherClassHandler(
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
try {
|
||||
const username = req.params.username as string;
|
||||
const full = req.query.full === 'true';
|
||||
|
@ -96,10 +57,11 @@ export async function getTeacherClassHandler(req: Request, res: Response): Promi
|
|||
return;
|
||||
}
|
||||
|
||||
let classes: ClassDTO[] | string[];
|
||||
const teacherService = new TeacherService();
|
||||
|
||||
if (full) classes = await getClassesByTeacher(username);
|
||||
else classes = await getClassIdsByTeacher(username);
|
||||
const classes: ClassDTO[] | string[] = full
|
||||
? await teacherService.getClassesByTeacher(username)
|
||||
: await teacherService.getClassIdsByTeacher(username);
|
||||
|
||||
res.status(201).json(classes);
|
||||
} catch (error) {
|
||||
|
@ -108,7 +70,10 @@ export async function getTeacherClassHandler(req: Request, res: Response): Promi
|
|||
}
|
||||
}
|
||||
|
||||
export async function getTeacherStudentHandler(req: Request, res: Response): Promise<void> {
|
||||
export async function getTeacherStudentHandler(
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
try {
|
||||
const username = req.params.username as string;
|
||||
const full = req.query.full === 'true';
|
||||
|
@ -118,10 +83,11 @@ export async function getTeacherStudentHandler(req: Request, res: Response): Pro
|
|||
return;
|
||||
}
|
||||
|
||||
let students: StudentDTO[] | string[];
|
||||
const teacherService = new TeacherService();
|
||||
|
||||
if (full) students = await getStudentsByTeacher(username);
|
||||
else students = await getStudentIdsByTeacher(username);
|
||||
const students: StudentDTO[] | string[] = full
|
||||
? await teacherService.getStudentsByTeacher(username)
|
||||
: await teacherService.getStudentIdsByTeacher(username);
|
||||
|
||||
res.status(201).json(students);
|
||||
} catch (error) {
|
||||
|
@ -130,7 +96,10 @@ export async function getTeacherStudentHandler(req: Request, res: Response): Pro
|
|||
}
|
||||
}
|
||||
|
||||
export async function getTeacherQuestionHandler(req: Request, res: Response): Promise<void> {
|
||||
export async function getTeacherQuestionHandler(
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
try {
|
||||
const username = req.params.username as string;
|
||||
const full = req.query.full === 'true';
|
||||
|
@ -140,10 +109,11 @@ export async function getTeacherQuestionHandler(req: Request, res: Response): Pr
|
|||
return;
|
||||
}
|
||||
|
||||
let questions: QuestionDTO[] | QuestionId[];
|
||||
const teacherService = new TeacherService();
|
||||
|
||||
if (full) questions = await getQuestionsByTeacher(username);
|
||||
else questions = await getQuestionIdsByTeacher(username);
|
||||
const questions: QuestionDTO[] | QuestionId[] = full
|
||||
? await teacherService.getQuestionsByTeacher(username)
|
||||
: await teacherService.getQuestionIdsByTeacher(username);
|
||||
|
||||
res.status(201).json(questions);
|
||||
} catch (error) {
|
||||
|
@ -151,5 +121,3 @@ export async function getTeacherQuestionHandler(req: Request, res: Response): Pr
|
|||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { themes } from '../data/themes.js';
|
||||
import { loadTranslations } from "../util/translation-helper.js";
|
||||
import { FALLBACK_LANG } from '../config.js';
|
||||
import { loadTranslations } from '../util/translation-helper.js';
|
||||
|
||||
interface Translations {
|
||||
curricula_page: {
|
||||
|
|
|
@ -1,30 +1,29 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { UserService } from "../services/users.js";
|
||||
import {UserDTO} from "../interfaces/user.js";
|
||||
import {User} from "../entities/users/user.entity.js";
|
||||
import { UserService } from '../services/users.js';
|
||||
import { UserDTO } from '../interfaces/user.js';
|
||||
import { User } from '../entities/users/user.entity.js';
|
||||
|
||||
export async function getAllUsersHandler<T extends User>(
|
||||
req: Request,
|
||||
res: Response,
|
||||
service: UserService<T>
|
||||
): Promise<void> {
|
||||
): Promise<void> {
|
||||
try {
|
||||
const full = req.query.full === 'true';
|
||||
|
||||
let users: UserDTO[] | string[] = full
|
||||
const users: UserDTO[] | string[] = full
|
||||
? await service.getAllUsers()
|
||||
: await service.getAllUserIds();
|
||||
|
||||
if (!users){
|
||||
if (!users) {
|
||||
res.status(404).json({ error: `Users not found.` });
|
||||
return;
|
||||
}
|
||||
|
||||
res.status(201).json(users);
|
||||
|
||||
} catch (error) {
|
||||
console.error("❌ Error fetching users:", error);
|
||||
res.status(500).json({ error: "Internal server error" });
|
||||
console.error('❌ Error fetching users:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +31,7 @@ export async function getUserHandler<T extends User>(
|
|||
req: Request,
|
||||
res: Response,
|
||||
service: UserService<T>
|
||||
): Promise<void> {
|
||||
): Promise<void> {
|
||||
try {
|
||||
const username = req.params.username as string;
|
||||
|
||||
|
@ -43,16 +42,17 @@ export async function getUserHandler<T extends User>(
|
|||
|
||||
const user = await service.getUserByUsername(username);
|
||||
|
||||
if (!user){
|
||||
res.status(404).json({ error: `User with username '${username}' not found.` });
|
||||
if (!user) {
|
||||
res.status(404).json({
|
||||
error: `User with username '${username}' not found.`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
res.status(201).json(user);
|
||||
|
||||
} catch (error) {
|
||||
console.error("❌ Error fetching users:", error);
|
||||
res.status(500).json({ error: "Internal server error" });
|
||||
console.error('❌ Error fetching users:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,23 +63,25 @@ export async function createUserHandler<T extends User>(
|
|||
UserClass: new () => T
|
||||
) {
|
||||
try {
|
||||
console.log("req", req)
|
||||
console.log('req', req);
|
||||
const userData = req.body as UserDTO;
|
||||
|
||||
if (!userData.username || !userData.firstName || !userData.lastName) {
|
||||
res.status(400).json({ error: "Missing required fields: username, firstName, lastName" });
|
||||
res.status(400).json({
|
||||
error: 'Missing required fields: username, firstName, lastName',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const newUser = await service.createUser(userData, UserClass);
|
||||
res.status(201).json(newUser);
|
||||
} catch (error) {
|
||||
console.error("❌ Error creating user:", error);
|
||||
res.status(500).json({ error: "Internal server error" });
|
||||
console.error('❌ Error creating user:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteUserHandler<T extends User> (
|
||||
export async function deleteUserHandler<T extends User>(
|
||||
req: Request,
|
||||
res: Response,
|
||||
service: UserService<T>
|
||||
|
@ -88,19 +90,21 @@ export async function deleteUserHandler<T extends User> (
|
|||
const username = req.params.username;
|
||||
|
||||
if (!username) {
|
||||
res.status(400).json({ error: "Missing required field: username" });
|
||||
res.status(400).json({ error: 'Missing required field: username' });
|
||||
return;
|
||||
}
|
||||
|
||||
const deletedUser = await service.deleteUser(username);
|
||||
if (!deletedUser) {
|
||||
res.status(404).json({ error: `User with username '${username}' not found.` });
|
||||
res.status(404).json({
|
||||
error: `User with username '${username}' not found.`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
res.status(200).json(deletedUser);
|
||||
} catch (error) {
|
||||
console.error("❌ Error deleting user:", error);
|
||||
res.status(500).json({ error: "Internal server error" });
|
||||
console.error('❌ Error deleting user:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue