style: fix linting issues met Prettier

This commit is contained in:
Lint Action 2025-04-08 08:56:50 +00:00
parent ba725f67b2
commit 8a55c0f003
22 changed files with 137 additions and 157 deletions

View file

@ -5,13 +5,13 @@ import {
getAllQuestions, getAllQuestions,
getAnswersByQuestion, getAnswersByQuestion,
getQuestion, getQuestion,
getQuestionsAboutLearningObjectInAssignment getQuestionsAboutLearningObjectInAssignment,
} from '../services/questions.js'; } from '../services/questions.js';
import { FALLBACK_LANG, FALLBACK_SEQ_NUM } from '../config.js'; import { FALLBACK_LANG, FALLBACK_SEQ_NUM } from '../config.js';
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question';
import { Language } from '@dwengo-1/common/util/language'; 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 { interface QuestionPathParams {
hruid: string; hruid: string;
@ -62,10 +62,10 @@ function getQuestionId<ReqBody, ResBody>(
} }
interface GetAllQuestionsQueryParams extends QuestionQueryParams { interface GetAllQuestionsQueryParams extends QuestionQueryParams {
classId?: string, classId?: string;
assignmentId?: number, assignmentId?: number;
forStudent?: string, forStudent?: string;
full?: boolean full?: boolean;
} }
export async function getAllQuestionsHandler( export async function getAllQuestionsHandler(
@ -118,10 +118,10 @@ export async function getQuestionHandler(
} }
interface GetQuestionAnswersQueryParams extends QuestionQueryParams { interface GetQuestionAnswersQueryParams extends QuestionQueryParams {
full: boolean full: boolean;
} }
export async function getQuestionAnswersHandler( export async function getQuestionAnswersHandler(
req: Request<GetQuestionIdPathParams, {answers: AnswerDTO[] | AnswerId[]}, unknown, GetQuestionAnswersQueryParams>, req: Request<GetQuestionIdPathParams, { answers: AnswerDTO[] | AnswerId[] }, unknown, GetQuestionAnswersQueryParams>,
res: Response res: Response
): Promise<void> { ): Promise<void> {
const questionId = getQuestionId(req, res); const questionId = getQuestionId(req, res);

View file

@ -1,13 +1,8 @@
import { Request, Response } from 'express'; import { Request, Response } from 'express';
import { import { createSubmission, deleteSubmission, getSubmission, getSubmissionsForLearningObjectAndAssignment } from '../services/submissions.js';
createSubmission,
deleteSubmission,
getSubmission,
getSubmissionsForLearningObjectAndAssignment
} from '../services/submissions.js';
import { SubmissionDTO } from '@dwengo-1/common/interfaces/submission'; import { SubmissionDTO } from '@dwengo-1/common/interfaces/submission';
import { Language, languageMap } from '@dwengo-1/common/util/language'; 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 { interface SubmissionParams {
hruid: string; hruid: string;
@ -15,27 +10,22 @@ interface SubmissionParams {
} }
interface SubmissionQuery { interface SubmissionQuery {
language: string, language: string;
version: number; version: number;
} }
interface SubmissionsQuery extends SubmissionQuery { interface SubmissionsQuery extends SubmissionQuery {
classId: string, classId: string;
assignmentId: number, assignmentId: number;
studentUsername?: string studentUsername?: string;
} }
export async function getSubmissionsHandler( export async function getSubmissionsHandler(req: Request<SubmissionParams, Submission[], null, SubmissionsQuery>, res: Response): Promise<void> {
req: Request<SubmissionParams, Submission[], null, SubmissionsQuery>,
res: Response
): Promise<void> {
const loHruid = req.params.hruid; const loHruid = req.params.hruid;
const lang = languageMap[req.query.language] || Language.Dutch; const lang = languageMap[req.query.language] || Language.Dutch;
const version = (req.query.version || 1); const version = req.query.version || 1;
const submissions = await getSubmissionsForLearningObjectAndAssignment( const submissions = await getSubmissionsForLearningObjectAndAssignment(loHruid, lang, version, req.query.classId, req.query.assignmentId);
loHruid, lang, version, req.query.classId, req.query.assignmentId
);
res.json(submissions); res.json(submissions);
} }

View file

@ -15,11 +15,11 @@ export class AssignmentRepository extends DwengoEntityRepository<Assignment> {
within: { within: {
teachers: { teachers: {
$some: { $some: {
username: teacherUsername username: teacherUsername,
} },
} },
} },
} },
}); });
} }
public async findAllAssignmentsInClass(within: Class): Promise<Assignment[]> { public async findAllAssignmentsInClass(within: Class): Promise<Assignment[]> {

View file

@ -3,7 +3,7 @@ import { Group } from '../../entities/assignments/group.entity.js';
import { Submission } from '../../entities/assignments/submission.entity.js'; import { Submission } from '../../entities/assignments/submission.entity.js';
import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js'; import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js';
import { Student } from '../../entities/users/student.entity.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> { export class SubmissionRepository extends DwengoEntityRepository<Submission> {
public async findSubmissionByLearningObjectAndSubmissionNumber( public async findSubmissionByLearningObjectAndSubmissionNumber(
@ -46,7 +46,7 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> {
return this.find( return this.find(
{ onBehalfOf: group }, { onBehalfOf: group },
{ {
populate: ["onBehalfOf.members"] populate: ['onBehalfOf.members'],
} }
); );
} }
@ -60,15 +60,17 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> {
assignment: Assignment, assignment: Assignment,
forStudentUsername?: string forStudentUsername?: string
): Promise<Submission[]> { ): Promise<Submission[]> {
const onBehalfOf = forStudentUsername ? { const onBehalfOf = forStudentUsername
? {
assignment, assignment,
members: { members: {
$some: { $some: {
username: forStudentUsername username: forStudentUsername,
},
},
} }
} : {
} : { assignment,
assignment
}; };
return this.findAll({ return this.findAll({
@ -76,8 +78,8 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> {
learningObjectHruid: loId.hruid, learningObjectHruid: loId.hruid,
learningObjectLanguage: loId.language, learningObjectLanguage: loId.language,
learningObjectVersion: loId.version, learningObjectVersion: loId.version,
onBehalfOf onBehalfOf,
} },
}); });
} }
@ -85,9 +87,7 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> {
const result = await this.find( const result = await this.find(
{ submitter: student }, { submitter: student },
{ {
populate: [ populate: ['onBehalfOf.members'],
"onBehalfOf.members"
]
} }
); );

View file

@ -3,11 +3,11 @@ import { Question } from '../../entities/questions/question.entity.js';
import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js'; import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js';
import { Student } from '../../entities/users/student.entity.js'; import { Student } from '../../entities/users/student.entity.js';
import { LearningObject } from '../../entities/content/learning-object.entity.js'; import { LearningObject } from '../../entities/content/learning-object.entity.js';
import {Group} from "../../entities/assignments/group.entity"; import { Group } from '../../entities/assignments/group.entity';
import {Assignment} from "../../entities/assignments/assignment.entity"; import { Assignment } from '../../entities/assignments/assignment.entity';
export class QuestionRepository extends DwengoEntityRepository<Question> { 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({ const questionEntity = this.create({
learningObjectHruid: question.loId.hruid, learningObjectHruid: question.loId.hruid,
learningObjectLanguage: question.loId.language, learningObjectLanguage: question.loId.language,
@ -75,15 +75,17 @@ export class QuestionRepository extends DwengoEntityRepository<Question> {
assignment: Assignment, assignment: Assignment,
forStudentUsername?: string forStudentUsername?: string
): Promise<Question[]> { ): Promise<Question[]> {
const inGroup = forStudentUsername ? { const inGroup = forStudentUsername
? {
assignment, assignment,
members: { members: {
$some: { $some: {
username: forStudentUsername username: forStudentUsername,
},
},
} }
} : {
} : { assignment,
assignment
}; };
return this.findAll({ return this.findAll({
@ -91,8 +93,8 @@ export class QuestionRepository extends DwengoEntityRepository<Question> {
learningObjectHruid: loId.hruid, learningObjectHruid: loId.hruid,
learningObjectLanguage: loId.language, learningObjectLanguage: loId.language,
learningObjectVersion: loId.version, learningObjectVersion: loId.version,
inGroup inGroup,
} },
}); });
} }
} }

View file

@ -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 { Class } from '../classes/class.entity.js';
import { Group } from './group.entity.js'; import { Group } from './group.entity.js';
import { Language } from '@dwengo-1/common/util/language'; import { Language } from '@dwengo-1/common/util/language';

View file

@ -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 { Assignment } from './assignment.entity.js';
import { Student } from '../users/student.entity.js'; import { Student } from '../users/student.entity.js';
import { GroupRepository } from '../../data/assignments/group-repository.js'; import { GroupRepository } from '../../data/assignments/group-repository.js';

View file

@ -22,7 +22,7 @@ export class Submission {
submissionNumber?: number; submissionNumber?: number;
@ManyToOne({ @ManyToOne({
entity: () => Group entity: () => Group,
}) })
onBehalfOf!: Group; onBehalfOf!: Group;
@ -34,8 +34,6 @@ export class Submission {
@Property({ type: 'datetime' }) @Property({ type: 'datetime' })
submissionTime!: Date; submissionTime!: Date;
@Property({ type: 'json' }) @Property({ type: 'json' })
content!: string; content!: string;
} }

View file

@ -2,7 +2,7 @@ import { Entity, Enum, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core';
import { Student } from '../users/student.entity.js'; import { Student } from '../users/student.entity.js';
import { QuestionRepository } from '../../data/questions/question-repository.js'; import { QuestionRepository } from '../../data/questions/question-repository.js';
import { Language } from '@dwengo-1/common/util/language'; import { Language } from '@dwengo-1/common/util/language';
import {Group} from "../assignments/group.entity"; import { Group } from '../assignments/group.entity';
@Entity({ repository: () => QuestionRepository }) @Entity({ repository: () => QuestionRepository })
export class Question { export class Question {

View file

@ -1,11 +1,11 @@
import { Group } from '../entities/assignments/group.entity.js'; import { Group } from '../entities/assignments/group.entity.js';
import {mapToAssignment, mapToAssignmentDTO, mapToAssignmentDTOId} from './assignment.js'; import { mapToAssignment, mapToAssignmentDTO, mapToAssignmentDTOId } from './assignment.js';
import {mapToStudent, mapToStudentDTO} from './student.js'; import { mapToStudent, mapToStudentDTO } from './student.js';
import {GroupDTO} from '@dwengo-1/common/interfaces/group'; import { GroupDTO } from '@dwengo-1/common/interfaces/group';
import {getGroupRepository} from "../data/repositories"; import { getGroupRepository } from '../data/repositories';
import {AssignmentDTO} from "@dwengo-1/common/interfaces/assignment"; import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment';
import {Class} from "../entities/classes/class.entity"; import { Class } from '../entities/classes/class.entity';
import {StudentDTO} from "@dwengo-1/common/interfaces/student"; import { StudentDTO } from '@dwengo-1/common/interfaces/student';
export function mapToGroup(groupDto: GroupDTO, clazz: Class): Group { export function mapToGroup(groupDto: GroupDTO, clazz: Class): Group {
const assignmentDto = groupDto.assignment as AssignmentDTO; const assignmentDto = groupDto.assignment as AssignmentDTO;
@ -13,7 +13,7 @@ export function mapToGroup(groupDto: GroupDTO, clazz: Class): Group {
return getGroupRepository().create({ return getGroupRepository().create({
groupNumber: groupDto.groupNumber, groupNumber: groupDto.groupNumber,
assignment: mapToAssignment(assignmentDto, clazz), assignment: mapToAssignment(assignmentDto, clazz),
members: groupDto.members!.map(studentDto => mapToStudent(studentDto as StudentDTO)) members: groupDto.members!.map((studentDto) => mapToStudent(studentDto as StudentDTO)),
}); });
} }

View file

@ -2,7 +2,7 @@ import { Question } from '../entities/questions/question.entity.js';
import { mapToStudentDTO } from './student.js'; import { mapToStudentDTO } from './student.js';
import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question';
import { LearningObjectIdentifier } from '@dwengo-1/common/interfaces/learning-content'; import { LearningObjectIdentifier } from '@dwengo-1/common/interfaces/learning-content';
import { mapToGroupDTOId } from "./group"; import { mapToGroupDTOId } from './group';
function getLearningObjectIdentifier(question: Question): LearningObjectIdentifier { function getLearningObjectIdentifier(question: Question): LearningObjectIdentifier {
return { return {

View file

@ -1,10 +1,5 @@
import express from 'express'; import express from 'express';
import { import { createSubmissionHandler, deleteSubmissionHandler, getSubmissionHandler, getSubmissionsHandler } from '../controllers/submissions.js';
createSubmissionHandler,
deleteSubmissionHandler,
getSubmissionHandler,
getSubmissionsHandler
} from '../controllers/submissions.js';
const router = express.Router({ mergeParams: true }); const router = express.Router({ mergeParams: true });
// Root endpoint used to search objects // Root endpoint used to search objects

View file

@ -1,9 +1,4 @@
import { import { getAnswerRepository, getAssignmentRepository, getClassRepository, getGroupRepository, getQuestionRepository } from '../data/repositories.js';
getAnswerRepository, getAssignmentRepository,
getClassRepository,
getGroupRepository,
getQuestionRepository
} from '../data/repositories.js';
import { mapToQuestionDTO, mapToQuestionDTOId } from '../interfaces/question.js'; import { mapToQuestionDTO, mapToQuestionDTOId } from '../interfaces/question.js';
import { Question } from '../entities/questions/question.entity.js'; import { Question } from '../entities/questions/question.entity.js';
import { Answer } from '../entities/questions/answer.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 { mapToStudent } from '../interfaces/student.js';
import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question';
import { AnswerDTO, AnswerId } from '@dwengo-1/common/interfaces/answer'; import { AnswerDTO, AnswerId } from '@dwengo-1/common/interfaces/answer';
import { AssignmentDTO } from "@dwengo-1/common/interfaces/assignment"; import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment';
import { mapToAssignment } from "../interfaces/assignment"; import { mapToAssignment } from '../interfaces/assignment';
export async function getQuestionsAboutLearningObjectInAssignment( export async function getQuestionsAboutLearningObjectInAssignment(
loId: LearningObjectIdentifier, loId: LearningObjectIdentifier,
@ -23,15 +18,14 @@ export async function getQuestionsAboutLearningObjectInAssignment(
full: boolean, full: boolean,
studentUsername?: string studentUsername?: string
): Promise<QuestionDTO[] | QuestionId[]> { ): Promise<QuestionDTO[] | QuestionId[]> {
const assignment = await getAssignmentRepository() const assignment = await getAssignmentRepository().findByClassIdAndAssignmentId(classId, assignmentId);
.findByClassIdAndAssignmentId(classId, assignmentId);
const questions = await getQuestionRepository() const questions = await getQuestionRepository().findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!, studentUsername);
.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!, studentUsername);
if (full) if (full) {
{return questions.map(q => mapToQuestionDTO(q));} return questions.map((q) => mapToQuestionDTO(q));
return questions.map(q => mapToQuestionDTOId(q)); }
return questions.map((q) => mapToQuestionDTOId(q));
} }
export async function getAllQuestions(id: LearningObjectIdentifier, full: boolean): Promise<QuestionDTO[] | QuestionId[]> { 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, 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 assignment = mapToAssignment(questionDTO.inGroup.assignment as AssignmentDTO, clazz!);
const inGroup = await getGroupRepository().findByAssignmentAndGroupNumber(assignment, questionDTO.inGroup.groupNumber); const inGroup = await getGroupRepository().findByAssignmentAndGroupNumber(assignment, questionDTO.inGroup.groupNumber);

View file

@ -23,7 +23,7 @@ import { GroupDTO } from '@dwengo-1/common/interfaces/group';
import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission'; import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission';
import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question';
import { ClassJoinRequestDTO } from '@dwengo-1/common/interfaces/class-join-request'; import { ClassJoinRequestDTO } from '@dwengo-1/common/interfaces/class-join-request';
import {Submission} from "../entities/assignments/submission.entity"; import { Submission } from '../entities/assignments/submission.entity';
export async function getAllStudents(full: boolean): Promise<StudentDTO[] | string[]> { export async function getAllStudents(full: boolean): Promise<StudentDTO[] | string[]> {
const studentRepository = getStudentRepository(); const studentRepository = getStudentRepository();

View file

@ -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 { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
import { mapToSubmission, mapToSubmissionDTO } from '../interfaces/submission.js'; import { mapToSubmission, mapToSubmissionDTO } from '../interfaces/submission.js';
import { SubmissionDTO } from '@dwengo-1/common/interfaces/submission'; import { SubmissionDTO } from '@dwengo-1/common/interfaces/submission';
@ -68,11 +68,9 @@ export async function getSubmissionsForLearningObjectAndAssignment(
studentUsername?: string studentUsername?: string
): Promise<SubmissionDTO[]> { ): Promise<SubmissionDTO[]> {
const loId = new LearningObjectIdentifier(learningObjectHruid, language, version); const loId = new LearningObjectIdentifier(learningObjectHruid, language, version);
const assignment = await getAssignmentRepository() const assignment = await getAssignmentRepository().findByClassIdAndAssignmentId(classId, assignmentId);
.findByClassIdAndAssignmentId(classId, assignmentId);
const submissions = await getSubmissionRepository() const submissions = await getSubmissionRepository().findAllSubmissionsForLearningObjectAndAssignment(loId, assignment!, studentUsername);
.findAllSubmissionsForLearningObjectAndAssignment(loId, assignment!, studentUsername);
return submissions.map(s => mapToSubmissionDTO(s)); return submissions.map((s) => mapToSubmissionDTO(s));
} }

View file

@ -147,7 +147,6 @@ describe('Student controllers', () => {
const result = jsonMock.mock.lastCall?.[0]; const result = jsonMock.mock.lastCall?.[0];
expect(result.submissions).to.have.length.greaterThan(0); expect(result.submissions).to.have.length.greaterThan(0);
}); });
it('Student questions', async () => { it('Student questions', async () => {

View file

@ -32,10 +32,8 @@ describe('AssignmentRepository', () => {
}); });
it('should find all by username of the responsible teacher', async () => { it('should find all by username of the responsible teacher', async () => {
const result = await assignmentRepository.findAllByResponsibleTeacher("FooFighters") const result = await assignmentRepository.findAllByResponsibleTeacher('FooFighters');
const resultIds = result const resultIds = result.map((it) => it.id).sort((a, b) => (a ?? 0) - (b ?? 0));
.map(it => it.id)
.sort((a, b) => (a ?? 0) - (b ?? 0));
expect(resultIds).toEqual([1, 3, 4]); expect(resultIds).toEqual([1, 3, 4]);
}); });

View file

@ -1,6 +1,6 @@
import {beforeAll, describe, expect, it} from 'vitest'; import { beforeAll, describe, expect, it } from 'vitest';
import {setupTestApp} from '../../setup-tests'; import { setupTestApp } from '../../setup-tests';
import {SubmissionRepository} from '../../../src/data/assignments/submission-repository'; import { SubmissionRepository } from '../../../src/data/assignments/submission-repository';
import { import {
getAssignmentRepository, getAssignmentRepository,
getClassRepository, getClassRepository,
@ -8,15 +8,15 @@ import {
getStudentRepository, getStudentRepository,
getSubmissionRepository, getSubmissionRepository,
} from '../../../src/data/repositories'; } from '../../../src/data/repositories';
import {LearningObjectIdentifier} from '../../../src/entities/content/learning-object-identifier'; import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier';
import {Language} from '@dwengo-1/common/util/language'; import { Language } from '@dwengo-1/common/util/language';
import {StudentRepository} from '../../../src/data/users/student-repository'; import { StudentRepository } from '../../../src/data/users/student-repository';
import {GroupRepository} from '../../../src/data/assignments/group-repository'; import { GroupRepository } from '../../../src/data/assignments/group-repository';
import {AssignmentRepository} from '../../../src/data/assignments/assignment-repository'; import { AssignmentRepository } from '../../../src/data/assignments/assignment-repository';
import {ClassRepository} from '../../../src/data/classes/class-repository'; import { ClassRepository } from '../../../src/data/classes/class-repository';
import {Submission} from "../../../src/entities/assignments/submission.entity"; import { Submission } from '../../../src/entities/assignments/submission.entity';
import {Class} from "../../../src/entities/classes/class.entity"; import { Class } from '../../../src/entities/classes/class.entity';
import {Assignment} from "../../../src/entities/assignments/assignment.entity"; import { Assignment } from '../../../src/entities/assignments/assignment.entity';
describe('SubmissionRepository', () => { describe('SubmissionRepository', () => {
let submissionRepository: SubmissionRepository; let submissionRepository: SubmissionRepository;
@ -69,9 +69,9 @@ describe('SubmissionRepository', () => {
clazz = await classRepository.findById('id01'); clazz = await classRepository.findById('id01');
assignment = await assignmentRepository.findByClassAndId(clazz!, 1); assignment = await assignmentRepository.findByClassAndId(clazz!, 1);
loId = { loId = {
hruid: "id02", hruid: 'id02',
language: Language.English, language: Language.English,
version: 1 version: 1,
}; };
const result = await submissionRepository.findAllSubmissionsForLearningObjectAndAssignment(loId, assignment!); const result = await submissionRepository.findAllSubmissionsForLearningObjectAndAssignment(loId, assignment!);
sortSubmissions(result); 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 () => { it("should find only the submissions for a certain learning object and assignment made for the user's group", async () => {
const result = const result = await submissionRepository.findAllSubmissionsForLearningObjectAndAssignment(loId, assignment!, 'Tool');
await submissionRepository.findAllSubmissionsForLearningObjectAndAssignment(loId, assignment!, "Tool");
// (student Tool is in group #2) // (student Tool is in group #2)
expect(result).toHaveLength(1); expect(result).toHaveLength(1);
@ -118,8 +117,12 @@ describe('SubmissionRepository', () => {
function sortSubmissions(submissions: Submission[]): void { function sortSubmissions(submissions: Submission[]): void {
submissions.sort((a, b) => { submissions.sort((a, b) => {
if (a.learningObjectHruid < b.learningObjectHruid) {return -1;} if (a.learningObjectHruid < b.learningObjectHruid) {
if (a.learningObjectHruid > b.learningObjectHruid) {return 1;} return -1;
}
if (a.learningObjectHruid > b.learningObjectHruid) {
return 1;
}
return a.submissionNumber! - b.submissionNumber!; return a.submissionNumber! - b.submissionNumber!;
}); });
} }

View file

@ -2,17 +2,18 @@ import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests'; import { setupTestApp } from '../../setup-tests';
import { QuestionRepository } from '../../../src/data/questions/question-repository'; import { QuestionRepository } from '../../../src/data/questions/question-repository';
import { import {
getAssignmentRepository, getClassRepository, getAssignmentRepository,
getClassRepository,
getGroupRepository, getGroupRepository,
getQuestionRepository, getQuestionRepository,
getStudentRepository getStudentRepository,
} from '../../../src/data/repositories'; } from '../../../src/data/repositories';
import { StudentRepository } from '../../../src/data/users/student-repository'; import { StudentRepository } from '../../../src/data/users/student-repository';
import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier'; import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier';
import { Language } from '@dwengo-1/common/util/language'; import { Language } from '@dwengo-1/common/util/language';
import {Question} from "../../../src/entities/questions/question.entity"; import { Question } from '../../../src/entities/questions/question.entity';
import {Class} from "../../../src/entities/classes/class.entity"; import { Class } from '../../../src/entities/classes/class.entity';
import {Assignment} from "../../../src/entities/assignments/assignment.entity"; import { Assignment } from '../../../src/entities/assignments/assignment.entity';
describe('QuestionRepository', () => { describe('QuestionRepository', () => {
let questionRepository: QuestionRepository; let questionRepository: QuestionRepository;
@ -36,7 +37,7 @@ describe('QuestionRepository', () => {
const id = new LearningObjectIdentifier('id03', Language.English, 1); const id = new LearningObjectIdentifier('id03', Language.English, 1);
const student = await studentRepository.findByUsername('Noordkaap'); 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 assignment = await getAssignmentRepository().findByClassAndId(clazz!, 1);
const group = await getGroupRepository().findByAssignmentAndGroupNumber(assignment!, 1); const group = await getGroupRepository().findByAssignmentAndGroupNumber(assignment!, 1);
await questionRepository.createQuestion({ await questionRepository.createQuestion({
@ -58,9 +59,9 @@ describe('QuestionRepository', () => {
clazz = await getClassRepository().findById('id01'); clazz = await getClassRepository().findById('id01');
assignment = await getAssignmentRepository().findByClassAndId(clazz!, 1); assignment = await getAssignmentRepository().findByClassAndId(clazz!, 1);
loId = { loId = {
hruid: "id05", hruid: 'id05',
language: Language.English, language: Language.English,
version: 1 version: 1,
}; };
const result = await questionRepository.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!); const result = await questionRepository.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!);
sortQuestions(result); 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 () => { it("should find only the questions for a certain learning object and assignment asked by the user's group", async () => {
const result = const result = await questionRepository.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!, 'Tool');
await questionRepository.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!, "Tool");
// (student Tool is in group #2) // (student Tool is in group #2)
expect(result).toHaveLength(1); expect(result).toHaveLength(1);
@ -110,8 +110,11 @@ describe('QuestionRepository', () => {
function sortQuestions(questions: Question[]): void { function sortQuestions(questions: Question[]): void {
questions.sort((a, b) => { questions.sort((a, b) => {
if (a.learningObjectHruid < b.learningObjectHruid) {return -1} if (a.learningObjectHruid < b.learningObjectHruid) {
else if (a.learningObjectHruid > b.learningObjectHruid) {return 1} return -1;
return a.sequenceNumber! - b.sequenceNumber! } else if (a.learningObjectHruid > b.learningObjectHruid) {
return 1;
}
return a.sequenceNumber! - b.sequenceNumber!;
}); });
} }

View file

@ -25,9 +25,9 @@ import { Student } from '../../../src/entities/users/student.entity.js';
import { LearningObjectNode, LearningPathResponse } from '@dwengo-1/common/interfaces/learning-content'; import { LearningObjectNode, LearningPathResponse } from '@dwengo-1/common/interfaces/learning-content';
const STUDENT_A_USERNAME = "student_a"; const STUDENT_A_USERNAME = 'student_a';
const STUDENT_B_USERNAME = "student_b"; const STUDENT_B_USERNAME = 'student_b';
const CLASS_NAME = "test_class" const CLASS_NAME = 'test_class';
async function initExampleData(): Promise<{ learningObject: LearningObject; learningPath: LearningPath }> { async function initExampleData(): Promise<{ learningObject: LearningObject; learningPath: LearningPath }> {
const learningObjectRepo = getLearningObjectRepository(); const learningObjectRepo = getLearningObjectRepository();
@ -44,7 +44,7 @@ async function initPersonalizationTestData(): Promise<{
studentA: Student; studentA: Student;
studentB: Student; studentB: Student;
}> { }> {
const studentRepo = getStudentRepository() const studentRepo = getStudentRepository();
const classRepo = getClassRepository(); const classRepo = getClassRepository();
const assignmentRepo = getAssignmentRepository(); const assignmentRepo = getAssignmentRepository();
const groupRepo = getGroupRepository(); const groupRepo = getGroupRepository();
@ -75,31 +75,31 @@ async function initPersonalizationTestData(): Promise<{
// Create class for students // Create class for students
const testClass = classRepo.create({ const testClass = classRepo.create({
classId: CLASS_NAME, classId: CLASS_NAME,
displayName: "Test class" displayName: 'Test class',
}); });
await classRepo.save(testClass); await classRepo.save(testClass);
// Create assignment for students and assign them to different groups // Create assignment for students and assign them to different groups
const assignment = assignmentRepo.create({ const assignment = assignmentRepo.create({
id: 0, id: 0,
title: "Test assignment", title: 'Test assignment',
description: "Test description", description: 'Test description',
learningPathHruid: learningContent.learningPath.hruid, learningPathHruid: learningContent.learningPath.hruid,
learningPathLanguage: learningContent.learningPath.language, learningPathLanguage: learningContent.learningPath.language,
within: testClass within: testClass,
}) });
const groupA = groupRepo.create({ const groupA = groupRepo.create({
groupNumber: 0, groupNumber: 0,
members: [studentA], members: [studentA],
assignment assignment,
}); });
await groupRepo.save(groupA); await groupRepo.save(groupA);
const groupB = groupRepo.create({ const groupB = groupRepo.create({
groupNumber: 1, groupNumber: 1,
members: [studentB], members: [studentB],
assignment assignment,
}); });
await groupRepo.save(groupB); await groupRepo.save(groupB);

View file

@ -2,7 +2,7 @@ import { EntityManager } from '@mikro-orm/core';
import { Question } from '../../../src/entities/questions/question.entity'; import { Question } from '../../../src/entities/questions/question.entity';
import { Language } from '@dwengo-1/common/util/language'; import { Language } from '@dwengo-1/common/util/language';
import { Student } from '../../../src/entities/users/student.entity'; 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[] { export function makeTestQuestions(em: EntityManager, students: Student[], groups: Group[]): Question[] {
const question01 = em.create(Question, { const question01 = em.create(Question, {

View file

@ -1,6 +1,6 @@
import { LearningObjectIdentifier } from './learning-content'; import { LearningObjectIdentifier } from './learning-content';
import { StudentDTO } from './student'; import { StudentDTO } from './student';
import {GroupDTO} from "./group"; import { GroupDTO } from './group';
export interface QuestionDTO { export interface QuestionDTO {
learningObjectIdentifier: LearningObjectIdentifier; learningObjectIdentifier: LearningObjectIdentifier;