diff --git a/backend/src/controllers/questions.ts b/backend/src/controllers/questions.ts index f1426b38..26efb4f4 100644 --- a/backend/src/controllers/questions.ts +++ b/backend/src/controllers/questions.ts @@ -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( } 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, + req: Request, res: Response ): Promise { const questionId = getQuestionId(req, res); diff --git a/backend/src/controllers/submissions.ts b/backend/src/controllers/submissions.ts index ac6c3bb9..73f1317f 100644 --- a/backend/src/controllers/submissions.ts +++ b/backend/src/controllers/submissions.ts @@ -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, - res: Response -): Promise { +export async function getSubmissionsHandler(req: Request, res: Response): Promise { 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); } diff --git a/backend/src/data/assignments/assignment-repository.ts b/backend/src/data/assignments/assignment-repository.ts index c6766af9..db12a74f 100644 --- a/backend/src/data/assignments/assignment-repository.ts +++ b/backend/src/data/assignments/assignment-repository.ts @@ -15,11 +15,11 @@ export class AssignmentRepository extends DwengoEntityRepository { within: { teachers: { $some: { - username: teacherUsername - } - } - } - } + username: teacherUsername, + }, + }, + }, + }, }); } public async findAllAssignmentsInClass(within: Class): Promise { diff --git a/backend/src/data/assignments/submission-repository.ts b/backend/src/data/assignments/submission-repository.ts index a79dc417..c82ed9c3 100644 --- a/backend/src/data/assignments/submission-repository.ts +++ b/backend/src/data/assignments/submission-repository.ts @@ -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 { public async findSubmissionByLearningObjectAndSubmissionNumber( @@ -46,7 +46,7 @@ export class SubmissionRepository extends DwengoEntityRepository { return this.find( { onBehalfOf: group }, { - populate: ["onBehalfOf.members"] + populate: ['onBehalfOf.members'], } ); } @@ -60,24 +60,26 @@ export class SubmissionRepository extends DwengoEntityRepository { assignment: Assignment, forStudentUsername?: string ): Promise { - 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 { const result = await this.find( { submitter: student }, { - populate: [ - "onBehalfOf.members" - ] + populate: ['onBehalfOf.members'], } ); diff --git a/backend/src/data/questions/question-repository.ts b/backend/src/data/questions/question-repository.ts index 714c3818..6b961e07 100644 --- a/backend/src/data/questions/question-repository.ts +++ b/backend/src/data/questions/question-repository.ts @@ -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 { - public async createQuestion(question: { loId: LearningObjectIdentifier; author: Student; inGroup: Group, content: string }): Promise { + public async createQuestion(question: { loId: LearningObjectIdentifier; author: Student; inGroup: Group; content: string }): Promise { const questionEntity = this.create({ learningObjectHruid: question.loId.hruid, learningObjectLanguage: question.loId.language, @@ -75,24 +75,26 @@ export class QuestionRepository extends DwengoEntityRepository { assignment: Assignment, forStudentUsername?: string ): Promise { - 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, + }, }); } } diff --git a/backend/src/entities/assignments/assignment.entity.ts b/backend/src/entities/assignments/assignment.entity.ts index 52773909..e3f75489 100644 --- a/backend/src/entities/assignments/assignment.entity.ts +++ b/backend/src/entities/assignments/assignment.entity.ts @@ -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'; diff --git a/backend/src/entities/assignments/group.entity.ts b/backend/src/entities/assignments/group.entity.ts index 1a69ed4b..55770b7f 100644 --- a/backend/src/entities/assignments/group.entity.ts +++ b/backend/src/entities/assignments/group.entity.ts @@ -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'; diff --git a/backend/src/entities/assignments/submission.entity.ts b/backend/src/entities/assignments/submission.entity.ts index 728dd436..82d49a40 100644 --- a/backend/src/entities/assignments/submission.entity.ts +++ b/backend/src/entities/assignments/submission.entity.ts @@ -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; } diff --git a/backend/src/entities/questions/question.entity.ts b/backend/src/entities/questions/question.entity.ts index c6df4e6a..44ff3e32 100644 --- a/backend/src/entities/questions/question.entity.ts +++ b/backend/src/entities/questions/question.entity.ts @@ -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 { diff --git a/backend/src/interfaces/group.ts b/backend/src/interfaces/group.ts index d3785137..295c7e0f 100644 --- a/backend/src/interfaces/group.ts +++ b/backend/src/interfaces/group.ts @@ -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)), }); } diff --git a/backend/src/interfaces/question.ts b/backend/src/interfaces/question.ts index 5419618a..a9347047 100644 --- a/backend/src/interfaces/question.ts +++ b/backend/src/interfaces/question.ts @@ -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 { diff --git a/backend/src/routes/submissions.ts b/backend/src/routes/submissions.ts index 930e1a59..492b6439 100644 --- a/backend/src/routes/submissions.ts +++ b/backend/src/routes/submissions.ts @@ -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 diff --git a/backend/src/services/questions.ts b/backend/src/services/questions.ts index 5f5c22b7..aa3e1298 100644 --- a/backend/src/services/questions.ts +++ b/backend/src/services/questions.ts @@ -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 { - 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 { @@ -101,7 +95,7 @@ export async function createQuestion(questionDTO: QuestionDTO): Promise { const studentRepository = getStudentRepository(); diff --git a/backend/src/services/submissions.ts b/backend/src/services/submissions.ts index 08a19481..23659d63 100644 --- a/backend/src/services/submissions.ts +++ b/backend/src/services/submissions.ts @@ -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 { 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)); } diff --git a/backend/tests/controllers/students.test.ts b/backend/tests/controllers/students.test.ts index 35f9a9cf..93f35c48 100644 --- a/backend/tests/controllers/students.test.ts +++ b/backend/tests/controllers/students.test.ts @@ -147,7 +147,6 @@ describe('Student controllers', () => { const result = jsonMock.mock.lastCall?.[0]; expect(result.submissions).to.have.length.greaterThan(0); - }); it('Student questions', async () => { diff --git a/backend/tests/data/assignments/assignments.test.ts b/backend/tests/data/assignments/assignments.test.ts index aad084e3..2bad08f2 100644 --- a/backend/tests/data/assignments/assignments.test.ts +++ b/backend/tests/data/assignments/assignments.test.ts @@ -32,10 +32,8 @@ describe('AssignmentRepository', () => { }); it('should find all by username of the responsible teacher', async () => { - const result = await assignmentRepository.findAllByResponsibleTeacher("FooFighters") - const resultIds = result - .map(it => it.id) - .sort((a, b) => (a ?? 0) - (b ?? 0)); + const result = await assignmentRepository.findAllByResponsibleTeacher('FooFighters'); + const resultIds = result.map((it) => it.id).sort((a, b) => (a ?? 0) - (b ?? 0)); expect(resultIds).toEqual([1, 3, 4]); }); diff --git a/backend/tests/data/assignments/submissions.test.ts b/backend/tests/data/assignments/submissions.test.ts index c7920734..acc82384 100644 --- a/backend/tests/data/assignments/submissions.test.ts +++ b/backend/tests/data/assignments/submissions.test.ts @@ -1,6 +1,6 @@ -import {beforeAll, describe, expect, it} from 'vitest'; -import {setupTestApp} from '../../setup-tests'; -import {SubmissionRepository} from '../../../src/data/assignments/submission-repository'; +import { beforeAll, describe, expect, it } from 'vitest'; +import { setupTestApp } from '../../setup-tests'; +import { SubmissionRepository } from '../../../src/data/assignments/submission-repository'; import { getAssignmentRepository, getClassRepository, @@ -8,15 +8,15 @@ import { getStudentRepository, getSubmissionRepository, } from '../../../src/data/repositories'; -import {LearningObjectIdentifier} from '../../../src/entities/content/learning-object-identifier'; -import {Language} from '@dwengo-1/common/util/language'; -import {StudentRepository} from '../../../src/data/users/student-repository'; -import {GroupRepository} from '../../../src/data/assignments/group-repository'; -import {AssignmentRepository} from '../../../src/data/assignments/assignment-repository'; -import {ClassRepository} from '../../../src/data/classes/class-repository'; -import {Submission} from "../../../src/entities/assignments/submission.entity"; -import {Class} from "../../../src/entities/classes/class.entity"; -import {Assignment} from "../../../src/entities/assignments/assignment.entity"; +import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier'; +import { Language } from '@dwengo-1/common/util/language'; +import { StudentRepository } from '../../../src/data/users/student-repository'; +import { GroupRepository } from '../../../src/data/assignments/group-repository'; +import { AssignmentRepository } from '../../../src/data/assignments/assignment-repository'; +import { ClassRepository } from '../../../src/data/classes/class-repository'; +import { Submission } from '../../../src/entities/assignments/submission.entity'; +import { Class } from '../../../src/entities/classes/class.entity'; +import { Assignment } from '../../../src/entities/assignments/assignment.entity'; describe('SubmissionRepository', () => { let submissionRepository: SubmissionRepository; @@ -69,9 +69,9 @@ describe('SubmissionRepository', () => { clazz = await classRepository.findById('id01'); assignment = await assignmentRepository.findByClassAndId(clazz!, 1); loId = { - hruid: "id02", + hruid: 'id02', language: Language.English, - version: 1 + version: 1, }; const result = await submissionRepository.findAllSubmissionsForLearningObjectAndAssignment(loId, assignment!); sortSubmissions(result); @@ -92,8 +92,7 @@ describe('SubmissionRepository', () => { }); it("should find only the submissions for a certain learning object and assignment made for the user's group", async () => { - const result = - await submissionRepository.findAllSubmissionsForLearningObjectAndAssignment(loId, assignment!, "Tool"); + const result = await submissionRepository.findAllSubmissionsForLearningObjectAndAssignment(loId, assignment!, 'Tool'); // (student Tool is in group #2) expect(result).toHaveLength(1); @@ -118,8 +117,12 @@ describe('SubmissionRepository', () => { function sortSubmissions(submissions: Submission[]): void { submissions.sort((a, b) => { - if (a.learningObjectHruid < b.learningObjectHruid) {return -1;} - if (a.learningObjectHruid > b.learningObjectHruid) {return 1;} + if (a.learningObjectHruid < b.learningObjectHruid) { + return -1; + } + if (a.learningObjectHruid > b.learningObjectHruid) { + return 1; + } return a.submissionNumber! - b.submissionNumber!; }); } diff --git a/backend/tests/data/questions/questions.test.ts b/backend/tests/data/questions/questions.test.ts index e8069070..f24601bb 100644 --- a/backend/tests/data/questions/questions.test.ts +++ b/backend/tests/data/questions/questions.test.ts @@ -2,17 +2,18 @@ import { beforeAll, describe, expect, it } from 'vitest'; import { setupTestApp } from '../../setup-tests'; import { QuestionRepository } from '../../../src/data/questions/question-repository'; import { - getAssignmentRepository, getClassRepository, + getAssignmentRepository, + getClassRepository, getGroupRepository, getQuestionRepository, - getStudentRepository + getStudentRepository, } from '../../../src/data/repositories'; import { StudentRepository } from '../../../src/data/users/student-repository'; import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier'; import { Language } from '@dwengo-1/common/util/language'; -import {Question} from "../../../src/entities/questions/question.entity"; -import {Class} from "../../../src/entities/classes/class.entity"; -import {Assignment} from "../../../src/entities/assignments/assignment.entity"; +import { Question } from '../../../src/entities/questions/question.entity'; +import { Class } from '../../../src/entities/classes/class.entity'; +import { Assignment } from '../../../src/entities/assignments/assignment.entity'; describe('QuestionRepository', () => { let questionRepository: QuestionRepository; @@ -36,7 +37,7 @@ describe('QuestionRepository', () => { const id = new LearningObjectIdentifier('id03', Language.English, 1); const student = await studentRepository.findByUsername('Noordkaap'); - const clazz = await getClassRepository().findById("id01"); + const clazz = await getClassRepository().findById('id01'); const assignment = await getAssignmentRepository().findByClassAndId(clazz!, 1); const group = await getGroupRepository().findByAssignmentAndGroupNumber(assignment!, 1); await questionRepository.createQuestion({ @@ -58,9 +59,9 @@ describe('QuestionRepository', () => { clazz = await getClassRepository().findById('id01'); assignment = await getAssignmentRepository().findByClassAndId(clazz!, 1); loId = { - hruid: "id05", + hruid: 'id05', language: Language.English, - version: 1 + version: 1, }; const result = await questionRepository.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!); sortQuestions(result); @@ -83,8 +84,7 @@ describe('QuestionRepository', () => { }); it("should find only the questions for a certain learning object and assignment asked by the user's group", async () => { - const result = - await questionRepository.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!, "Tool"); + const result = await questionRepository.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!, 'Tool'); // (student Tool is in group #2) expect(result).toHaveLength(1); @@ -110,8 +110,11 @@ describe('QuestionRepository', () => { function sortQuestions(questions: Question[]): void { questions.sort((a, b) => { - if (a.learningObjectHruid < b.learningObjectHruid) {return -1} - else if (a.learningObjectHruid > b.learningObjectHruid) {return 1} - return a.sequenceNumber! - b.sequenceNumber! + if (a.learningObjectHruid < b.learningObjectHruid) { + return -1; + } else if (a.learningObjectHruid > b.learningObjectHruid) { + return 1; + } + return a.sequenceNumber! - b.sequenceNumber!; }); } diff --git a/backend/tests/services/learning-path/database-learning-path-provider.test.ts b/backend/tests/services/learning-path/database-learning-path-provider.test.ts index 2c7ceb0b..0a0370a3 100644 --- a/backend/tests/services/learning-path/database-learning-path-provider.test.ts +++ b/backend/tests/services/learning-path/database-learning-path-provider.test.ts @@ -25,9 +25,9 @@ import { Student } from '../../../src/entities/users/student.entity.js'; import { LearningObjectNode, LearningPathResponse } from '@dwengo-1/common/interfaces/learning-content'; -const STUDENT_A_USERNAME = "student_a"; -const STUDENT_B_USERNAME = "student_b"; -const CLASS_NAME = "test_class" +const STUDENT_A_USERNAME = 'student_a'; +const STUDENT_B_USERNAME = 'student_b'; +const CLASS_NAME = 'test_class'; async function initExampleData(): Promise<{ learningObject: LearningObject; learningPath: LearningPath }> { const learningObjectRepo = getLearningObjectRepository(); @@ -44,7 +44,7 @@ async function initPersonalizationTestData(): Promise<{ studentA: Student; studentB: Student; }> { - const studentRepo = getStudentRepository() + const studentRepo = getStudentRepository(); const classRepo = getClassRepository(); const assignmentRepo = getAssignmentRepository(); const groupRepo = getGroupRepository(); @@ -75,31 +75,31 @@ async function initPersonalizationTestData(): Promise<{ // Create class for students const testClass = classRepo.create({ classId: CLASS_NAME, - displayName: "Test class" + displayName: 'Test class', }); await classRepo.save(testClass); // Create assignment for students and assign them to different groups const assignment = assignmentRepo.create({ id: 0, - title: "Test assignment", - description: "Test description", + title: 'Test assignment', + description: 'Test description', learningPathHruid: learningContent.learningPath.hruid, learningPathLanguage: learningContent.learningPath.language, - within: testClass - }) + within: testClass, + }); const groupA = groupRepo.create({ groupNumber: 0, members: [studentA], - assignment + assignment, }); await groupRepo.save(groupA); const groupB = groupRepo.create({ groupNumber: 1, members: [studentB], - assignment + assignment, }); await groupRepo.save(groupB); diff --git a/backend/tests/test_assets/questions/questions.testdata.ts b/backend/tests/test_assets/questions/questions.testdata.ts index 1e4a37ef..10a04571 100644 --- a/backend/tests/test_assets/questions/questions.testdata.ts +++ b/backend/tests/test_assets/questions/questions.testdata.ts @@ -2,7 +2,7 @@ import { EntityManager } from '@mikro-orm/core'; import { Question } from '../../../src/entities/questions/question.entity'; import { Language } from '@dwengo-1/common/util/language'; import { Student } from '../../../src/entities/users/student.entity'; -import {Group} from "../../../src/entities/assignments/group.entity"; +import { Group } from '../../../src/entities/assignments/group.entity'; export function makeTestQuestions(em: EntityManager, students: Student[], groups: Group[]): Question[] { const question01 = em.create(Question, { diff --git a/common/src/interfaces/question.ts b/common/src/interfaces/question.ts index 9b00e1bd..bd689c34 100644 --- a/common/src/interfaces/question.ts +++ b/common/src/interfaces/question.ts @@ -1,6 +1,6 @@ import { LearningObjectIdentifier } from './learning-content'; import { StudentDTO } from './student'; -import {GroupDTO} from "./group"; +import { GroupDTO } from './group'; export interface QuestionDTO { learningObjectIdentifier: LearningObjectIdentifier;