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));
|
||||
}
|
||||
|
|
|
@ -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 () => {
|
||||
|
|
|
@ -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]);
|
||||
});
|
||||
|
|
|
@ -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!;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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!;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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, {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue