diff --git a/backend/src/app.ts b/backend/src/app.ts index e4da44e7..8f01dea6 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -16,6 +16,7 @@ import loginRouter from './routes/login.js'; const app: Express = express(); const port: string | number = getNumericEnvVar(EnvVars.Port); +app.use(express.json()); // TODO Replace with Express routes app.get('/', (_, res: Response) => { diff --git a/backend/src/controllers/assignments.ts b/backend/src/controllers/assignments.ts index 78d11336..ab0f951f 100644 --- a/backend/src/controllers/assignments.ts +++ b/backend/src/controllers/assignments.ts @@ -1,5 +1,5 @@ import { Request, Response } from 'express' -import { getAllAssignments, getAssignment } from '../services/assignments'; +import { getAllAssignments, getAssignment } from '../services/assignments.js'; // typescript is annoy with with parameter forwarding from class.ts interface AssignmentParams { @@ -41,4 +41,4 @@ export async function getAssignmentHandler( } res.json(assignment); -} \ No newline at end of file +} diff --git a/backend/src/controllers/classes.ts b/backend/src/controllers/classes.ts index d7580d62..9f8f4669 100644 --- a/backend/src/controllers/classes.ts +++ b/backend/src/controllers/classes.ts @@ -1,6 +1,5 @@ import { Request, Response } from 'express'; -import { getAllClasses, getClass, getClassStudents, getClassTeacherInvitations } from '../services/class'; -import { ClassDTO } from '../interfaces/classes'; +import { getAllClasses, getClass, getClassStudents, getClassTeacherInvitations } from '../services/class.js'; export async function getAllClassesHandler( req: Request, @@ -61,10 +60,10 @@ export async function getTeacherInvitationsHandler( ): Promise { const classId = req.params.id; const full = req.query.full === "true"; // TODO: not implemented yet - + const invitations = await getClassTeacherInvitations(classId, full); res.json({ invitations: invitations, }); -} \ No newline at end of file +} diff --git a/backend/src/controllers/groups.ts b/backend/src/controllers/groups.ts index 1c523744..d301c98d 100644 --- a/backend/src/controllers/groups.ts +++ b/backend/src/controllers/groups.ts @@ -1,5 +1,5 @@ import { Request, Response } from 'express'; -import { getAllGroups, getGroup } from '../services/groups'; +import { getAllGroups, getGroup } from '../services/groups.js'; // typescript is annoywith with parameter forwarding from class.ts interface GroupParams { @@ -52,4 +52,4 @@ export async function getAllGroupsHandler( res.json({ groups: groups, }); -} \ No newline at end of file +} diff --git a/backend/src/controllers/students.ts b/backend/src/controllers/students.ts index 68a5fc76..b4fe7b47 100644 --- a/backend/src/controllers/students.ts +++ b/backend/src/controllers/students.ts @@ -1,53 +1,33 @@ import { Request, Response } from 'express'; -import { getAllStudents, getStudent, getStudentClasses, getStudentClassIds } from '../services/students'; -import { ClassDTO } from '../interfaces/classes'; -import { getAllAssignments } from '../services/assignments'; +import { + getStudentClasses, + getStudentClassIds, + StudentService +} from '../services/students.js'; +import { ClassDTO } from '../interfaces/classes.js'; +import { getAllAssignments } from '../services/assignments.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 { - try { - const students = await getAllStudents(); - - res.json({ - students: students - }); - } catch (error) { - console.error('Error fetching learning objects:', error); - res.status(500).json({ error: 'Internal server error' }); - } +export async function getAllStudentsHandler (req: Request, res: Response): Promise { + await getAllUsersHandler(req, res, new StudentService()); } -export async function getStudentHandler( - req: Request, - res: Response, -): Promise { - try { - const username = req.params.id; - const student = await getStudent(username); - - if (!student) { - res.status(404).json({ error: "Student not found" }); - return; - } else { - student.endpoints = { - classes: `/student/${req.params.id}/classes`, - questions: `/student/${req.params.id}/submissions`, - invitations: `/student/${req.params.id}/assignments`, - groups: `/student/${req.params.id}/groups`, - } - res.json(student); - } - - } catch (error) { - console.error('Error fetching learning objects:', error); - res.status(500).json({ error: 'Internal server error' }); - } +export async function getStudentHandler(req: Request, res: Response): Promise { + await getUserHandler(req, res, new StudentService()); } +export async function createStudentHandler(req: Request, res: Response): Promise { + await createUserHandler(req, res, new StudentService(), Student); +} + +export async function deleteStudentHandler(req: Request, res: Response): Promise { + await deleteUserHandler(req, res, new StudentService()); +} + + export async function getStudentClassesHandler ( req: Request, res: Response, @@ -75,6 +55,7 @@ export async function getStudentClassesHandler ( } } +// TODO // Might not be fully correct depending on if // a class has an assignment, that all students // have this assignment. @@ -92,4 +73,6 @@ export async function getStudentAssignmentsHandler( res.json({ assignments: assignments }); -} \ No newline at end of file +} + + diff --git a/backend/src/controllers/users.ts b/backend/src/controllers/users.ts new file mode 100644 index 00000000..4b29617e --- /dev/null +++ b/backend/src/controllers/users.ts @@ -0,0 +1,106 @@ +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"; + +export async function getAllUsersHandler( + req: Request, + res: Response, + service: UserService +): Promise { + try { + const full = req.query.full === 'true'; + + let users: UserDTO[] | string[] = full + ? await service.getAllUsers() + : await service.getAllUserIds(); + + 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" }); + } +} + +export async function getUserHandler( + req: Request, + res: Response, + service: UserService +): Promise { + try { + const username = req.params.username as string; + + if (!username) { + res.status(400).json({ error: 'Missing required field: username' }); + return; + } + + const user = await service.getUserByUsername(username); + + 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" }); + } +} + +export async function createUserHandler( + req: Request, + res: Response, + service: UserService, + UserClass: new () => T +) { + try { + 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" }); + 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" }); + } +} + +export async function deleteUserHandler ( + req: Request, + res: Response, + service: UserService +) { + try { + const username = req.params.username; + + if (!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.` }); + return; + } + + res.status(200).json(deletedUser); + } catch (error) { + console.error("❌ Error deleting user:", error); + res.status(500).json({ error: "Internal server error" }); + } +} diff --git a/backend/src/data/repositories.ts b/backend/src/data/repositories.ts index 35ad26cd..e65bb882 100644 --- a/backend/src/data/repositories.ts +++ b/backend/src/data/repositories.ts @@ -59,7 +59,7 @@ function repositoryGetter>( } /* Users */ -export const getUserRepository = repositoryGetter(User); +export const getUserRepository = repositoryGetter>(User); export const getStudentRepository = repositoryGetter< Student, StudentRepository diff --git a/backend/src/data/users/student-repository.ts b/backend/src/data/users/student-repository.ts index 1c3a6fae..c553aab8 100644 --- a/backend/src/data/users/student-repository.ts +++ b/backend/src/data/users/student-repository.ts @@ -1,11 +1,4 @@ -import { DwengoEntityRepository } from '../dwengo-entity-repository.js'; import { Student } from '../../entities/users/student.entity.js'; +import {UserRepository} from "./user-repository.js"; -export class StudentRepository extends DwengoEntityRepository { - public findByUsername(username: string): Promise { - return this.findOne({ username: username }); - } - public deleteByUsername(username: string): Promise { - return this.deleteWhere({ username: username }); - } -} +export class StudentRepository extends UserRepository {} diff --git a/backend/src/data/users/teacher-repository.ts b/backend/src/data/users/teacher-repository.ts index 704ef409..9940b4bd 100644 --- a/backend/src/data/users/teacher-repository.ts +++ b/backend/src/data/users/teacher-repository.ts @@ -1,11 +1,4 @@ -import { DwengoEntityRepository } from '../dwengo-entity-repository.js'; import { Teacher } from '../../entities/users/teacher.entity.js'; +import {UserRepository} from "./user-repository.js"; -export class TeacherRepository extends DwengoEntityRepository { - public findByUsername(username: string): Promise { - return this.findOne({ username: username }); - } - public deleteByUsername(username: string): Promise { - return this.deleteWhere({ username: username }); - } -} +export class TeacherRepository extends UserRepository {} diff --git a/backend/src/data/users/user-repository.ts b/backend/src/data/users/user-repository.ts index 7e2a42ad..21497b79 100644 --- a/backend/src/data/users/user-repository.ts +++ b/backend/src/data/users/user-repository.ts @@ -1,11 +1,11 @@ import { DwengoEntityRepository } from '../dwengo-entity-repository.js'; import { User } from '../../entities/users/user.entity.js'; -export class UserRepository extends DwengoEntityRepository { - public findByUsername(username: string): Promise { - return this.findOne({ username: username }); +export class UserRepository extends DwengoEntityRepository { + public findByUsername(username: string): Promise { + return this.findOne({ username } as Partial); } public deleteByUsername(username: string): Promise { - return this.deleteWhere({ username: username }); + return this.deleteWhere({ username } as Partial); } } diff --git a/backend/src/entities/content/learning-object.entity.ts b/backend/src/entities/content/learning-object.entity.ts index 179a2f5f..78d4aa00 100644 --- a/backend/src/entities/content/learning-object.entity.ts +++ b/backend/src/entities/content/learning-object.entity.ts @@ -13,6 +13,15 @@ import { Attachment } from './attachment.entity.js'; import { Teacher } from '../users/teacher.entity.js'; import { LearningObjectRepository } from '../../data/content/learning-object-repository.js'; +@Embeddable() +export class ReturnValue { + @Property({ type: 'string' }) + callbackUrl!: string; + + @Property({ type: 'json' }) + callbackSchema!: string; +} + @Entity({ repository: () => LearningObjectRepository }) export class LearningObject { @PrimaryKey({ type: 'string' }) @@ -88,15 +97,6 @@ export class EducationalGoal { id!: string; } -@Embeddable() -export class ReturnValue { - @Property({ type: 'string' }) - callbackUrl!: string; - - @Property({ type: 'json' }) - callbackSchema!: string; -} - export enum ContentType { Markdown = 'text/markdown', Image = 'image/image', diff --git a/backend/src/entities/users/student.entity.ts b/backend/src/entities/users/student.entity.ts index dc791adc..401b1ed2 100644 --- a/backend/src/entities/users/student.entity.ts +++ b/backend/src/entities/users/student.entity.ts @@ -11,12 +11,4 @@ export class Student extends User { @ManyToMany(() => Group) groups!: Collection; - - constructor( - public username: string, - public firstName: string, - public lastName: string - ) { - super(); - } } diff --git a/backend/src/interfaces/assignments.ts b/backend/src/interfaces/assignments.ts index 7fabece5..146a0517 100644 --- a/backend/src/interfaces/assignments.ts +++ b/backend/src/interfaces/assignments.ts @@ -1,6 +1,5 @@ -import { Assignment } from "../entities/assignments/assignment.entity"; -import { Class } from "../entities/classes/class.entity"; -import { GroupDTO, mapToGroupDTO } from "./groups"; +import { Assignment } from "../entities/assignments/assignment.entity.js"; +import { GroupDTO, mapToGroupDTO } from "./groups.js"; export interface AssignmentDTO { id: number, @@ -34,4 +33,4 @@ export function mapToAssignmentDTO(assignment: Assignment): AssignmentDTO { language: assignment.learningPathLanguage, // groups: assignment.groups.map(mapToGroupDTO), }; -} \ No newline at end of file +} diff --git a/backend/src/interfaces/classes.ts b/backend/src/interfaces/classes.ts index 5c285446..0274d90c 100644 --- a/backend/src/interfaces/classes.ts +++ b/backend/src/interfaces/classes.ts @@ -1,4 +1,4 @@ -import { Class } from "../entities/classes/class.entity"; +import { Class } from "../entities/classes/class.entity.js"; export interface ClassDTO { id: string; diff --git a/backend/src/interfaces/groups.ts b/backend/src/interfaces/groups.ts index fe78cc69..c4c95baf 100644 --- a/backend/src/interfaces/groups.ts +++ b/backend/src/interfaces/groups.ts @@ -1,6 +1,6 @@ -import { Group } from "../entities/assignments/group.entity"; -import { AssignmentDTO, mapToAssignmentDTO } from "./assignments"; -import { mapToStudentDTO, StudentDTO } from "./students"; +import { Group } from "../entities/assignments/group.entity.js"; +import { AssignmentDTO, mapToAssignmentDTO } from "./assignments.js"; +import { mapToStudentDTO, StudentDTO } from "./students.js"; export interface GroupDTO { assignment: number | AssignmentDTO, @@ -10,7 +10,7 @@ export interface GroupDTO { export function mapToGroupDTO(group: Group): GroupDTO { return { - assignment: mapToAssignmentDTO(group.assignment, group.assignment.within), + assignment: mapToAssignmentDTO(group.assignment), // ERROR: , group.assignment.within), groupNumber: group.groupNumber, members: group.members.map(mapToStudentDTO), } @@ -22,4 +22,4 @@ export function mapToGroupDTOId(group: Group): GroupDTO { groupNumber: group.groupNumber, members: group.members.map(member => member.username), } -} \ No newline at end of file +} diff --git a/backend/src/interfaces/students.ts b/backend/src/interfaces/students.ts index e87e707d..c18461e8 100644 --- a/backend/src/interfaces/students.ts +++ b/backend/src/interfaces/students.ts @@ -1,4 +1,4 @@ -import { Student } from "../entities/users/student.entity"; +import { Student } from "../entities/users/student.entity.js"; export interface StudentDTO { id: string; @@ -20,4 +20,13 @@ export function mapToStudentDTO(student: Student): StudentDTO { firstName: student.firstName, lastName: student.lastName, }; -} \ No newline at end of file +} + +export function mapToStudent(studentData: StudentDTO): Student { + const student = new Student(); + student.username = studentData.username; + student.firstName = studentData.firstName; + student.lastName = studentData.lastName; + + return student; +} diff --git a/backend/src/interfaces/teacher-invitation.ts b/backend/src/interfaces/teacher-invitation.ts index c563968b..489e5565 100644 --- a/backend/src/interfaces/teacher-invitation.ts +++ b/backend/src/interfaces/teacher-invitation.ts @@ -1,6 +1,6 @@ -import { TeacherInvitation } from "../entities/classes/teacher-invitation.entity"; -import { ClassDTO, mapToClassDTO } from "./classes"; -import { mapToTeacherDTO, TeacherDTO } from "./teacher"; +import { TeacherInvitation } from "../entities/classes/teacher-invitation.entity.js"; +import { ClassDTO, mapToClassDTO } from "./classes.js"; +import { mapToTeacherDTO, TeacherDTO } from "./teacher.js"; export interface TeacherInvitationDTO { sender: string | TeacherDTO, @@ -22,4 +22,4 @@ export function mapToTeacherInvitationDTOIds(invitation: TeacherInvitation): Tea receiver: invitation.receiver.username, class: invitation.class.classId, }; -} \ No newline at end of file +} diff --git a/backend/src/interfaces/teacher.ts b/backend/src/interfaces/teacher.ts index 5aee089c..4f489c57 100644 --- a/backend/src/interfaces/teacher.ts +++ b/backend/src/interfaces/teacher.ts @@ -1,4 +1,4 @@ -import { Teacher } from "../entities/users/teacher.entity"; +import { Teacher } from "../entities/users/teacher.entity.js"; export interface TeacherDTO { id: string; @@ -20,4 +20,4 @@ export function mapToTeacherDTO(teacher: Teacher): TeacherDTO { firstName: teacher.firstName, lastName: teacher.lastName, }; -} \ No newline at end of file +} diff --git a/backend/src/interfaces/user.ts b/backend/src/interfaces/user.ts new file mode 100644 index 00000000..02e27d83 --- /dev/null +++ b/backend/src/interfaces/user.ts @@ -0,0 +1,30 @@ +import { User } from "../entities/users/user.entity.js"; + +export interface UserDTO { + id?: string, + username: string; + firstName: string; + lastName: string; + endpoints?: { + self: string; + classes: string; + questions: string; + invitations: string; + }; +} + +export function mapToUserDTO(user: User): UserDTO { + return { + id: user.username, + username: user.username, + firstName: user.firstName, + lastName: user.lastName, + }; +} + +export function mapToUser(userData: UserDTO, userInstance: T): T { + userInstance.username = userData.username; + userInstance.firstName = userData.firstName; + userInstance.lastName = userData.lastName; + return userInstance; +} diff --git a/backend/src/routes/assignment.ts b/backend/src/routes/assignment.ts index d6965c49..9d83e755 100644 --- a/backend/src/routes/assignment.ts +++ b/backend/src/routes/assignment.ts @@ -1,5 +1,5 @@ import express from 'express' -import { getAllAssignmentsHandler, getAssignmentHandler } from '../controllers/assignments'; +import { getAllAssignmentsHandler, getAssignmentHandler } from '../controllers/assignments.js'; import groupRouter from './group.js'; const router = express.Router({ mergeParams: true }); @@ -28,4 +28,4 @@ router.get('/:id/questions', (req, res) => { router.use('/:assignmentid/groups', groupRouter); -export default router \ No newline at end of file +export default router diff --git a/backend/src/routes/class.ts b/backend/src/routes/class.ts index 369e6ff4..06154e60 100644 --- a/backend/src/routes/class.ts +++ b/backend/src/routes/class.ts @@ -1,5 +1,5 @@ import express from 'express' -import { getAllClassesHandler, getClassHandler, getClassStudentsHandler, getTeacherInvitationsHandler } from '../controllers/classes'; +import { getAllClassesHandler, getClassHandler, getClassStudentsHandler, getTeacherInvitationsHandler } from '../controllers/classes.js'; import assignmentRouter from './assignment.js'; const router = express.Router(); @@ -16,4 +16,4 @@ router.get('/:id/students', getClassStudentsHandler); router.use('/:classid/assignments', assignmentRouter); -export default router \ No newline at end of file +export default router diff --git a/backend/src/routes/group.ts b/backend/src/routes/group.ts index a8d4dbe5..76cdc61f 100644 --- a/backend/src/routes/group.ts +++ b/backend/src/routes/group.ts @@ -1,5 +1,5 @@ import express from 'express' -import { getAllGroupsHandler, getGroupHandler } from '../controllers/groups'; +import { getAllGroupsHandler, getGroupHandler } from '../controllers/groups.js'; const router = express.Router({ mergeParams: true }); // root endpoint used to search objects @@ -15,4 +15,4 @@ router.get('/:id/question', (req, res) => { }); }) -export default router \ No newline at end of file +export default router diff --git a/backend/src/routes/student.ts b/backend/src/routes/student.ts index bc806b4e..a5355c48 100644 --- a/backend/src/routes/student.ts +++ b/backend/src/routes/student.ts @@ -1,12 +1,24 @@ import express from 'express' -import { getAllStudentsHandler, getStudentAssignmentsHandler, getStudentClassesHandler, getStudentHandler } from '../controllers/students'; +import { + createStudentHandler, deleteStudentHandler, + getAllStudentsHandler, + getStudentAssignmentsHandler, + getStudentClassesHandler, + getStudentHandler +} from '../controllers/students.js'; const router = express.Router(); // root endpoint used to search objects router.get('/', getAllStudentsHandler); +router.post('/', createStudentHandler); + +router.delete('/:username', deleteStudentHandler); + // information about a student's profile -router.get('/:id', getStudentHandler); +router.get('/:username', getStudentHandler); + + // the list of classes a student is in router.get('/:id/classes', getStudentClassesHandler); @@ -18,10 +30,10 @@ router.get('/:id/submissions', (req, res) => { }); }) - + // the list of assignments a student has router.get('/:id/assignments', getStudentAssignmentsHandler); - + // the list of groups a student is in router.get('/:id/groups', (req, res) => { res.json({ @@ -36,4 +48,4 @@ router.get('/:id/questions', (req, res) => { }); }) -export default router \ No newline at end of file +export default router diff --git a/backend/src/services/assignments.ts b/backend/src/services/assignments.ts index e0804750..aaa51c10 100644 --- a/backend/src/services/assignments.ts +++ b/backend/src/services/assignments.ts @@ -1,5 +1,5 @@ -import { getAssignmentRepository, getClassRepository } from "../data/repositories"; -import { AssignmentDTO, mapToAssignmentDTO, mapToAssignmentDTOId } from "../interfaces/assignments"; +import { getAssignmentRepository, getClassRepository } from "../data/repositories.js"; +import { AssignmentDTO, mapToAssignmentDTO, mapToAssignmentDTOId } from "../interfaces/assignments.js"; export async function getAllAssignments(classid: string, full: boolean): Promise { const classRepository = getClassRepository(); @@ -8,7 +8,7 @@ export async function getAllAssignments(classid: string, full: boolean): Promise if (!cls) { return []; } - + const assignmentRepository = getAssignmentRepository(); const assignments = await assignmentRepository.findAllAssignmentsInClass(cls); @@ -26,7 +26,7 @@ export async function getAssignment(classid: string, id: number): Promise { const classRepository = getClassRepository(); @@ -11,7 +10,7 @@ export async function getAllClasses(full: boolean): Promise { @@ -64,4 +64,4 @@ export async function getAllGroups( } return groups.map(mapToGroupDTOId); -} \ No newline at end of file +} diff --git a/backend/src/services/students.ts b/backend/src/services/students.ts index a69cab85..24c9029b 100644 --- a/backend/src/services/students.ts +++ b/backend/src/services/students.ts @@ -1,26 +1,13 @@ -import { getClassRepository, getStudentRepository } from "../data/repositories"; -import { Class } from "../entities/classes/class.entity"; -import { Student } from "../entities/users/student.entity"; -import { ClassDTO, mapToClassDTO } from "../interfaces/classes"; -import { StudentDTO, mapToStudentDTO } from "../interfaces/students"; +import { getClassRepository, getStudentRepository } from "../data/repositories.js"; +import { Class } from "../entities/classes/class.entity.js"; +import { Student } from "../entities/users/student.entity.js"; +import { ClassDTO, mapToClassDTO } from "../interfaces/classes.js"; +import {UserService} from "./users.js"; - -export async function getAllStudents(): Promise { - const studentRepository = getStudentRepository(); - const students = await studentRepository.find({}); - - return students.map(mapToStudentDTO); -} - -export async function getStudent(username: string): Promise { - const studentRepository = getStudentRepository(); - const student = await studentRepository.findByUsername(username); - - if (!student) { - return null; +export class StudentService extends UserService { + constructor() { + super(getStudentRepository()); } - - return mapToStudentDTO(student); } async function fetchStudentClasses(username: string): Promise { diff --git a/backend/src/services/users.ts b/backend/src/services/users.ts new file mode 100644 index 00000000..bf88e916 --- /dev/null +++ b/backend/src/services/users.ts @@ -0,0 +1,39 @@ +import { UserRepository } from "../data/users/user-repository.js"; +import { UserDTO, mapToUser, mapToUserDTO } from "../interfaces/user.js"; +import {User} from "../entities/users/user.entity.js"; + +export class UserService { + protected repository: UserRepository; + + constructor(repository: UserRepository) { + this.repository = repository; + } + + async getAllUsers(): Promise { + const users = await this.repository.findAll(); + return users.map(mapToUserDTO); + } + + async getAllUserIds(): Promise { + const users = await this.getAllUsers(); + return users.map((user) => user.username); + } + + async getUserByUsername(username: string): Promise { + const user = await this.repository.findByUsername(username) + return user ? mapToUserDTO(user) : null; + } + + async createUser(userData: UserDTO, UserClass: new () => T): Promise { + const newUser = mapToUser(userData, new UserClass()); + await this.repository.save(newUser); + return newUser; + } + + async deleteUser(username: string): Promise { + const user = await this.getUserByUsername(username); + if (!user) return null; + await this.repository.deleteByUsername(username) + return mapToUserDTO(user); + } +} diff --git a/backend/src/util/translationHelper.ts b/backend/src/util/translationHelper.ts index f4443531..eb7141ee 100644 --- a/backend/src/util/translationHelper.ts +++ b/backend/src/util/translationHelper.ts @@ -1,7 +1,7 @@ import fs from 'fs'; import path from 'path'; import yaml from 'js-yaml'; -import {FALLBACK_LANG} from "../../config"; +import {FALLBACK_LANG} from "../config.js"; export function loadTranslations(language: string): T { try {