refactor(common): Teacher
This commit is contained in:
		
							parent
							
								
									3b51b0f1f6
								
							
						
					
					
						commit
						6ff29cb949
					
				
					 7 changed files with 28 additions and 24 deletions
				
			
		|  | @ -8,7 +8,8 @@ import { | ||||||
|     getStudentsByTeacher, |     getStudentsByTeacher, | ||||||
|     getTeacher, |     getTeacher, | ||||||
| } from '../services/teachers.js'; | } from '../services/teachers.js'; | ||||||
| import { TeacherDTO } from '../interfaces/teacher.js'; | 
 | ||||||
|  | import { TeacherDTO } from 'dwengo-1-common/src/interfaces/teacher'; | ||||||
| 
 | 
 | ||||||
| export async function getAllTeachersHandler(req: Request, res: Response): Promise<void> { | export async function getAllTeachersHandler(req: Request, res: Response): Promise<void> { | ||||||
|     const full = req.query.full === 'true'; |     const full = req.query.full === 'true'; | ||||||
|  |  | ||||||
|  | @ -1,14 +1,7 @@ | ||||||
| import { TeacherInvitation } from '../entities/classes/teacher-invitation.entity.js'; | import { TeacherInvitation } from '../entities/classes/teacher-invitation.entity.js'; | ||||||
| import { mapToClassDTO } from './class.js'; | import { mapToClassDTO } from './class.js'; | ||||||
| import { mapToUserDTO } from './user.js'; | import { mapToUserDTO } from './user.js'; | ||||||
| import { ClassDTO } from 'dwengo-1-common/src/interfaces/class'; | import { TeacherInvitationDTO } from 'dwengo-1-common/src/interfaces/teacher-invitation'; | ||||||
| import { UserDTO } from 'dwengo-1-common/src/interfaces/user'; |  | ||||||
| 
 |  | ||||||
| export interface TeacherInvitationDTO { |  | ||||||
|     sender: string | UserDTO; |  | ||||||
|     receiver: string | UserDTO; |  | ||||||
|     class: string | ClassDTO; |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| export function mapToTeacherInvitationDTO(invitation: TeacherInvitation): TeacherInvitationDTO { | export function mapToTeacherInvitationDTO(invitation: TeacherInvitation): TeacherInvitationDTO { | ||||||
|     return { |     return { | ||||||
|  |  | ||||||
|  | @ -1,18 +1,6 @@ | ||||||
| import { Teacher } from '../entities/users/teacher.entity.js'; | import { Teacher } from '../entities/users/teacher.entity.js'; | ||||||
| import { getTeacherRepository } from '../data/repositories.js'; | import { getTeacherRepository } from '../data/repositories.js'; | ||||||
| 
 | import { TeacherDTO } from 'dwengo-1-common/src/interfaces/teacher'; | ||||||
| export interface TeacherDTO { |  | ||||||
|     id: string; |  | ||||||
|     username: string; |  | ||||||
|     firstName: string; |  | ||||||
|     lastName: string; |  | ||||||
|     endpoints?: { |  | ||||||
|         classes: string; |  | ||||||
|         questions: string; |  | ||||||
|         invitations: string; |  | ||||||
|         groups: string; |  | ||||||
|     }; |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| export function mapToTeacherDTO(teacher: Teacher): TeacherDTO { | export function mapToTeacherDTO(teacher: Teacher): TeacherDTO { | ||||||
|     return { |     return { | ||||||
|  |  | ||||||
|  | @ -1,9 +1,10 @@ | ||||||
| import { getClassRepository, getStudentRepository, getTeacherInvitationRepository, getTeacherRepository } from '../data/repositories.js'; | import { getClassRepository, getStudentRepository, getTeacherInvitationRepository, getTeacherRepository } from '../data/repositories.js'; | ||||||
| import { mapToClassDTO } from '../interfaces/class.js'; | import { mapToClassDTO } from '../interfaces/class.js'; | ||||||
| import { mapToStudentDTO, StudentDTO } from '../interfaces/student.js'; | import { mapToStudentDTO, StudentDTO } from '../interfaces/student.js'; | ||||||
| import { mapToTeacherInvitationDTO, mapToTeacherInvitationDTOIds, TeacherInvitationDTO } from '../interfaces/teacher-invitation.js'; | import { mapToTeacherInvitationDTO, mapToTeacherInvitationDTOIds } from '../interfaces/teacher-invitation.js'; | ||||||
| import { getLogger } from '../logging/initalize.js'; | import { getLogger } from '../logging/initalize.js'; | ||||||
| import { ClassDTO } from 'dwengo-1-common/src/interfaces/class'; | import { ClassDTO } from 'dwengo-1-common/src/interfaces/class'; | ||||||
|  | import { TeacherInvitationDTO } from 'dwengo-1-common/src/interfaces/teacher-invitation'; | ||||||
| 
 | 
 | ||||||
| const logger = getLogger(); | const logger = getLogger(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -3,8 +3,9 @@ import { mapToClassDTO } from '../interfaces/class.js'; | ||||||
| import { getClassStudents } from './classes.js'; | import { getClassStudents } from './classes.js'; | ||||||
| import { StudentDTO } from '../interfaces/student.js'; | import { StudentDTO } from '../interfaces/student.js'; | ||||||
| import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js'; | import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js'; | ||||||
| import { mapToTeacher, mapToTeacherDTO, TeacherDTO } from '../interfaces/teacher.js'; | import { mapToTeacher, mapToTeacherDTO } from '../interfaces/teacher.js'; | ||||||
| import { ClassDTO } from 'dwengo-1-common/src/interfaces/class'; | import { ClassDTO } from 'dwengo-1-common/src/interfaces/class'; | ||||||
|  | import { TeacherDTO } from 'dwengo-1-common/src/interfaces/teacher'; | ||||||
| 
 | 
 | ||||||
| export async function getAllTeachers(full: boolean): Promise<TeacherDTO[] | string[]> { | export async function getAllTeachers(full: boolean): Promise<TeacherDTO[] | string[]> { | ||||||
|     const teacherRepository = getTeacherRepository(); |     const teacherRepository = getTeacherRepository(); | ||||||
|  |  | ||||||
							
								
								
									
										8
									
								
								common/src/interfaces/teacher-invitation.d.ts
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								common/src/interfaces/teacher-invitation.d.ts
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,8 @@ | ||||||
|  | import { UserDTO } from './user'; | ||||||
|  | import { ClassDTO } from './class'; | ||||||
|  | 
 | ||||||
|  | export interface TeacherInvitationDTO { | ||||||
|  |     sender: string | UserDTO; | ||||||
|  |     receiver: string | UserDTO; | ||||||
|  |     class: string | ClassDTO; | ||||||
|  | } | ||||||
							
								
								
									
										12
									
								
								common/src/interfaces/teacher.d.ts
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								common/src/interfaces/teacher.d.ts
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,12 @@ | ||||||
|  | export interface TeacherDTO { | ||||||
|  |     id: string; | ||||||
|  |     username: string; | ||||||
|  |     firstName: string; | ||||||
|  |     lastName: string; | ||||||
|  |     endpoints?: { | ||||||
|  |         classes: string; | ||||||
|  |         questions: string; | ||||||
|  |         invitations: string; | ||||||
|  |         groups: string; | ||||||
|  |     }; | ||||||
|  | } | ||||||
		Reference in a new issue