fix: merge + types frontend controller
This commit is contained in:
		
							parent
							
								
									4ca568e738
								
							
						
					
					
						commit
						8ceed7f779
					
				
					 20 changed files with 129 additions and 92 deletions
				
			
		|  | @ -10,11 +10,11 @@ import { | |||
|     getTeacherQuestions, | ||||
|     updateClassJoinRequestStatus, | ||||
| } from '../services/teachers.js'; | ||||
| import { ClassDTO } from '../interfaces/class.js'; | ||||
| import { StudentDTO } from '../interfaces/student.js'; | ||||
| import { QuestionDTO, QuestionId } from '../interfaces/question.js'; | ||||
| import { TeacherDTO } from '../interfaces/teacher.js'; | ||||
| import { requireFields } from './error-helper.js'; | ||||
| import {TeacherDTO} from "dwengo-1-common/src/interfaces/teacher"; | ||||
| import {ClassDTO} from "dwengo-1-common/src/interfaces/class"; | ||||
| import {StudentDTO} from "dwengo-1-common/src/interfaces/student"; | ||||
| import {QuestionDTO, QuestionId} from "dwengo-1-common/src/interfaces/question"; | ||||
| 
 | ||||
| export async function getAllTeachersHandler(req: Request, res: Response): Promise<void> { | ||||
|     const full = req.query.full === 'true'; | ||||
|  |  | |||
|  | @ -16,10 +16,10 @@ export function mapToAnswerDTO(answer: Answer): AnswerDTO { | |||
|     }; | ||||
| } | ||||
| 
 | ||||
| export function mapToAnswerId(answer: AnswerDTO): AnswerId { | ||||
| export function mapToAnswerDTOId(answer: Answer): AnswerId { | ||||
|     return { | ||||
|         author: answer.author.username, | ||||
|         toQuestion: mapToQuestionDTOId(answer.toQuestion), | ||||
|         sequenceNumber: answer.sequenceNumber, | ||||
|         sequenceNumber: answer.sequenceNumber!, | ||||
|     }; | ||||
| } | ||||
|  |  | |||
|  | @ -1,6 +1,7 @@ | |||
| import { Question } from '../entities/questions/question.entity.js'; | ||||
| import { mapToStudentDTO } from './student.js'; | ||||
| import { QuestionDTO, QuestionId } from 'dwengo-1-common/src/interfaces/question'; | ||||
| import {LearningObjectIdentifier} from "../entities/content/learning-object-identifier"; | ||||
| 
 | ||||
| function getLearningObjectIdentifier(question: Question): LearningObjectIdentifier { | ||||
|     return { | ||||
|  |  | |||
|  | @ -1,16 +1,12 @@ | |||
| import { mapToStudentDTO, StudentDTO } from './student.js'; | ||||
| import { mapToStudentDTO } from './student.js'; | ||||
| import { ClassJoinRequest, ClassJoinRequestStatus } from '../entities/classes/class-join-request.entity.js'; | ||||
| import { getClassJoinRequestRepository } from '../data/repositories.js'; | ||||
| import { Student } from '../entities/users/student.entity.js'; | ||||
| import { Class } from '../entities/classes/class.entity.js'; | ||||
| import {ClassJoinRequestDTO} from "dwengo-1-common/src/interfaces/class-join-request"; | ||||
| 
 | ||||
| export interface StudentRequestDTO { | ||||
|     requester: StudentDTO; | ||||
|     class: string; | ||||
|     status: ClassJoinRequestStatus; | ||||
| } | ||||
| 
 | ||||
| export function mapToStudentRequestDTO(request: ClassJoinRequest): StudentRequestDTO { | ||||
| export function mapToStudentRequestDTO(request: ClassJoinRequest): ClassJoinRequestDTO { | ||||
|     return { | ||||
|         requester: mapToStudentDTO(request.requester), | ||||
|         class: request.class.classId!, | ||||
|  |  | |||
|  | @ -1,11 +1,13 @@ | |||
| import { getAnswerRepository, getQuestionRepository } from '../data/repositories.js'; | ||||
| import {mapToQuestionDTO, mapToQuestionDTOId, QuestionDTO, QuestionId} from '../interfaces/question.js'; | ||||
| import {mapToQuestionDTO, mapToQuestionDTOId } from '../interfaces/question.js'; | ||||
| import { Question } from '../entities/questions/question.entity.js'; | ||||
| import { Answer } from '../entities/questions/answer.entity.js'; | ||||
| import { AnswerDTO, AnswerId, mapToAnswerDTO, mapToAnswerDTOId } from '../interfaces/answer.js'; | ||||
| import {mapToAnswerDTO, mapToAnswerDTOId} from '../interfaces/answer.js'; | ||||
| import { QuestionRepository } from '../data/questions/question-repository.js'; | ||||
| import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; | ||||
| import { mapToStudent } from '../interfaces/student.js'; | ||||
| import {QuestionDTO, QuestionId} from "dwengo-1-common/src/interfaces/question"; | ||||
| import {AnswerDTO, AnswerId} from "dwengo-1-common/src/interfaces/answer"; | ||||
| 
 | ||||
| export async function getAllQuestions(id: LearningObjectIdentifier, full: boolean): Promise<QuestionDTO[] | QuestionId[]> { | ||||
|     const questionRepository: QuestionRepository = getQuestionRepository(); | ||||
|  |  | |||
|  | @ -19,7 +19,7 @@ import { NotFoundException } from '../../src/exceptions/not-found-exception.js'; | |||
| import { BadRequestException } from '../../src/exceptions/bad-request-exception.js'; | ||||
| import { ConflictException } from '../../src/exceptions/conflict-exception.js'; | ||||
| import { EntityAlreadyExistsException } from '../../src/exceptions/entity-already-exists-exception.js'; | ||||
| import { StudentDTO } from '../../src/interfaces/student.js'; | ||||
| import {StudentDTO} from "dwengo-1-common/src/interfaces/student"; | ||||
| 
 | ||||
| describe('Student controllers', () => { | ||||
|     let req: Partial<Request>; | ||||
|  |  | |||
|  | @ -15,7 +15,8 @@ import { | |||
| import { BadRequestException } from '../../src/exceptions/bad-request-exception.js'; | ||||
| import { EntityAlreadyExistsException } from '../../src/exceptions/entity-already-exists-exception.js'; | ||||
| import { getStudentRequestsHandler } from '../../src/controllers/students.js'; | ||||
| import { TeacherDTO } from '../../src/interfaces/teacher.js'; | ||||
| import {TeacherDTO} from "dwengo-1-common/src/interfaces/teacher"; | ||||
| 
 | ||||
| 
 | ||||
| describe('Teacher controllers', () => { | ||||
|     let req: Partial<Request>; | ||||
|  |  | |||
							
								
								
									
										7
									
								
								common/src/interfaces/class-join-request.d.ts
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								common/src/interfaces/class-join-request.d.ts
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,7 @@ | |||
| import {StudentDTO} from "./student"; | ||||
| 
 | ||||
| export interface ClassJoinRequestDTO { | ||||
|     requester: StudentDTO; | ||||
|     class: string; | ||||
|     status: ClassJoinRequestStatus; | ||||
| } | ||||
							
								
								
									
										6
									
								
								common/src/interfaces/student.d.ts
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								common/src/interfaces/student.d.ts
									
										
									
									
										vendored
									
									
								
							|  | @ -3,10 +3,4 @@ export interface StudentDTO { | |||
|     username: string; | ||||
|     firstName: string; | ||||
|     lastName: string; | ||||
|     endpoints?: { | ||||
|         classes: string; | ||||
|         questions: string; | ||||
|         invitations: string; | ||||
|         groups: string; | ||||
|     }; | ||||
| } | ||||
|  |  | |||
							
								
								
									
										3
									
								
								frontend/src/controllers/assignments.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								frontend/src/controllers/assignments.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | |||
| import type {AssignmentDTO} from "dwengo-1-common/src/interfaces/assignment"; | ||||
| 
 | ||||
| export type AssignmentsResponse = { assignments: AssignmentDTO[] }; // TODO ID
 | ||||
							
								
								
									
										3
									
								
								frontend/src/controllers/classes.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								frontend/src/controllers/classes.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | |||
| import type {ClassDTO} from "dwengo-1-common/src/interfaces/class"; | ||||
| 
 | ||||
| export type ClassesResponse = { classes: ClassDTO[] | string[] }; | ||||
							
								
								
									
										3
									
								
								frontend/src/controllers/groups.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								frontend/src/controllers/groups.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | |||
| import type {GroupDTO} from "dwengo-1-common/src/interfaces/group"; | ||||
| 
 | ||||
| export type GroupsResponse = { groups: GroupDTO[] }; // | TODO id
 | ||||
							
								
								
									
										3
									
								
								frontend/src/controllers/questions.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								frontend/src/controllers/questions.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | |||
| import type {QuestionDTO, QuestionId} from "dwengo-1-common/src/interfaces/question"; | ||||
| 
 | ||||
| export type QuestionsResponse = { questions: QuestionDTO[] | QuestionId[] } | ||||
|  | @ -1,59 +1,72 @@ | |||
| import { BaseController } from "@/controllers/base-controller.ts"; | ||||
| import type {StudentDTO} from "dwengo-1-common/src/interfaces/student"; | ||||
| import type {ClassesResponse} from "@/controllers/classes.ts"; | ||||
| import type {AssignmentsResponse} from "@/controllers/assignments.ts"; | ||||
| import type {GroupsResponse} from "@/controllers/groups.ts"; | ||||
| import type {SubmissionsResponse} from "@/controllers/submissions.ts"; | ||||
| import type {QuestionsResponse} from "@/controllers/questions.ts"; | ||||
| import type {ClassJoinRequestDTO} from "dwengo-1-common/src/interfaces/class-join-request"; | ||||
| 
 | ||||
| export type StudentsResponse = { students: StudentDTO[] | string[] }; | ||||
| export type StudentResponse = { student: StudentDTO }; | ||||
| export type JoinRequestsResponse = { requests: ClassJoinRequestDTO[] }; | ||||
| export type JoinRequestResponse = { request: ClassJoinRequestDTO }; | ||||
| 
 | ||||
| 
 | ||||
| export class StudentController extends BaseController { | ||||
|     constructor() { | ||||
|         super("student"); | ||||
|     } | ||||
| 
 | ||||
|     getAll(full = true) { | ||||
|         return this.get<{ students: any[] }>("/", { full }); | ||||
|     async getAll(full = true): Promise<StudentsResponse> { | ||||
|         return this.get<StudentsResponse>("/", { full }); | ||||
|     } | ||||
| 
 | ||||
|     getByUsername(username: string) { | ||||
|         return this.get<{ student: any }>(`/${username}`); | ||||
|     async getByUsername(username: string): Promise<StudentResponse> { | ||||
|         return this.get<StudentResponse>(`/${username}`); | ||||
|     } | ||||
| 
 | ||||
|     createStudent(data: any) { | ||||
|         return this.post("/", data); | ||||
|     async createStudent(data: StudentDTO): Promise<StudentResponse> { | ||||
|         return this.post<StudentResponse>("/", data); | ||||
|     } | ||||
| 
 | ||||
|     deleteStudent(username: string) { | ||||
|         return this.delete(`/${username}`); | ||||
|     async deleteStudent(username: string): Promise<StudentResponse> { | ||||
|         return this.delete<StudentResponse>(`/${username}`); | ||||
|     } | ||||
| 
 | ||||
|     getClasses(username: string, full = true) { | ||||
|         return this.get<{ classes: any[] }>(`/${username}/classes`, { full }); | ||||
|     async getClasses(username: string, full = true): Promise<ClassesResponse> { | ||||
|         return this.get<ClassesResponse>(`/${username}/classes`, { full }); | ||||
|     } | ||||
| 
 | ||||
|     getAssignments(username: string, full = true) { | ||||
|         return this.get<{ assignments: any[] }>(`/${username}/assignments`, { full }); | ||||
|     async getAssignments(username: string, full = true): Promise<AssignmentsResponse> { | ||||
|         return this.get<AssignmentsResponse>(`/${username}/assignments`, { full }); | ||||
|     } | ||||
| 
 | ||||
|     getGroups(username: string, full = true) { | ||||
|         return this.get<{ groups: any[] }>(`/${username}/groups`, { full }); | ||||
|     async getGroups(username: string, full = true): Promise<GroupsResponse> { | ||||
|         return this.get<GroupsResponse>(`/${username}/groups`, { full }); | ||||
|     } | ||||
| 
 | ||||
|     getSubmissions(username: string) { | ||||
|         return this.get<{ submissions: any[] }>(`/${username}/submissions`); | ||||
|     async getSubmissions(username: string): Promise<SubmissionsResponse> { | ||||
|         return this.get<SubmissionsResponse>(`/${username}/submissions`); | ||||
|     } | ||||
| 
 | ||||
|     getQuestions(username: string, full = true) { | ||||
|         return this.get<{ questions: any[] }>(`/${username}/questions`, { full }); | ||||
|     async getQuestions(username: string, full = true): Promise<QuestionsResponse> { | ||||
|         return this.get<QuestionsResponse>(`/${username}/questions`, { full }); | ||||
|     } | ||||
| 
 | ||||
|     getJoinRequests(username: string) { | ||||
|         return this.get<{ requests: any[] }>(`/${username}/joinRequests`); | ||||
|     async getJoinRequests(username: string): Promise<JoinRequestsResponse> { | ||||
|         return this.get<JoinRequestsResponse>(`/${username}/joinRequests`); | ||||
|     } | ||||
| 
 | ||||
|     getJoinRequest(username: string, classId: string) { | ||||
|         return this.get<{ request: any[] }>(`/${username}/joinRequests/${classId}`); | ||||
|     async getJoinRequest(username: string, classId: string): Promise<JoinRequestResponse> { | ||||
|         return this.get<JoinRequestResponse>(`/${username}/joinRequests/${classId}`); | ||||
|     } | ||||
| 
 | ||||
|     createJoinRequest(username: string, classId: string) { | ||||
|         return this.post(`/${username}/joinRequests}`, classId); | ||||
|     async createJoinRequest(username: string, classId: string): Promise<JoinRequestResponse> { | ||||
|         return this.post<JoinRequestResponse>(`/${username}/joinRequests}`, classId); | ||||
|     } | ||||
| 
 | ||||
|     deleteJoinRequest(username: string, classId: string) { | ||||
|         return this.delete(`/${username}/joinRequests/${classId}`); | ||||
|     async deleteJoinRequest(username: string, classId: string): Promise<JoinRequestResponse> { | ||||
|         return this.delete<JoinRequestResponse>(`/${username}/joinRequests/${classId}`); | ||||
|     } | ||||
| } | ||||
|  |  | |||
							
								
								
									
										3
									
								
								frontend/src/controllers/submissions.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								frontend/src/controllers/submissions.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | |||
| import {type SubmissionDTO, SubmissionDTOId} from "dwengo-1-common/src/interfaces/submission"; | ||||
| 
 | ||||
| export type SubmissionsResponse = { submissions: SubmissionDTO[] | SubmissionDTOId[] }; | ||||
|  | @ -1,44 +1,52 @@ | |||
| import { BaseController } from "@/controllers/base-controller.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 {TeacherDTO} from "dwengo-1-common/src/interfaces/teacher"; | ||||
| 
 | ||||
| export type TeachersResponse = { teachers: TeacherDTO[] | string[] }; | ||||
| export type TeacherResponse = { teacher: TeacherDTO | string }; | ||||
| 
 | ||||
| 
 | ||||
| export class TeacherController extends BaseController { | ||||
|     constructor() { | ||||
|         super("teacher"); | ||||
|     } | ||||
| 
 | ||||
|     getAll(full = false) { | ||||
|         return this.get<{ teachers: any[] }>("/", { full }); | ||||
|     async getAll(full = false): Promise<TeachersResponse> { | ||||
|         return this.get<TeachersResponse>("/", { full }); | ||||
|     } | ||||
| 
 | ||||
|     getByUsername(username: string) { | ||||
|         return this.get<any>(`/${username}`); | ||||
|     async getByUsername(username: string): Promise<TeacherResponse> { | ||||
|         return this.get<TeacherResponse>(`/${username}`); | ||||
|     } | ||||
| 
 | ||||
|     createTeacher(data: any) { | ||||
|         return this.post("/", data); | ||||
|     async createTeacher(data: any): Promise<TeacherResponse> { | ||||
|         return this.post<TeacherResponse>("/", data); | ||||
|     } | ||||
| 
 | ||||
|     deleteTeacher(username: string) { | ||||
|         return this.delete(`/${username}`); | ||||
|     async deleteTeacher(username: string): Promise<TeacherResponse> { | ||||
|         return this.delete<TeacherResponse>(`/${username}`); | ||||
|     } | ||||
| 
 | ||||
|     getClasses(username: string, full = false) { | ||||
|         return this.get<any[]>(`/${username}/classes`, { full }); | ||||
|     async getClasses(username: string, full = false): Promise<ClassesResponse> { | ||||
|         return this.get<ClassesResponse>(`/${username}/classes`, { full }); | ||||
|     } | ||||
| 
 | ||||
|     getStudents(username: string, full = false) { | ||||
|         return this.get<{ students: any[] }>(`/${username}/students`, { full }); | ||||
|     async getStudents(username: string, full = false): Promise<StudentsResponse> { | ||||
|         return this.get<StudentsResponse>(`/${username}/students`, { full }); | ||||
|     } | ||||
| 
 | ||||
|     getQuestions(username: string, full = false) { | ||||
|         return this.get<{ questions: any[] }>(`/${username}/questions`, { full }); | ||||
|     async getQuestions(username: string, full = false): Promise<QuestionsResponse> { | ||||
|         return this.get<QuestionsResponse>(`/${username}/questions`, { full }); | ||||
|     } | ||||
| 
 | ||||
|     getStudentJoinRequests(username: string, classId: string) { | ||||
|         return this.get<{ joinRequests: any[] }>(`/${username}/joinRequests/${classId}`); | ||||
|     async getStudentJoinRequests(username: string, classId: string): Promise<JoinRequestsResponse> { | ||||
|         return this.get<JoinRequestsResponse>(`/${username}/joinRequests/${classId}`); | ||||
|     } | ||||
| 
 | ||||
|     updateStudentJoinRequest(teacherUsername: string, classId: string, studentUsername: string, accepted: boolean) { | ||||
|         return this.put(`/${teacherUsername}/joinRequests/${classId}/${studentUsername}`, accepted); | ||||
|     async updateStudentJoinRequest(teacherUsername: string, classId: string, studentUsername: string, accepted: boolean): Promise<JoinRequestResponse> { | ||||
|         return this.put<JoinRequestResponse>(`/${teacherUsername}/joinRequests/${classId}/${studentUsername}`, accepted); | ||||
|     } | ||||
| 
 | ||||
|     // GetInvitations(id: string) {return this.get<{ invitations: string[] }>(`/${id}/invitations`);}
 | ||||
|  |  | |||
|  | @ -18,14 +18,14 @@ const STUDENT_JOIN_REQUESTS_QUERY_KEY = (username: string) => ["student-join-req | |||
| export function useStudentsQuery(full: MaybeRefOrGetter<boolean> = true) { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => STUDENTS_QUERY_KEY(toValue(full))), | ||||
|         queryFn: () => studentController.getAll(toValue(full)), | ||||
|         queryFn: async () => studentController.getAll(toValue(full)), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useStudentQuery(username: MaybeRefOrGetter<string | undefined>) { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => STUDENT_QUERY_KEY(toValue(username)!)), | ||||
|         queryFn: () => studentController.getByUsername(toValue(username)!), | ||||
|         queryFn: async () => studentController.getByUsername(toValue(username)!), | ||||
|         enabled: () => Boolean(toValue(username)), | ||||
|     }); | ||||
| } | ||||
|  | @ -36,7 +36,7 @@ export function useStudentClassesQuery( | |||
| ) { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => STUDENT_CLASSES_QUERY_KEY(toValue(username)!, toValue(full))), | ||||
|         queryFn: () => studentController.getClasses(toValue(username)!, toValue(full)), | ||||
|         queryFn: async () => studentController.getClasses(toValue(username)!, toValue(full)), | ||||
|         enabled: () => Boolean(toValue(username)), | ||||
|     }); | ||||
| } | ||||
|  | @ -47,7 +47,7 @@ export function useStudentAssignmentsQuery( | |||
| ) { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => STUDENT_ASSIGNMENTS_QUERY_KEY(toValue(username)!, toValue(full))), | ||||
|         queryFn: () => studentController.getAssignments(toValue(username)!, toValue(full)), | ||||
|         queryFn: async () => studentController.getAssignments(toValue(username)!, toValue(full)), | ||||
|         enabled: () => Boolean(toValue(username)), | ||||
|     }); | ||||
| } | ||||
|  | @ -58,7 +58,7 @@ export function useStudentGroupsQuery( | |||
| ) { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => STUDENT_GROUPS_QUERY_KEY(toValue(username)!, toValue(full))), | ||||
|         queryFn: () => studentController.getGroups(toValue(username)!, toValue(full)), | ||||
|         queryFn: async () => studentController.getGroups(toValue(username)!, toValue(full)), | ||||
|         enabled: () => Boolean(toValue(username)), | ||||
|     }); | ||||
| } | ||||
|  | @ -66,7 +66,7 @@ export function useStudentGroupsQuery( | |||
| export function useStudentSubmissionsQuery(username: MaybeRefOrGetter<string | undefined>) { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => STUDENT_SUBMISSIONS_QUERY_KEY(toValue(username)!)), | ||||
|         queryFn: () => studentController.getSubmissions(toValue(username)!), | ||||
|         queryFn: async () => studentController.getSubmissions(toValue(username)!), | ||||
|         enabled: () => Boolean(toValue(username)), | ||||
|     }); | ||||
| } | ||||
|  | @ -77,7 +77,7 @@ export function useStudentQuestionsQuery( | |||
| ) { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => STUDENT_QUESTIONS_QUERY_KEY(toValue(username)!, toValue(full))), | ||||
|         queryFn: () => studentController.getQuestions(toValue(username)!, toValue(full)), | ||||
|         queryFn: async () => studentController.getQuestions(toValue(username)!, toValue(full)), | ||||
|         enabled: () => Boolean(toValue(username)), | ||||
|     }); | ||||
| } | ||||
|  | @ -86,7 +86,7 @@ export function useCreateStudentMutation() { | |||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: (data: any) => studentController.createStudent(data), | ||||
|         mutationFn: async (data: any) => studentController.createStudent(data), | ||||
|         onSuccess: () => { | ||||
|             await queryClient.invalidateQueries({ queryKey: ["students"] }); | ||||
|         }, | ||||
|  | @ -103,7 +103,7 @@ export function useDeleteStudentMutation() { | |||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: (username: string) => studentController.deleteStudent(username), | ||||
|         mutationFn: async (username: string) => studentController.deleteStudent(username), | ||||
|         onSuccess: () => { | ||||
|             await queryClient.invalidateQueries({ queryKey: ["students"] }); | ||||
|         }, | ||||
|  | @ -116,7 +116,7 @@ export function useDeleteStudentMutation() { | |||
| export function useStudentJoinRequestsQuery(username: MaybeRefOrGetter<string | undefined>) { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => STUDENT_JOIN_REQUESTS_QUERY_KEY(toValue(username)!)), | ||||
|         queryFn: () => studentController.getJoinRequests(toValue(username)!), | ||||
|         queryFn: async () => studentController.getJoinRequests(toValue(username)!), | ||||
|         enabled: () => Boolean(toValue(username)), | ||||
|     }); | ||||
| } | ||||
|  | @ -127,7 +127,7 @@ export function useStudentJoinRequestQuery( | |||
| ) { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => STUDENT_JOIN_REQUESTS_QUERY_KEY(toValue(username)!)), | ||||
|         queryFn: () => studentController.getJoinRequest(toValue(username)!, toValue(classId)!), | ||||
|         queryFn: async () => studentController.getJoinRequest(toValue(username)!, toValue(classId)!), | ||||
|         enabled: () => Boolean(toValue(username)), | ||||
|     }); | ||||
| } | ||||
|  | @ -139,7 +139,7 @@ export function useCreateJoinRequestMutation() { | |||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: ({ username, classId }: { username: string; classId: string }) => | ||||
|         mutationFn: async ({ username, classId }: { username: string; classId: string }) => | ||||
|             studentController.createJoinRequest(username, classId), | ||||
|         onSuccess: (_, { username }) => { | ||||
|             await queryClient.invalidateQueries({ queryKey: STUDENT_JOIN_REQUESTS_QUERY_KEY(username) }); | ||||
|  | @ -157,7 +157,7 @@ export function useDeleteJoinRequestMutation() { | |||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: ({ username, classId }: { username: string; classId: string }) => | ||||
|         mutationFn: async ({ username, classId }: { username: string; classId: string }) => | ||||
|             studentController.deleteJoinRequest(username, classId), | ||||
|         onSuccess: (_, { username }) => { | ||||
|             await queryClient.invalidateQueries({ queryKey: STUDENT_JOIN_REQUESTS_QUERY_KEY(username) }); | ||||
|  |  | |||
|  | @ -16,14 +16,14 @@ const JOIN_REQUESTS_QUERY_KEY = (username: string, classId: string) => ["join-re | |||
| export function useTeachersQuery(full: MaybeRefOrGetter<boolean> = false) { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => TEACHERS_QUERY_KEY(toValue(full))), | ||||
|         queryFn: () => teacherController.getAll(toValue(full)), | ||||
|         queryFn: async () => teacherController.getAll(toValue(full)), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useTeacherQuery(username: MaybeRefOrGetter<string | undefined>) { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => TEACHER_QUERY_KEY(toValue(username)!)), | ||||
|         queryFn: () => teacherController.getByUsername(toValue(username)!), | ||||
|         queryFn: async () => teacherController.getByUsername(toValue(username)!), | ||||
|         enabled: () => Boolean(toValue(username)), | ||||
|     }); | ||||
| } | ||||
|  | @ -34,7 +34,7 @@ export function useTeacherClassesQuery( | |||
| ) { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => TEACHER_CLASSES_QUERY_KEY(toValue(username)!, toValue(full))), | ||||
|         queryFn: () => teacherController.getClasses(toValue(username)!, toValue(full)), | ||||
|         queryFn: async () => teacherController.getClasses(toValue(username)!, toValue(full)), | ||||
|         enabled: () => Boolean(toValue(username)), | ||||
|     }); | ||||
| } | ||||
|  | @ -45,7 +45,7 @@ export function useTeacherStudentsQuery( | |||
| ) { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => TEACHER_STUDENTS_QUERY_KEY(toValue(username)!, toValue(full))), | ||||
|         queryFn: () => teacherController.getStudents(toValue(username)!, toValue(full)), | ||||
|         queryFn: async () => teacherController.getStudents(toValue(username)!, toValue(full)), | ||||
|         enabled: () => Boolean(toValue(username)), | ||||
|     }); | ||||
| } | ||||
|  | @ -56,7 +56,7 @@ export function useTeacherQuestionsQuery( | |||
| ) { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => TEACHER_QUESTIONS_QUERY_KEY(toValue(username)!, toValue(full))), | ||||
|         queryFn: () => teacherController.getQuestions(toValue(username)!, toValue(full)), | ||||
|         queryFn: async () => teacherController.getQuestions(toValue(username)!, toValue(full)), | ||||
|         enabled: () => Boolean(toValue(username)), | ||||
|     }); | ||||
| } | ||||
|  | @ -67,7 +67,7 @@ export function useTeacherJoinRequestsQuery( | |||
| ) { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => JOIN_REQUESTS_QUERY_KEY(toValue(username)!, toValue(classId)!)), | ||||
|         queryFn: () => teacherController.getStudentJoinRequests(toValue(username)!, toValue(classId)!), | ||||
|         queryFn: async () => teacherController.getStudentJoinRequests(toValue(username)!, toValue(classId)!), | ||||
|         enabled: () => Boolean(toValue(username)) && Boolean(toValue(classId)), | ||||
|     }); | ||||
| } | ||||
|  | @ -76,7 +76,7 @@ export function useCreateTeacherMutation() { | |||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: (data: any) => teacherController.createTeacher(data), | ||||
|         mutationFn: async (data: any) => teacherController.createTeacher(data), | ||||
|         onSuccess: () => { | ||||
|             await queryClient.invalidateQueries({ queryKey: ["teachers"] }); | ||||
|         }, | ||||
|  | @ -90,7 +90,7 @@ export function useDeleteTeacherMutation() { | |||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: (username: string) => teacherController.deleteTeacher(username), | ||||
|         mutationFn: async (username: string) => teacherController.deleteTeacher(username), | ||||
|         onSuccess: () => { | ||||
|             await queryClient.invalidateQueries({ queryKey: ["teachers"] }); | ||||
|         }, | ||||
|  | @ -104,7 +104,7 @@ export function useUpdateJoinRequestMutation() { | |||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: ({ | ||||
|         mutationFn: async ({ | ||||
|             teacherUsername, | ||||
|             classId, | ||||
|             studentUsername, | ||||
|  |  | |||
|  | @ -7,7 +7,7 @@ const themeController = new ThemeController(); | |||
| export function useThemeQuery(language: MaybeRefOrGetter<string | undefined>) { | ||||
|     return useQuery({ | ||||
|         queryKey: ["themes", language], | ||||
|         queryFn: () => { | ||||
|         queryFn: async () => { | ||||
|             const lang = toValue(language); | ||||
|             return themeController.getAll(lang); | ||||
|         }, | ||||
|  | @ -18,7 +18,7 @@ export function useThemeQuery(language: MaybeRefOrGetter<string | undefined>) { | |||
| export function useThemeHruidsQuery(themeKey: MaybeRefOrGetter<string | undefined>) { | ||||
|     return useQuery({ | ||||
|         queryKey: ["theme-hruids", themeKey], | ||||
|         queryFn: () => themeController.getHruidsByKey(toValue(themeKey)!), | ||||
|         queryFn: async () => themeController.getHruidsByKey(toValue(themeKey)!), | ||||
|         enabled: Boolean(themeKey), | ||||
|     }); | ||||
| } | ||||
|  |  | |||
|  | @ -120,6 +120,6 @@ | |||
|         // "skipDefaultLibCheck": true,                      /* Skip type checking .d.ts files that are included with TypeScript. */ | ||||
|         "skipLibCheck": true, | ||||
|         /* Skip type checking all .d.ts files. */ | ||||
|         "resolveJsonModule": true | ||||
|         "resolveJsonModule": true, | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Reference in a new issue
	
	 Gabriellvl
						Gabriellvl