style: fix linting issues met Prettier
This commit is contained in:
		
							parent
							
								
									ba725f67b2
								
							
						
					
					
						commit
						8a55c0f003
					
				
					 22 changed files with 137 additions and 157 deletions
				
			
		|  | @ -5,13 +5,13 @@ import { | |||
|     getAllQuestions, | ||||
|     getAnswersByQuestion, | ||||
|     getQuestion, | ||||
|     getQuestionsAboutLearningObjectInAssignment | ||||
|     getQuestionsAboutLearningObjectInAssignment, | ||||
| } from '../services/questions.js'; | ||||
| import { FALLBACK_LANG, FALLBACK_SEQ_NUM } from '../config.js'; | ||||
| import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; | ||||
| import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | ||||
| import { Language } from '@dwengo-1/common/util/language'; | ||||
| import {AnswerDTO, AnswerId} from "@dwengo-1/common/interfaces/answer"; | ||||
| import { AnswerDTO, AnswerId } from '@dwengo-1/common/interfaces/answer'; | ||||
| 
 | ||||
| interface QuestionPathParams { | ||||
|     hruid: string; | ||||
|  | @ -62,10 +62,10 @@ function getQuestionId<ReqBody, ResBody>( | |||
| } | ||||
| 
 | ||||
| interface GetAllQuestionsQueryParams extends QuestionQueryParams { | ||||
|     classId?: string, | ||||
|     assignmentId?: number, | ||||
|     forStudent?: string, | ||||
|     full?: boolean | ||||
|     classId?: string; | ||||
|     assignmentId?: number; | ||||
|     forStudent?: string; | ||||
|     full?: boolean; | ||||
| } | ||||
| 
 | ||||
| export async function getAllQuestionsHandler( | ||||
|  | @ -118,10 +118,10 @@ export async function getQuestionHandler( | |||
| } | ||||
| 
 | ||||
| interface GetQuestionAnswersQueryParams extends QuestionQueryParams { | ||||
|     full: boolean | ||||
|     full: boolean; | ||||
| } | ||||
| export async function getQuestionAnswersHandler( | ||||
|     req: Request<GetQuestionIdPathParams, {answers: AnswerDTO[] | AnswerId[]}, unknown, GetQuestionAnswersQueryParams>, | ||||
|     req: Request<GetQuestionIdPathParams, { answers: AnswerDTO[] | AnswerId[] }, unknown, GetQuestionAnswersQueryParams>, | ||||
|     res: Response | ||||
| ): Promise<void> { | ||||
|     const questionId = getQuestionId(req, res); | ||||
|  |  | |||
|  | @ -1,13 +1,8 @@ | |||
| import { Request, Response } from 'express'; | ||||
| import { | ||||
|     createSubmission, | ||||
|     deleteSubmission, | ||||
|     getSubmission, | ||||
|     getSubmissionsForLearningObjectAndAssignment | ||||
| } from '../services/submissions.js'; | ||||
| import { createSubmission, deleteSubmission, getSubmission, getSubmissionsForLearningObjectAndAssignment } from '../services/submissions.js'; | ||||
| import { SubmissionDTO } from '@dwengo-1/common/interfaces/submission'; | ||||
| import { Language, languageMap } from '@dwengo-1/common/util/language'; | ||||
| import {Submission} from "../entities/assignments/submission.entity"; | ||||
| import { Submission } from '../entities/assignments/submission.entity'; | ||||
| 
 | ||||
| interface SubmissionParams { | ||||
|     hruid: string; | ||||
|  | @ -15,27 +10,22 @@ interface SubmissionParams { | |||
| } | ||||
| 
 | ||||
| interface SubmissionQuery { | ||||
|     language: string, | ||||
|     language: string; | ||||
|     version: number; | ||||
| } | ||||
| 
 | ||||
| interface SubmissionsQuery extends SubmissionQuery { | ||||
|     classId: string, | ||||
|     assignmentId: number, | ||||
|     studentUsername?: string | ||||
|     classId: string; | ||||
|     assignmentId: number; | ||||
|     studentUsername?: string; | ||||
| } | ||||
| 
 | ||||
| export async function getSubmissionsHandler( | ||||
|     req: Request<SubmissionParams, Submission[], null, SubmissionsQuery>, | ||||
|     res: Response | ||||
| ): Promise<void> { | ||||
| export async function getSubmissionsHandler(req: Request<SubmissionParams, Submission[], null, SubmissionsQuery>, res: Response): Promise<void> { | ||||
|     const loHruid = req.params.hruid; | ||||
|     const lang = languageMap[req.query.language] || Language.Dutch; | ||||
|     const version = (req.query.version || 1); | ||||
|     const version = req.query.version || 1; | ||||
| 
 | ||||
|     const submissions = await getSubmissionsForLearningObjectAndAssignment( | ||||
|         loHruid, lang, version, req.query.classId, req.query.assignmentId | ||||
|     ); | ||||
|     const submissions = await getSubmissionsForLearningObjectAndAssignment(loHruid, lang, version, req.query.classId, req.query.assignmentId); | ||||
| 
 | ||||
|     res.json(submissions); | ||||
| } | ||||
|  |  | |||
|  | @ -15,11 +15,11 @@ export class AssignmentRepository extends DwengoEntityRepository<Assignment> { | |||
|                 within: { | ||||
|                     teachers: { | ||||
|                         $some: { | ||||
|                             username: teacherUsername | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|                             username: teacherUsername, | ||||
|                         }, | ||||
|                     }, | ||||
|                 }, | ||||
|             }, | ||||
|         }); | ||||
|     } | ||||
|     public async findAllAssignmentsInClass(within: Class): Promise<Assignment[]> { | ||||
|  |  | |||
|  | @ -3,7 +3,7 @@ import { Group } from '../../entities/assignments/group.entity.js'; | |||
| import { Submission } from '../../entities/assignments/submission.entity.js'; | ||||
| import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js'; | ||||
| import { Student } from '../../entities/users/student.entity.js'; | ||||
| import {Assignment} from "../../entities/assignments/assignment.entity"; | ||||
| import { Assignment } from '../../entities/assignments/assignment.entity'; | ||||
| 
 | ||||
| export class SubmissionRepository extends DwengoEntityRepository<Submission> { | ||||
|     public async findSubmissionByLearningObjectAndSubmissionNumber( | ||||
|  | @ -46,7 +46,7 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> { | |||
|         return this.find( | ||||
|             { onBehalfOf: group }, | ||||
|             { | ||||
|                 populate: ["onBehalfOf.members"] | ||||
|                 populate: ['onBehalfOf.members'], | ||||
|             } | ||||
|         ); | ||||
|     } | ||||
|  | @ -60,24 +60,26 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> { | |||
|         assignment: Assignment, | ||||
|         forStudentUsername?: string | ||||
|     ): Promise<Submission[]> { | ||||
|         const onBehalfOf = forStudentUsername ? { | ||||
|             assignment, | ||||
|             members: { | ||||
|                 $some: { | ||||
|                     username: forStudentUsername | ||||
|                 } | ||||
|             } | ||||
|         } : { | ||||
|             assignment | ||||
|         }; | ||||
|         const onBehalfOf = forStudentUsername | ||||
|             ? { | ||||
|                   assignment, | ||||
|                   members: { | ||||
|                       $some: { | ||||
|                           username: forStudentUsername, | ||||
|                       }, | ||||
|                   }, | ||||
|               } | ||||
|             : { | ||||
|                   assignment, | ||||
|               }; | ||||
| 
 | ||||
|         return this.findAll({ | ||||
|             where: { | ||||
|                 learningObjectHruid: loId.hruid, | ||||
|                 learningObjectLanguage: loId.language, | ||||
|                 learningObjectVersion: loId.version, | ||||
|                 onBehalfOf | ||||
|             } | ||||
|                 onBehalfOf, | ||||
|             }, | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|  | @ -85,9 +87,7 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> { | |||
|         const result = await this.find( | ||||
|             { submitter: student }, | ||||
|             { | ||||
|                 populate: [ | ||||
|                     "onBehalfOf.members" | ||||
|                 ] | ||||
|                 populate: ['onBehalfOf.members'], | ||||
|             } | ||||
|         ); | ||||
| 
 | ||||
|  |  | |||
|  | @ -3,11 +3,11 @@ import { Question } from '../../entities/questions/question.entity.js'; | |||
| import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js'; | ||||
| import { Student } from '../../entities/users/student.entity.js'; | ||||
| import { LearningObject } from '../../entities/content/learning-object.entity.js'; | ||||
| import {Group} from "../../entities/assignments/group.entity"; | ||||
| import {Assignment} from "../../entities/assignments/assignment.entity"; | ||||
| import { Group } from '../../entities/assignments/group.entity'; | ||||
| import { Assignment } from '../../entities/assignments/assignment.entity'; | ||||
| 
 | ||||
| export class QuestionRepository extends DwengoEntityRepository<Question> { | ||||
|     public async createQuestion(question: { loId: LearningObjectIdentifier; author: Student; inGroup: Group, content: string }): Promise<Question> { | ||||
|     public async createQuestion(question: { loId: LearningObjectIdentifier; author: Student; inGroup: Group; content: string }): Promise<Question> { | ||||
|         const questionEntity = this.create({ | ||||
|             learningObjectHruid: question.loId.hruid, | ||||
|             learningObjectLanguage: question.loId.language, | ||||
|  | @ -75,24 +75,26 @@ export class QuestionRepository extends DwengoEntityRepository<Question> { | |||
|         assignment: Assignment, | ||||
|         forStudentUsername?: string | ||||
|     ): Promise<Question[]> { | ||||
|         const inGroup = forStudentUsername ? { | ||||
|             assignment, | ||||
|             members: { | ||||
|                 $some: { | ||||
|                     username: forStudentUsername | ||||
|                 } | ||||
|             } | ||||
|         } : { | ||||
|             assignment | ||||
|         }; | ||||
|         const inGroup = forStudentUsername | ||||
|             ? { | ||||
|                   assignment, | ||||
|                   members: { | ||||
|                       $some: { | ||||
|                           username: forStudentUsername, | ||||
|                       }, | ||||
|                   }, | ||||
|               } | ||||
|             : { | ||||
|                   assignment, | ||||
|               }; | ||||
| 
 | ||||
|         return this.findAll({ | ||||
|             where: { | ||||
|                 learningObjectHruid: loId.hruid, | ||||
|                 learningObjectLanguage: loId.language, | ||||
|                 learningObjectVersion: loId.version, | ||||
|                 inGroup | ||||
|             } | ||||
|                 inGroup, | ||||
|             }, | ||||
|         }); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| import {Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property} from '@mikro-orm/core'; | ||||
| import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'; | ||||
| import { Class } from '../classes/class.entity.js'; | ||||
| import { Group } from './group.entity.js'; | ||||
| import { Language } from '@dwengo-1/common/util/language'; | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| import {Collection, Entity, ManyToMany, ManyToOne, PrimaryKey} from '@mikro-orm/core'; | ||||
| import { Collection, Entity, ManyToMany, ManyToOne, PrimaryKey } from '@mikro-orm/core'; | ||||
| import { Assignment } from './assignment.entity.js'; | ||||
| import { Student } from '../users/student.entity.js'; | ||||
| import { GroupRepository } from '../../data/assignments/group-repository.js'; | ||||
|  |  | |||
|  | @ -22,7 +22,7 @@ export class Submission { | |||
|     submissionNumber?: number; | ||||
| 
 | ||||
|     @ManyToOne({ | ||||
|         entity: () => Group | ||||
|         entity: () => Group, | ||||
|     }) | ||||
|     onBehalfOf!: Group; | ||||
| 
 | ||||
|  | @ -34,8 +34,6 @@ export class Submission { | |||
|     @Property({ type: 'datetime' }) | ||||
|     submissionTime!: Date; | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     @Property({ type: 'json' }) | ||||
|     content!: string; | ||||
| } | ||||
|  |  | |||
|  | @ -2,7 +2,7 @@ import { Entity, Enum, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'; | |||
| import { Student } from '../users/student.entity.js'; | ||||
| import { QuestionRepository } from '../../data/questions/question-repository.js'; | ||||
| import { Language } from '@dwengo-1/common/util/language'; | ||||
| import {Group} from "../assignments/group.entity"; | ||||
| import { Group } from '../assignments/group.entity'; | ||||
| 
 | ||||
| @Entity({ repository: () => QuestionRepository }) | ||||
| export class Question { | ||||
|  |  | |||
|  | @ -1,11 +1,11 @@ | |||
| import { Group } from '../entities/assignments/group.entity.js'; | ||||
| import {mapToAssignment, mapToAssignmentDTO, mapToAssignmentDTOId} from './assignment.js'; | ||||
| import {mapToStudent, mapToStudentDTO} from './student.js'; | ||||
| import {GroupDTO} from '@dwengo-1/common/interfaces/group'; | ||||
| import {getGroupRepository} from "../data/repositories"; | ||||
| import {AssignmentDTO} from "@dwengo-1/common/interfaces/assignment"; | ||||
| import {Class} from "../entities/classes/class.entity"; | ||||
| import {StudentDTO} from "@dwengo-1/common/interfaces/student"; | ||||
| import { mapToAssignment, mapToAssignmentDTO, mapToAssignmentDTOId } from './assignment.js'; | ||||
| import { mapToStudent, mapToStudentDTO } from './student.js'; | ||||
| import { GroupDTO } from '@dwengo-1/common/interfaces/group'; | ||||
| import { getGroupRepository } from '../data/repositories'; | ||||
| import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment'; | ||||
| import { Class } from '../entities/classes/class.entity'; | ||||
| import { StudentDTO } from '@dwengo-1/common/interfaces/student'; | ||||
| 
 | ||||
| export function mapToGroup(groupDto: GroupDTO, clazz: Class): Group { | ||||
|     const assignmentDto = groupDto.assignment as AssignmentDTO; | ||||
|  | @ -13,7 +13,7 @@ export function mapToGroup(groupDto: GroupDTO, clazz: Class): Group { | |||
|     return getGroupRepository().create({ | ||||
|         groupNumber: groupDto.groupNumber, | ||||
|         assignment: mapToAssignment(assignmentDto, clazz), | ||||
|         members: groupDto.members!.map(studentDto => mapToStudent(studentDto as StudentDTO)) | ||||
|         members: groupDto.members!.map((studentDto) => mapToStudent(studentDto as StudentDTO)), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -2,7 +2,7 @@ import { Question } from '../entities/questions/question.entity.js'; | |||
| import { mapToStudentDTO } from './student.js'; | ||||
| import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | ||||
| import { LearningObjectIdentifier } from '@dwengo-1/common/interfaces/learning-content'; | ||||
| import { mapToGroupDTOId } from "./group"; | ||||
| import { mapToGroupDTOId } from './group'; | ||||
| 
 | ||||
| function getLearningObjectIdentifier(question: Question): LearningObjectIdentifier { | ||||
|     return { | ||||
|  |  | |||
|  | @ -1,10 +1,5 @@ | |||
| import express from 'express'; | ||||
| import { | ||||
|     createSubmissionHandler, | ||||
|     deleteSubmissionHandler, | ||||
|     getSubmissionHandler, | ||||
|     getSubmissionsHandler | ||||
| } from '../controllers/submissions.js'; | ||||
| import { createSubmissionHandler, deleteSubmissionHandler, getSubmissionHandler, getSubmissionsHandler } from '../controllers/submissions.js'; | ||||
| const router = express.Router({ mergeParams: true }); | ||||
| 
 | ||||
| // Root endpoint used to search objects
 | ||||
|  |  | |||
|  | @ -1,9 +1,4 @@ | |||
| import { | ||||
|     getAnswerRepository, getAssignmentRepository, | ||||
|     getClassRepository, | ||||
|     getGroupRepository, | ||||
|     getQuestionRepository | ||||
| } from '../data/repositories.js'; | ||||
| import { getAnswerRepository, getAssignmentRepository, getClassRepository, getGroupRepository, getQuestionRepository } from '../data/repositories.js'; | ||||
| import { mapToQuestionDTO, mapToQuestionDTOId } from '../interfaces/question.js'; | ||||
| import { Question } from '../entities/questions/question.entity.js'; | ||||
| import { Answer } from '../entities/questions/answer.entity.js'; | ||||
|  | @ -13,8 +8,8 @@ import { LearningObjectIdentifier } from '../entities/content/learning-object-id | |||
| import { mapToStudent } from '../interfaces/student.js'; | ||||
| import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | ||||
| import { AnswerDTO, AnswerId } from '@dwengo-1/common/interfaces/answer'; | ||||
| import { AssignmentDTO } from "@dwengo-1/common/interfaces/assignment"; | ||||
| import { mapToAssignment } from "../interfaces/assignment"; | ||||
| import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment'; | ||||
| import { mapToAssignment } from '../interfaces/assignment'; | ||||
| 
 | ||||
| export async function getQuestionsAboutLearningObjectInAssignment( | ||||
|     loId: LearningObjectIdentifier, | ||||
|  | @ -23,15 +18,14 @@ export async function getQuestionsAboutLearningObjectInAssignment( | |||
|     full: boolean, | ||||
|     studentUsername?: string | ||||
| ): Promise<QuestionDTO[] | QuestionId[]> { | ||||
|     const assignment = await getAssignmentRepository() | ||||
|         .findByClassIdAndAssignmentId(classId, assignmentId); | ||||
|     const assignment = await getAssignmentRepository().findByClassIdAndAssignmentId(classId, assignmentId); | ||||
| 
 | ||||
|     const questions = await getQuestionRepository() | ||||
|         .findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!, studentUsername); | ||||
|     const questions = await getQuestionRepository().findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!, studentUsername); | ||||
| 
 | ||||
|     if (full) | ||||
|         {return questions.map(q => mapToQuestionDTO(q));} | ||||
|     return questions.map(q => mapToQuestionDTOId(q)); | ||||
|     if (full) { | ||||
|         return questions.map((q) => mapToQuestionDTO(q)); | ||||
|     } | ||||
|     return questions.map((q) => mapToQuestionDTOId(q)); | ||||
| } | ||||
| 
 | ||||
| export async function getAllQuestions(id: LearningObjectIdentifier, full: boolean): Promise<QuestionDTO[] | QuestionId[]> { | ||||
|  | @ -101,7 +95,7 @@ export async function createQuestion(questionDTO: QuestionDTO): Promise<Question | |||
|         version: questionDTO.learningObjectIdentifier.version ?? 1, | ||||
|     }; | ||||
| 
 | ||||
|     const clazz = await getClassRepository().findById((questionDTO.inGroup.assignment as AssignmentDTO).class) | ||||
|     const clazz = await getClassRepository().findById((questionDTO.inGroup.assignment as AssignmentDTO).class); | ||||
|     const assignment = mapToAssignment(questionDTO.inGroup.assignment as AssignmentDTO, clazz!); | ||||
|     const inGroup = await getGroupRepository().findByAssignmentAndGroupNumber(assignment, questionDTO.inGroup.groupNumber); | ||||
| 
 | ||||
|  |  | |||
|  | @ -23,7 +23,7 @@ import { GroupDTO } from '@dwengo-1/common/interfaces/group'; | |||
| import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission'; | ||||
| import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | ||||
| import { ClassJoinRequestDTO } from '@dwengo-1/common/interfaces/class-join-request'; | ||||
| import {Submission} from "../entities/assignments/submission.entity"; | ||||
| import { Submission } from '../entities/assignments/submission.entity'; | ||||
| 
 | ||||
| export async function getAllStudents(full: boolean): Promise<StudentDTO[] | string[]> { | ||||
|     const studentRepository = getStudentRepository(); | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| import {getAssignmentRepository, getSubmissionRepository} from '../data/repositories.js'; | ||||
| import { getAssignmentRepository, getSubmissionRepository } from '../data/repositories.js'; | ||||
| import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; | ||||
| import { mapToSubmission, mapToSubmissionDTO } from '../interfaces/submission.js'; | ||||
| import { SubmissionDTO } from '@dwengo-1/common/interfaces/submission'; | ||||
|  | @ -68,11 +68,9 @@ export async function getSubmissionsForLearningObjectAndAssignment( | |||
|     studentUsername?: string | ||||
| ): Promise<SubmissionDTO[]> { | ||||
|     const loId = new LearningObjectIdentifier(learningObjectHruid, language, version); | ||||
|     const assignment = await getAssignmentRepository() | ||||
|                                                 .findByClassIdAndAssignmentId(classId, assignmentId); | ||||
|     const assignment = await getAssignmentRepository().findByClassIdAndAssignmentId(classId, assignmentId); | ||||
| 
 | ||||
|     const submissions = await getSubmissionRepository() | ||||
|                     .findAllSubmissionsForLearningObjectAndAssignment(loId, assignment!, studentUsername); | ||||
|     const submissions = await getSubmissionRepository().findAllSubmissionsForLearningObjectAndAssignment(loId, assignment!, studentUsername); | ||||
| 
 | ||||
|     return submissions.map(s => mapToSubmissionDTO(s)); | ||||
|     return submissions.map((s) => mapToSubmissionDTO(s)); | ||||
| } | ||||
|  |  | |||
		Reference in a new issue
	
	 Lint Action
						Lint Action