fix: merge + lint fixes
This commit is contained in:
		
							parent
							
								
									7f189188e8
								
							
						
					
					
						commit
						b556516359
					
				
					 12 changed files with 58 additions and 62 deletions
				
			
		|  | @ -33,7 +33,7 @@ export async function getStudentHandler(req: Request, res: Response): Promise<vo | |||
|     res.json({ student }); | ||||
| } | ||||
| 
 | ||||
| export async function createStudentHandler(req: Request, res: Response) { | ||||
| export async function createStudentHandler(req: Request, res: Response): Promise<void> { | ||||
|     const username = req.body.username; | ||||
|     const firstName = req.body.firstName; | ||||
|     const lastName = req.body.lastName; | ||||
|  | @ -45,7 +45,7 @@ export async function createStudentHandler(req: Request, res: Response) { | |||
|     res.json({ student }); | ||||
| } | ||||
| 
 | ||||
| export async function deleteStudentHandler(req: Request, res: Response) { | ||||
| export async function deleteStudentHandler(req: Request, res: Response): Promise<void> { | ||||
|     const username = req.params.username; | ||||
|     requireFields({ username }); | ||||
| 
 | ||||
|  | @ -125,7 +125,7 @@ export async function getStudentRequestsHandler(req: Request, res: Response): Pr | |||
| } | ||||
| 
 | ||||
| export async function getStudentRequestHandler(req: Request, res: Response): Promise<void> { | ||||
|     const username = req.params.username as string; | ||||
|     const username = req.params.username; | ||||
|     const classId = req.params.classId; | ||||
|     requireFields({ username, classId }); | ||||
| 
 | ||||
|  | @ -133,8 +133,8 @@ export async function getStudentRequestHandler(req: Request, res: Response): Pro | |||
|     res.json({ request }); | ||||
| } | ||||
| 
 | ||||
| export async function deleteClassJoinRequestHandler(req: Request, res: Response) { | ||||
|     const username = req.params.username as string; | ||||
| export async function deleteClassJoinRequestHandler(req: Request, res: Response): Promise<void> { | ||||
|     const username = req.params.username; | ||||
|     const classId = req.params.classId; | ||||
|     requireFields({ username, classId }); | ||||
| 
 | ||||
|  |  | |||
|  | @ -33,7 +33,7 @@ export async function getTeacherHandler(req: Request, res: Response): Promise<vo | |||
|     res.json({ teacher }); | ||||
| } | ||||
| 
 | ||||
| export async function createTeacherHandler(req: Request, res: Response) { | ||||
| export async function createTeacherHandler(req: Request, res: Response): Promise<void> { | ||||
|     const username = req.body.username; | ||||
|     const firstName = req.body.firstName; | ||||
|     const lastName = req.body.lastName; | ||||
|  | @ -45,7 +45,7 @@ export async function createTeacherHandler(req: Request, res: Response) { | |||
|     res.json({ teacher }); | ||||
| } | ||||
| 
 | ||||
| export async function deleteTeacherHandler(req: Request, res: Response) { | ||||
| export async function deleteTeacherHandler(req: Request, res: Response): Promise<void> { | ||||
|     const username = req.params.username; | ||||
|     requireFields({ username }); | ||||
| 
 | ||||
|  | @ -54,7 +54,7 @@ export async function deleteTeacherHandler(req: Request, res: Response) { | |||
| } | ||||
| 
 | ||||
| export async function getTeacherClassHandler(req: Request, res: Response): Promise<void> { | ||||
|     const username = req.params.username as string; | ||||
|     const username = req.params.username; | ||||
|     const full = req.query.full === 'true'; | ||||
|     requireFields({ username }); | ||||
| 
 | ||||
|  | @ -64,7 +64,7 @@ export async function getTeacherClassHandler(req: Request, res: Response): Promi | |||
| } | ||||
| 
 | ||||
| export async function getTeacherStudentHandler(req: Request, res: Response): Promise<void> { | ||||
|     const username = req.params.username as string; | ||||
|     const username = req.params.username; | ||||
|     const full = req.query.full === 'true'; | ||||
|     requireFields({ username }); | ||||
| 
 | ||||
|  | @ -74,7 +74,7 @@ export async function getTeacherStudentHandler(req: Request, res: Response): Pro | |||
| } | ||||
| 
 | ||||
| export async function getTeacherQuestionHandler(req: Request, res: Response): Promise<void> { | ||||
|     const username = req.params.username as string; | ||||
|     const username = req.params.username; | ||||
|     const full = req.query.full === 'true'; | ||||
|     requireFields({ username }); | ||||
| 
 | ||||
|  | @ -83,7 +83,7 @@ export async function getTeacherQuestionHandler(req: Request, res: Response): Pr | |||
|     res.json({ questions }); | ||||
| } | ||||
| 
 | ||||
| export async function getStudentJoinRequestHandler(req: Request, res: Response) { | ||||
| export async function getStudentJoinRequestHandler(req: Request, res: Response): Promise<void> { | ||||
|     const username = req.query.username as string; | ||||
|     const classId = req.params.classId; | ||||
|     requireFields({ username, classId }); | ||||
|  | @ -92,7 +92,7 @@ export async function getStudentJoinRequestHandler(req: Request, res: Response) | |||
|     res.json({ joinRequests }); | ||||
| } | ||||
| 
 | ||||
| export async function updateStudentJoinRequestHandler(req: Request, res: Response) { | ||||
| export async function updateStudentJoinRequestHandler(req: Request, res: Response): Promise<void> { | ||||
|     const studentUsername = req.query.studentUsername as string; | ||||
|     const classId = req.params.classId; | ||||
|     const accepted = req.body.accepted !== 'false'; // Default = true
 | ||||
|  |  | |||
|  | @ -55,7 +55,7 @@ export class QuestionRepository extends DwengoEntityRepository<Question> { | |||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     public findAllByAuthor(author: Student): Promise<Question[]> { | ||||
|     public async findAllByAuthor(author: Student): Promise<Question[]> { | ||||
|         return this.findAll({ | ||||
|             where: { author }, | ||||
|             orderBy: { timestamp: 'DESC' }, // New to old
 | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| import { mapToUserDTO, UserDTO } from './user.js'; | ||||
| import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from './question.js'; | ||||
| import {mapToQuestionDTO, mapToQuestionDTOId, QuestionDTO, QuestionId} from './question.js'; | ||||
| import { Answer } from '../entities/questions/answer.entity.js'; | ||||
| 
 | ||||
| export interface AnswerDTO { | ||||
|  | @ -29,10 +29,10 @@ export interface AnswerId { | |||
|     sequenceNumber: number; | ||||
| } | ||||
| 
 | ||||
| export function mapToAnswerId(answer: AnswerDTO): AnswerId { | ||||
| export function mapToAnswerDTOId(answer: Answer): AnswerId { | ||||
|     return { | ||||
|         author: answer.author.username, | ||||
|         toQuestion: mapToQuestionId(answer.toQuestion), | ||||
|         sequenceNumber: answer.sequenceNumber, | ||||
|         toQuestion: mapToQuestionDTOId(answer.toQuestion), | ||||
|         sequenceNumber: answer.sequenceNumber!, | ||||
|     }; | ||||
| } | ||||
|  |  | |||
|  | @ -18,7 +18,7 @@ export function mapToStudentRequestDTO(request: ClassJoinRequest): StudentReques | |||
|     }; | ||||
| } | ||||
| 
 | ||||
| export function mapToStudentRequest(student: Student, cls: Class) { | ||||
| export function mapToStudentRequest(student: Student, cls: Class): ClassJoinRequest { | ||||
|     return getClassJoinRequestRepository().create({ | ||||
|         requester: student, | ||||
|         class: cls, | ||||
|  |  | |||
|  | @ -1,8 +1,8 @@ | |||
| import { getAnswerRepository, getQuestionRepository } from '../data/repositories.js'; | ||||
| import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js'; | ||||
| import {mapToQuestionDTO, mapToQuestionDTOId, QuestionDTO, QuestionId} from '../interfaces/question.js'; | ||||
| import { Question } from '../entities/questions/question.entity.js'; | ||||
| import { Answer } from '../entities/questions/answer.entity.js'; | ||||
| import { AnswerDTO, AnswerId, mapToAnswerDTO, mapToAnswerId } from '../interfaces/answer.js'; | ||||
| import { AnswerDTO, AnswerId, 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'; | ||||
|  | @ -15,13 +15,11 @@ export async function getAllQuestions(id: LearningObjectIdentifier, full: boolea | |||
|         return []; | ||||
|     } | ||||
| 
 | ||||
|     const questionsDTO: QuestionDTO[] = questions.map(mapToQuestionDTO); | ||||
| 
 | ||||
|     if (full) { | ||||
|         return questionsDTO; | ||||
|         return questions.map(mapToQuestionDTO); | ||||
|     } | ||||
| 
 | ||||
|     return questionsDTO.map(mapToQuestionId); | ||||
|     return questions.map(mapToQuestionDTOId); | ||||
| } | ||||
| 
 | ||||
| async function fetchQuestion(questionId: QuestionId): Promise<Question | null> { | ||||
|  | @ -59,13 +57,11 @@ export async function getAnswersByQuestion(questionId: QuestionId, full: boolean | |||
|         return []; | ||||
|     } | ||||
| 
 | ||||
|     const answersDTO = answers.map(mapToAnswerDTO); | ||||
| 
 | ||||
|     if (full) { | ||||
|         return answersDTO; | ||||
|         return answers.map(mapToAnswerDTO); | ||||
|     } | ||||
| 
 | ||||
|     return answersDTO.map(mapToAnswerId); | ||||
|     return answers.map(mapToAnswerDTOId); | ||||
| } | ||||
| 
 | ||||
| export async function createQuestion(questionDTO: QuestionDTO): Promise<QuestionDTO | null> { | ||||
|  |  | |||
|  | @ -12,8 +12,13 @@ import { GroupDTO, mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js | |||
| import { mapToStudent, mapToStudentDTO, StudentDTO } from '../interfaces/student.js'; | ||||
| import { mapToSubmissionDTO, mapToSubmissionDTOId, SubmissionDTO, SubmissionDTOId } from '../interfaces/submission.js'; | ||||
| import { getAllAssignments } from './assignments.js'; | ||||
| import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js'; | ||||
| import { mapToStudentRequest, mapToStudentRequestDTO } from '../interfaces/student-request.js'; | ||||
| import { | ||||
|     mapToQuestionDTO, | ||||
|     mapToQuestionDTOId, | ||||
|     QuestionDTO, | ||||
|     QuestionId | ||||
| } from '../interfaces/question.js'; | ||||
| import {mapToStudentRequest, mapToStudentRequestDTO, StudentRequestDTO} from '../interfaces/student-request.js'; | ||||
| import { Student } from '../entities/users/student.entity.js'; | ||||
| import { NotFoundException } from '../exceptions/not-found-exception.js'; | ||||
| import { fetchClass } from './classes.js'; | ||||
|  | @ -116,16 +121,14 @@ export async function getStudentQuestions(username: string, full: boolean): Prom | |||
|     const questionRepository = getQuestionRepository(); | ||||
|     const questions = await questionRepository.findAllByAuthor(student); | ||||
| 
 | ||||
|     const questionsDTO = questions.map(mapToQuestionDTO); | ||||
| 
 | ||||
|     if (full) { | ||||
|         return questionsDTO; | ||||
|         return questions.map(mapToQuestionDTO); | ||||
|     } | ||||
| 
 | ||||
|     return questionsDTO.map(mapToQuestionId); | ||||
|     return questions.map(mapToQuestionDTOId); | ||||
| } | ||||
| 
 | ||||
| export async function createClassJoinRequest(username: string, classId: string) { | ||||
| export async function createClassJoinRequest(username: string, classId: string): Promise<StudentRequestDTO> { | ||||
|     const requestRepo = getClassJoinRequestRepository(); | ||||
| 
 | ||||
|     const student = await fetchStudent(username); // Throws error if student not found
 | ||||
|  | @ -136,7 +139,7 @@ export async function createClassJoinRequest(username: string, classId: string) | |||
|     return mapToStudentRequestDTO(request); | ||||
| } | ||||
| 
 | ||||
| export async function getJoinRequestsByStudent(username: string) { | ||||
| export async function getJoinRequestsByStudent(username: string): Promise<StudentRequestDTO[]> { | ||||
|     const requestRepo = getClassJoinRequestRepository(); | ||||
| 
 | ||||
|     const student = await fetchStudent(username); | ||||
|  | @ -145,7 +148,7 @@ export async function getJoinRequestsByStudent(username: string) { | |||
|     return requests.map(mapToStudentRequestDTO); | ||||
| } | ||||
| 
 | ||||
| export async function getJoinRequestByStudentClass(username: string, classId: string){ | ||||
| export async function getJoinRequestByStudentClass(username: string, classId: string): Promise<StudentRequestDTO>{ | ||||
|     const requestRepo = getClassJoinRequestRepository(); | ||||
| 
 | ||||
|     const student = await fetchStudent(username); | ||||
|  | @ -159,7 +162,7 @@ export async function getJoinRequestByStudentClass(username: string, classId: st | |||
|     return mapToStudentRequestDTO(request); | ||||
| } | ||||
| 
 | ||||
| export async function deleteClassJoinRequest(username: string, classId: string) { | ||||
| export async function deleteClassJoinRequest(username: string, classId: string): Promise<StudentRequestDTO> { | ||||
|     const requestRepo = getClassJoinRequestRepository(); | ||||
| 
 | ||||
|     const student = await fetchStudent(username); | ||||
|  |  | |||
|  | @ -90,7 +90,7 @@ export async function getClassesByTeacher(username: string, full: boolean): Prom | |||
|     return classes.map((cls) => cls.id); | ||||
| } | ||||
| 
 | ||||
| export async function getStudentsByTeacher(username: string, full: boolean) { | ||||
| export async function getStudentsByTeacher(username: string, full: boolean): Promise<StudentDTO[] | string[]> { | ||||
|     const classes: ClassDTO[] = await fetchClassesByTeacher(username); | ||||
| 
 | ||||
|     if (!classes || classes.length === 0) { | ||||
|  | @ -141,7 +141,7 @@ export async function getJoinRequestsByClass(classId: string): Promise<StudentRe | |||
|     return requests.map(mapToStudentRequestDTO); | ||||
| } | ||||
| 
 | ||||
| export async function updateClassJoinRequestStatus(studentUsername: string, classId: string, accepted: boolean = true): Promise<StudentRequestDTO> { | ||||
| export async function updateClassJoinRequestStatus(studentUsername: string, classId: string, accepted = true): Promise<StudentRequestDTO> { | ||||
|     const requestRepo: ClassJoinRequestRepository = getClassJoinRequestRepository(); | ||||
|     const classRepo: ClassRepository = getClassRepository(); | ||||
| 
 | ||||
|  |  | |||
		Reference in a new issue
	
	 Gabriellvl
						Gabriellvl