fix: meervoud en ongebruikte file gefixt #130
This commit is contained in:
		
							parent
							
								
									32a3bb0dd6
								
							
						
					
					
						commit
						ce0fabc0e2
					
				
					 4 changed files with 2 additions and 44 deletions
				
			
		|  | @ -1,5 +1,5 @@ | |||
| import { Request, Response } from 'express'; | ||||
| import { createClass, getAllClasses, getClass, getClassStudents, getClassStudentsIds, getClassTeacherInvitations } from '../services/class.js'; | ||||
| import { createClass, getAllClasses, getClass, getClassStudents, getClassStudentsIds, getClassTeacherInvitations } from '../services/classes.js'; | ||||
| import { ClassDTO } from '../interfaces/class.js'; | ||||
| 
 | ||||
| export async function getAllClassesHandler(req: Request, res: Response): Promise<void> { | ||||
|  |  | |||
|  | @ -7,10 +7,9 @@ import { | |||
| } from '../data/repositories.js'; | ||||
| import { Teacher } from '../entities/users/teacher.entity.js'; | ||||
| import { ClassDTO, mapToClassDTO } from '../interfaces/class.js'; | ||||
| import { getClassStudents } from './class.js'; | ||||
| import { getClassStudents } from './classes.js'; | ||||
| import { StudentDTO } from '../interfaces/student.js'; | ||||
| import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js'; | ||||
| import { UserService } from './users.js'; | ||||
| import { mapToUser } from '../interfaces/user.js'; | ||||
| import { mapToTeacher, mapToTeacherDTO, TeacherDTO } from '../interfaces/teacher.js'; | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,41 +0,0 @@ | |||
| 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<T extends User> { | ||||
|     protected repository: UserRepository<T>; | ||||
| 
 | ||||
|     constructor(repository: UserRepository<T>) { | ||||
|         this.repository = repository; | ||||
|     } | ||||
| 
 | ||||
|     async getAllUsers(): Promise<UserDTO[]> { | ||||
|         const users = await this.repository.findAll(); | ||||
|         return users.map(mapToUserDTO); | ||||
|     } | ||||
| 
 | ||||
|     async getAllUserIds(): Promise<string[]> { | ||||
|         const users = await this.getAllUsers(); | ||||
|         return users.map((user) => user.username); | ||||
|     } | ||||
| 
 | ||||
|     async getUserByUsername(username: string): Promise<UserDTO | null> { | ||||
|         const user = await this.repository.findByUsername(username); | ||||
|         return user ? mapToUserDTO(user) : null; | ||||
|     } | ||||
| 
 | ||||
|     async createUser(userData: UserDTO, UserClass: new () => T): Promise<T> { | ||||
|         const newUser = mapToUser(userData, new UserClass()); | ||||
|         await this.repository.save(newUser); | ||||
|         return newUser; | ||||
|     } | ||||
| 
 | ||||
|     async deleteUser(username: string): Promise<UserDTO | null> { | ||||
|         const user = await this.getUserByUsername(username); | ||||
|         if (!user) { | ||||
|             return null; | ||||
|         } | ||||
|         await this.repository.deleteByUsername(username); | ||||
|         return mapToUserDTO(user); | ||||
|     } | ||||
| } | ||||
		Reference in a new issue
	
	 Adriaan Jacquet
						Adriaan Jacquet