feat: teacher invitation databank api verbinding aangemaakt, bug in data repo waar teacher invitation repo niet juist werd teruggegeven gefixt
This commit is contained in:
		
							parent
							
								
									cfd0cce2df
								
							
						
					
					
						commit
						baf43e91de
					
				
					 6 changed files with 92 additions and 11 deletions
				
			
		|  | @ -1,5 +1,5 @@ | |||
| import { Request, Response } from 'express'; | ||||
| import { getAllClasses, getClass, getClassStudents } from '../services/class'; | ||||
| import { getAllClasses, getClass, getClassStudents, getClassTeacherInvitations } from '../services/class'; | ||||
| import { ClassDTO } from '../interfaces/classes'; | ||||
| 
 | ||||
| export async function getAllClassesHandler( | ||||
|  | @ -54,3 +54,17 @@ export async function getClassStudentsHandler( | |||
|         students: students, | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export async function getTeacherInvitationsHandler( | ||||
|     req: Request, | ||||
|     res: Response, | ||||
| ): Promise<void> { | ||||
|     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, | ||||
|     }); | ||||
| } | ||||
|  | @ -80,7 +80,7 @@ export const getClassJoinRequestRepository = repositoryGetter< | |||
| export const getTeacherInvitationRepository = repositoryGetter< | ||||
|     TeacherInvitation, | ||||
|     TeacherInvitationRepository | ||||
| >(TeacherInvitationRepository); | ||||
| >(TeacherInvitation); | ||||
| 
 | ||||
| /* Assignments */ | ||||
| export const getAssignmentRepository = repositoryGetter< | ||||
|  |  | |||
							
								
								
									
										25
									
								
								backend/src/interfaces/teacher-invitation.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								backend/src/interfaces/teacher-invitation.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,25 @@ | |||
| import { TeacherInvitation } from "../entities/classes/teacher-invitation.entity"; | ||||
| import { ClassDTO, mapToClassDTO } from "./classes"; | ||||
| import { mapToTeacherDTO, TeacherDTO } from "./teacher"; | ||||
| 
 | ||||
| export interface TeacherInvitationDTO { | ||||
|     sender: string | TeacherDTO, | ||||
|     receiver: string | TeacherDTO, | ||||
|     class: string | ClassDTO, | ||||
| } | ||||
| 
 | ||||
| export function mapToTeacherInvitationDTO(invitation: TeacherInvitation): TeacherInvitationDTO { | ||||
|     return { | ||||
|         sender: mapToTeacherDTO(invitation.sender), | ||||
|         receiver: mapToTeacherDTO(invitation.receiver), | ||||
|         class: mapToClassDTO(invitation.class), | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| export function mapToTeacherInvitationDTOIds(invitation: TeacherInvitation): TeacherInvitationDTO { | ||||
|     return { | ||||
|         sender: invitation.sender.username, | ||||
|         receiver: invitation.receiver.username, | ||||
|         class: invitation.class.classId, | ||||
|     }; | ||||
| } | ||||
							
								
								
									
										23
									
								
								backend/src/interfaces/teacher.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								backend/src/interfaces/teacher.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,23 @@ | |||
| import { Teacher } from "../entities/users/teacher.entity"; | ||||
| 
 | ||||
| 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 { | ||||
|     return { | ||||
|         id: teacher.username, | ||||
|         username: teacher.username, | ||||
|         firstName: teacher.firstName, | ||||
|         lastName: teacher.lastName, | ||||
|     }; | ||||
| } | ||||
|  | @ -1,5 +1,5 @@ | |||
| import express from 'express' | ||||
| import { getAllClassesHandler, getClassHandler, getClassStudentsHandler } from '../controllers/classes'; | ||||
| import { getAllClassesHandler, getClassHandler, getClassStudentsHandler, getTeacherInvitationsHandler } from '../controllers/classes'; | ||||
| import assignmentRouter from './assignment.js'; | ||||
| 
 | ||||
| const router = express.Router(); | ||||
|  | @ -10,13 +10,7 @@ router.get('/', getAllClassesHandler); | |||
| // information about an class with id 'id'
 | ||||
| router.get('/:id', getClassHandler); | ||||
| 
 | ||||
| router.get('/:id/invitations', (req, res) => { | ||||
|     res.json({ | ||||
|         invitations: [  | ||||
|             '0' | ||||
|         ], | ||||
|     }); | ||||
| }) | ||||
| router.get('/:id/teacher-invitations', getTeacherInvitationsHandler); | ||||
| 
 | ||||
| router.get('/:id/students', getClassStudentsHandler); | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,7 +1,8 @@ | |||
| import { getClassRepository } from "../data/repositories"; | ||||
| import { getClassRepository, getTeacherInvitationRepository } from "../data/repositories"; | ||||
| import { Class } from "../entities/classes/class.entity"; | ||||
| import { ClassDTO, mapToClassDTO } from "../interfaces/classes"; | ||||
| import { mapToStudentDTO, StudentDTO } from "../interfaces/students"; | ||||
| import { mapToTeacherInvitationDTO, mapToTeacherInvitationDTOIds, TeacherInvitationDTO } from "../interfaces/teacher-invitation"; | ||||
| 
 | ||||
| export async function getAllClasses(full: boolean): Promise<ClassDTO[] | string[]> { | ||||
|     const classRepository = getClassRepository(); | ||||
|  | @ -42,3 +43,27 @@ export async function getClassStudents(classId: string, full: boolean): Promise< | |||
|         return cls.students.map((student) => student.username); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| export async function getClassTeacherInvitations(classId: string, full: boolean): Promise<TeacherInvitationDTO[]> { | ||||
|     const classRepository = getClassRepository(); | ||||
|     const cls = await classRepository.findById(classId); | ||||
| 
 | ||||
|     if (!cls) { | ||||
|         return []; | ||||
|     } | ||||
| 
 | ||||
|     const teacherInvitationRepository = getTeacherInvitationRepository(); | ||||
|     const invitations = await teacherInvitationRepository.findAllInvitationsForClass(cls); | ||||
| 
 | ||||
|     console.log(invitations); | ||||
| 
 | ||||
|     if (!invitations) { | ||||
|         return []; | ||||
|     } | ||||
| 
 | ||||
|     if (full) { | ||||
|         return invitations.map(mapToTeacherInvitationDTO); | ||||
|     } | ||||
| 
 | ||||
|     return invitations.map(mapToTeacherInvitationDTOIds); | ||||
| } | ||||
		Reference in a new issue
	
	 Adriaan Jacquet
						Adriaan Jacquet