refactor: delete endpoint back and frontend
This commit is contained in:
		
							parent
							
								
									a59417b8f5
								
							
						
					
					
						commit
						17620434f2
					
				
					 6 changed files with 0 additions and 69 deletions
				
			
		|  | @ -7,7 +7,6 @@ import { | ||||||
|     getJoinRequestsByClass, |     getJoinRequestsByClass, | ||||||
|     getStudentsByTeacher, |     getStudentsByTeacher, | ||||||
|     getTeacher, |     getTeacher, | ||||||
|     getTeacherQuestions, |  | ||||||
|     updateClassJoinRequestStatus, |     updateClassJoinRequestStatus, | ||||||
| } from '../services/teachers.js'; | } from '../services/teachers.js'; | ||||||
| import { requireFields } from './error-helper.js'; | import { requireFields } from './error-helper.js'; | ||||||
|  | @ -70,16 +69,6 @@ export async function getTeacherStudentHandler(req: Request, res: Response): Pro | ||||||
|     res.json({ students }); |     res.json({ students }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function getTeacherQuestionHandler(req: Request, res: Response): Promise<void> { |  | ||||||
|     const username = req.params.username; |  | ||||||
|     const full = req.query.full === 'true'; |  | ||||||
|     requireFields({ username }); |  | ||||||
| 
 |  | ||||||
|     const questions = await getTeacherQuestions(username, full); |  | ||||||
| 
 |  | ||||||
|     res.json({ questions }); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export async function getStudentJoinRequestHandler(req: Request, res: Response): Promise<void> { | export async function getStudentJoinRequestHandler(req: Request, res: Response): Promise<void> { | ||||||
|     const classId = req.params.classId; |     const classId = req.params.classId; | ||||||
|     requireFields({ classId }); |     requireFields({ classId }); | ||||||
|  |  | ||||||
|  | @ -2,7 +2,6 @@ import { DwengoEntityRepository } from '../dwengo-entity-repository.js'; | ||||||
| import { LearningObject } from '../../entities/content/learning-object.entity.js'; | import { LearningObject } from '../../entities/content/learning-object.entity.js'; | ||||||
| import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js'; | import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js'; | ||||||
| import { Language } from '@dwengo-1/common/util/language'; | import { Language } from '@dwengo-1/common/util/language'; | ||||||
| import { Teacher } from '../../entities/users/teacher.entity.js'; |  | ||||||
| 
 | 
 | ||||||
| export class LearningObjectRepository extends DwengoEntityRepository<LearningObject> { | export class LearningObjectRepository extends DwengoEntityRepository<LearningObject> { | ||||||
|     public async findByIdentifier(identifier: LearningObjectIdentifier): Promise<LearningObject | null> { |     public async findByIdentifier(identifier: LearningObjectIdentifier): Promise<LearningObject | null> { | ||||||
|  | @ -32,11 +31,4 @@ export class LearningObjectRepository extends DwengoEntityRepository<LearningObj | ||||||
|             } |             } | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
| 
 |  | ||||||
|     public async findAllByTeacher(teacher: Teacher): Promise<LearningObject[]> { |  | ||||||
|         return this.find( |  | ||||||
|             { admins: teacher }, |  | ||||||
|             { populate: ['admins'] } // Make sure to load admin relations
 |  | ||||||
|         ); |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -6,7 +6,6 @@ import { | ||||||
|     getStudentJoinRequestHandler, |     getStudentJoinRequestHandler, | ||||||
|     getTeacherClassHandler, |     getTeacherClassHandler, | ||||||
|     getTeacherHandler, |     getTeacherHandler, | ||||||
|     getTeacherQuestionHandler, |  | ||||||
|     getTeacherStudentHandler, |     getTeacherStudentHandler, | ||||||
|     updateStudentJoinRequestHandler, |     updateStudentJoinRequestHandler, | ||||||
| } from '../controllers/teachers.js'; | } from '../controllers/teachers.js'; | ||||||
|  | @ -27,8 +26,6 @@ router.get('/:username/classes', getTeacherClassHandler); | ||||||
| 
 | 
 | ||||||
| router.get('/:username/students', getTeacherStudentHandler); | router.get('/:username/students', getTeacherStudentHandler); | ||||||
| 
 | 
 | ||||||
| router.get('/:username/questions', getTeacherQuestionHandler); |  | ||||||
| 
 |  | ||||||
| router.get('/:username/joinRequests/:classId', getStudentJoinRequestHandler); | router.get('/:username/joinRequests/:classId', getStudentJoinRequestHandler); | ||||||
| 
 | 
 | ||||||
| router.put('/:username/joinRequests/:classId/:studentUsername', updateStudentJoinRequestHandler); | router.put('/:username/joinRequests/:classId/:studentUsername', updateStudentJoinRequestHandler); | ||||||
|  |  | ||||||
|  | @ -1,12 +1,9 @@ | ||||||
| import { | import { | ||||||
|     getClassJoinRequestRepository, |     getClassJoinRequestRepository, | ||||||
|     getClassRepository, |     getClassRepository, | ||||||
|     getLearningObjectRepository, |  | ||||||
|     getQuestionRepository, |  | ||||||
|     getTeacherRepository, |     getTeacherRepository, | ||||||
| } from '../data/repositories.js'; | } from '../data/repositories.js'; | ||||||
| import { mapToClassDTO } from '../interfaces/class.js'; | import { mapToClassDTO } from '../interfaces/class.js'; | ||||||
| import { mapToQuestionDTO, mapToQuestionDTOId } from '../interfaces/question.js'; |  | ||||||
| import { mapToTeacher, mapToTeacherDTO } from '../interfaces/teacher.js'; | import { mapToTeacher, mapToTeacherDTO } from '../interfaces/teacher.js'; | ||||||
| import { Teacher } from '../entities/users/teacher.entity.js'; | import { Teacher } from '../entities/users/teacher.entity.js'; | ||||||
| import { fetchStudent } from './students.js'; | import { fetchStudent } from './students.js'; | ||||||
|  | @ -15,10 +12,6 @@ import { mapToStudentRequestDTO } from '../interfaces/student-request.js'; | ||||||
| import { TeacherRepository } from '../data/users/teacher-repository.js'; | import { TeacherRepository } from '../data/users/teacher-repository.js'; | ||||||
| import { ClassRepository } from '../data/classes/class-repository.js'; | import { ClassRepository } from '../data/classes/class-repository.js'; | ||||||
| import { Class } from '../entities/classes/class.entity.js'; | import { Class } from '../entities/classes/class.entity.js'; | ||||||
| import { LearningObjectRepository } from '../data/content/learning-object-repository.js'; |  | ||||||
| import { LearningObject } from '../entities/content/learning-object.entity.js'; |  | ||||||
| import { QuestionRepository } from '../data/questions/question-repository.js'; |  | ||||||
| import { Question } from '../entities/questions/question.entity.js'; |  | ||||||
| import { ClassJoinRequestRepository } from '../data/classes/class-join-request-repository.js'; | import { ClassJoinRequestRepository } from '../data/classes/class-join-request-repository.js'; | ||||||
| import { Student } from '../entities/users/student.entity.js'; | import { Student } from '../entities/users/student.entity.js'; | ||||||
| import { NotFoundException } from '../exceptions/not-found-exception.js'; | import { NotFoundException } from '../exceptions/not-found-exception.js'; | ||||||
|  | @ -26,7 +19,6 @@ import { addClassStudent, fetchClass, getClassStudentsDTO } from './classes.js'; | ||||||
| import { TeacherDTO } from '@dwengo-1/common/interfaces/teacher'; | import { TeacherDTO } from '@dwengo-1/common/interfaces/teacher'; | ||||||
| import { ClassDTO } from '@dwengo-1/common/interfaces/class'; | import { ClassDTO } from '@dwengo-1/common/interfaces/class'; | ||||||
| import { StudentDTO } from '@dwengo-1/common/interfaces/student'; | import { StudentDTO } from '@dwengo-1/common/interfaces/student'; | ||||||
| import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; |  | ||||||
| import { ClassJoinRequestDTO } from '@dwengo-1/common/interfaces/class-join-request'; | import { ClassJoinRequestDTO } from '@dwengo-1/common/interfaces/class-join-request'; | ||||||
| import { ClassStatus } from '@dwengo-1/common/util/class-join-request'; | import { ClassStatus } from '@dwengo-1/common/util/class-join-request'; | ||||||
| import { ConflictException } from '../exceptions/conflict-exception.js'; | import { ConflictException } from '../exceptions/conflict-exception.js'; | ||||||
|  | @ -119,28 +111,6 @@ export async function getStudentsByTeacher(username: string, full: boolean): Pro | ||||||
|     return students.map((student) => student.username); |     return students.map((student) => student.username); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function getTeacherQuestions(username: string, full: boolean): Promise<QuestionDTO[] | QuestionId[]> { |  | ||||||
|     const teacher: Teacher = await fetchTeacher(username); |  | ||||||
| 
 |  | ||||||
|     // Find all learning objects that this teacher manages
 |  | ||||||
|     const learningObjectRepository: LearningObjectRepository = getLearningObjectRepository(); |  | ||||||
|     const learningObjects: LearningObject[] = await learningObjectRepository.findAllByTeacher(teacher); |  | ||||||
| 
 |  | ||||||
|     if (!learningObjects || learningObjects.length === 0) { |  | ||||||
|         return []; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     // Fetch all questions related to these learning objects
 |  | ||||||
|     const questionRepository: QuestionRepository = getQuestionRepository(); |  | ||||||
|     const questions: Question[] = await questionRepository.findAllByLearningObjects(learningObjects); |  | ||||||
| 
 |  | ||||||
|     if (full) { |  | ||||||
|         return questions.map(mapToQuestionDTO); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return questions.map(mapToQuestionDTOId); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export async function getJoinRequestsByClass(classId: string): Promise<ClassJoinRequestDTO[]> { | export async function getJoinRequestsByClass(classId: string): Promise<ClassJoinRequestDTO[]> { | ||||||
|     const classRepository: ClassRepository = getClassRepository(); |     const classRepository: ClassRepository = getClassRepository(); | ||||||
|     const cls: Class | null = await classRepository.findById(classId); |     const cls: Class | null = await classRepository.findById(classId); | ||||||
|  |  | ||||||
|  | @ -1,6 +1,5 @@ | ||||||
| import { BaseController } from "@/controllers/base-controller.ts"; | import { BaseController } from "@/controllers/base-controller.ts"; | ||||||
| import type { JoinRequestResponse, JoinRequestsResponse, StudentsResponse } from "@/controllers/students.ts"; | import type { JoinRequestResponse, JoinRequestsResponse, StudentsResponse } from "@/controllers/students.ts"; | ||||||
| import type { QuestionsResponse } from "@/controllers/questions.ts"; |  | ||||||
| import type { ClassesResponse } from "@/controllers/classes.ts"; | import type { ClassesResponse } from "@/controllers/classes.ts"; | ||||||
| import type { TeacherDTO } from "@dwengo-1/common/interfaces/teacher"; | import type { TeacherDTO } from "@dwengo-1/common/interfaces/teacher"; | ||||||
| 
 | 
 | ||||||
|  | @ -40,10 +39,6 @@ export class TeacherController extends BaseController { | ||||||
|         return this.get<StudentsResponse>(`/${username}/students`, { full }); |         return this.get<StudentsResponse>(`/${username}/students`, { full }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async getQuestions(username: string, full = false): Promise<QuestionsResponse> { |  | ||||||
|         return this.get<QuestionsResponse>(`/${username}/questions`, { full }); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     async getStudentJoinRequests(username: string, classId: string): Promise<JoinRequestsResponse> { |     async getStudentJoinRequests(username: string, classId: string): Promise<JoinRequestsResponse> { | ||||||
|         return this.get<JoinRequestsResponse>(`/${username}/joinRequests/${classId}`); |         return this.get<JoinRequestsResponse>(`/${username}/joinRequests/${classId}`); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -10,7 +10,6 @@ import { | ||||||
| import { TeacherController, type TeacherResponse, type TeachersResponse } from "@/controllers/teachers.ts"; | import { TeacherController, type TeacherResponse, type TeachersResponse } from "@/controllers/teachers.ts"; | ||||||
| import type { ClassesResponse } from "@/controllers/classes.ts"; | import type { ClassesResponse } from "@/controllers/classes.ts"; | ||||||
| import type { JoinRequestResponse, JoinRequestsResponse, StudentsResponse } from "@/controllers/students.ts"; | import type { JoinRequestResponse, JoinRequestsResponse, StudentsResponse } from "@/controllers/students.ts"; | ||||||
| import type { QuestionsResponse } from "@/controllers/questions.ts"; |  | ||||||
| import type { TeacherDTO } from "@dwengo-1/common/interfaces/teacher"; | import type { TeacherDTO } from "@dwengo-1/common/interfaces/teacher"; | ||||||
| import { studentJoinRequestQueryKey, studentJoinRequestsQueryKey } from "@/queries/students.ts"; | import { studentJoinRequestQueryKey, studentJoinRequestsQueryKey } from "@/queries/students.ts"; | ||||||
| 
 | 
 | ||||||
|  | @ -80,17 +79,6 @@ export function useTeacherStudentsQuery( | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export function useTeacherQuestionsQuery( |  | ||||||
|     username: MaybeRefOrGetter<string | undefined>, |  | ||||||
|     full: MaybeRefOrGetter<boolean> = false, |  | ||||||
| ): UseQueryReturnType<QuestionsResponse, Error> { |  | ||||||
|     return useQuery({ |  | ||||||
|         queryKey: computed(() => teacherQuestionsQueryKey(toValue(username)!, toValue(full))), |  | ||||||
|         queryFn: async () => teacherController.getQuestions(toValue(username)!, toValue(full)), |  | ||||||
|         enabled: () => Boolean(toValue(username)), |  | ||||||
|     }); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export function useTeacherJoinRequestsQuery( | export function useTeacherJoinRequestsQuery( | ||||||
|     username: MaybeRefOrGetter<string | undefined>, |     username: MaybeRefOrGetter<string | undefined>, | ||||||
|     classId: MaybeRefOrGetter<string | undefined>, |     classId: MaybeRefOrGetter<string | undefined>, | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Gabriellvl
						Gabriellvl