feat(backend): Functionaliteit toegevoegd om alle submissions zichtbaar voor een bepaalde leerling of leerkracht op te vragen.
This commit is contained in:
parent
03fa7c7b14
commit
9135b9c5b0
9 changed files with 338 additions and 156 deletions
|
@ -6,6 +6,19 @@ export class AssignmentRepository extends DwengoEntityRepository<Assignment> {
|
|||
public async findByClassAndId(within: Class, id: number): Promise<Assignment | null> {
|
||||
return this.findOne({ within: within, id: id });
|
||||
}
|
||||
public async findAllByResponsibleTeacher(teacherUsername: string): Promise<Assignment[]> {
|
||||
return this.findAll({
|
||||
where: {
|
||||
within: {
|
||||
teachers: {
|
||||
$some: {
|
||||
username: teacherUsername
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
public async findAllAssignmentsInClass(within: Class): Promise<Assignment[]> {
|
||||
return this.findAll({ where: { within: within } });
|
||||
}
|
||||
|
|
|
@ -3,6 +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";
|
||||
|
||||
export class SubmissionRepository extends DwengoEntityRepository<Submission> {
|
||||
public async findSubmissionByLearningObjectAndSubmissionNumber(
|
||||
|
@ -50,6 +51,30 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> {
|
|||
);
|
||||
}
|
||||
|
||||
public async findAllSubmissionsForAllGroupsOfStudent(studentUsername: string): Promise<Submission[]> {
|
||||
return this.findAll({
|
||||
where: {
|
||||
onBehalfOf: {
|
||||
members: {
|
||||
$some: {
|
||||
username: studentUsername
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async findAllSubmissionsForAssignment(assignment: Assignment): Promise<Submission[]> {
|
||||
return this.findAll({
|
||||
where: {
|
||||
onBehalfOf: {
|
||||
assignment
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async findAllSubmissionsForStudent(student: Student): Promise<Submission[]> {
|
||||
return this.find(
|
||||
{ submitter: student },
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { 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';
|
||||
|
@ -19,5 +19,5 @@ export class Group {
|
|||
@ManyToMany({
|
||||
entity: () => Student,
|
||||
})
|
||||
members!: Student[];
|
||||
members!: Collection<Student>;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,13 @@ describe('AssignmentRepository', () => {
|
|||
expect(assignments[0].title).toBe('tool');
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
expect(resultIds).toEqual([1, 3, 4]);
|
||||
});
|
||||
|
||||
it('should not find removed assignment', async () => {
|
||||
const class_ = await classRepository.findById('id01');
|
||||
await assignmentRepository.deleteByClassAndId(class_!, 3);
|
||||
|
|
|
@ -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,12 +8,32 @@ 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 {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";
|
||||
|
||||
export function checkSubmissionsForStudentNoordkaap(result: Submission[]) {
|
||||
sortSubmissions(result);
|
||||
|
||||
expect(result[0].learningObjectHruid).toBe("id01");
|
||||
expect(result[0].submissionNumber).toBe(2);
|
||||
|
||||
expect(result[1].learningObjectHruid).toBe("id02");
|
||||
expect(result[1].submissionNumber).toBe(1);
|
||||
|
||||
expect(result[2].learningObjectHruid).toBe("id02");
|
||||
expect(result[2].submissionNumber).toBe(2);
|
||||
|
||||
expect(result[3].learningObjectHruid).toBe("id03");
|
||||
expect(result[3].submissionNumber).toBe(1);
|
||||
|
||||
expect(result[4].learningObjectHruid).toBe("id03");
|
||||
expect(result[4].submissionNumber).toBe(2);
|
||||
}
|
||||
|
||||
describe('SubmissionRepository', () => {
|
||||
let submissionRepository: SubmissionRepository;
|
||||
|
@ -59,6 +79,42 @@ describe('SubmissionRepository', () => {
|
|||
expect(submission?.submissionTime.getDate()).toBe(25);
|
||||
});
|
||||
|
||||
it('should find all submissions for all groups of a student', async () => {
|
||||
const result = await submissionRepository.findAllSubmissionsForAllGroupsOfStudent("Noordkaap");
|
||||
expect(result.length).toBe(5);
|
||||
|
||||
checkSubmissionsForStudentNoordkaap(result);
|
||||
});
|
||||
|
||||
it('should find all submissions for a certain assignment', async () => {
|
||||
const clazz = await classRepository.findById('id01');
|
||||
const assignment = await assignmentRepository.findByClassAndId(clazz!, 1);
|
||||
const result = await submissionRepository.findAllSubmissionsForAssignment(assignment!);
|
||||
|
||||
sortSubmissions(result);
|
||||
|
||||
expect(result).toHaveLength(5);
|
||||
|
||||
expect(result[0].learningObjectHruid).toBe("id01");
|
||||
expect(result[0].submissionNumber).toBe(1);
|
||||
|
||||
expect(result[1].learningObjectHruid).toBe("id02");
|
||||
expect(result[1].submissionNumber).toBe(1);
|
||||
|
||||
expect(result[2].learningObjectHruid).toBe("id02");
|
||||
expect(result[2].submissionNumber).toBe(2);
|
||||
|
||||
expect(result[3].learningObjectHruid).toBe("id03");
|
||||
expect(result[3].submissionNumber).toBe(1);
|
||||
|
||||
expect(result[4].learningObjectHruid).toBe("id03");
|
||||
expect(result[4].submissionNumber).toBe(2);
|
||||
|
||||
// But not submission7 (id01, submission number: 3), since it was submitted for an assignment
|
||||
|
||||
sortSubmissions(result);
|
||||
});
|
||||
|
||||
it('should not find a deleted submission', async () => {
|
||||
const id = new LearningObjectIdentifier('id01', Language.English, 1);
|
||||
await submissionRepository.deleteSubmissionByLearningObjectAndSubmissionNumber(id, 1);
|
||||
|
@ -68,3 +124,11 @@ describe('SubmissionRepository', () => {
|
|||
expect(submission).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
function sortSubmissions(submissions: Submission[]) {
|
||||
submissions.sort((a, b) => {
|
||||
if (a.learningObjectHruid < b.learningObjectHruid) return -1;
|
||||
if (a.learningObjectHruid > b.learningObjectHruid) return 1;
|
||||
return a.submissionNumber! - b.submissionNumber!;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -34,5 +34,15 @@ export function makeTestAssignemnts(em: EntityManager, classes: Class[]): Assign
|
|||
groups: [],
|
||||
});
|
||||
|
||||
return [assignment01, assignment02, assignment03];
|
||||
const assignment04 = em.create(Assignment, {
|
||||
within: classes[0],
|
||||
id: 4,
|
||||
title: 'another assignment',
|
||||
description: 'with a description',
|
||||
learningPathHruid: 'id01',
|
||||
learningPathLanguage: Language.English,
|
||||
groups: [],
|
||||
});
|
||||
|
||||
return [assignment01, assignment02, assignment03, assignment04];
|
||||
}
|
||||
|
|
|
@ -28,5 +28,11 @@ export function makeTestGroups(em: EntityManager, students: Student[], assignmen
|
|||
members: students.slice(3, 4),
|
||||
});
|
||||
|
||||
return [group01, group02, group03, group04];
|
||||
const group05 = em.create(Group, {
|
||||
assignment: assignments[3],
|
||||
groupNumber: 1,
|
||||
members: students.slice(0, 2),
|
||||
});
|
||||
|
||||
return [group01, group02, group03, group04, group05];
|
||||
}
|
||||
|
|
|
@ -60,5 +60,27 @@ export function makeTestSubmissions(em: EntityManager, students: Student[], grou
|
|||
content: '',
|
||||
});
|
||||
|
||||
return [submission01, submission02, submission03, submission04, submission05];
|
||||
const submission06 = em.create(Submission, {
|
||||
learningObjectHruid: 'id01',
|
||||
learningObjectLanguage: Language.English,
|
||||
learningObjectVersion: 1,
|
||||
submissionNumber: 2,
|
||||
submitter: students[1],
|
||||
submissionTime: new Date(2025, 2, 25),
|
||||
onBehalfOf: groups[4],
|
||||
content: '',
|
||||
});
|
||||
|
||||
const submission07 = em.create(Submission, {
|
||||
learningObjectHruid: 'id01',
|
||||
learningObjectLanguage: Language.English,
|
||||
learningObjectVersion: 1,
|
||||
submissionNumber: 3,
|
||||
submitter: students[3],
|
||||
submissionTime: new Date(2025, 3, 25),
|
||||
onBehalfOf: groups[3],
|
||||
content: '',
|
||||
});
|
||||
|
||||
return [submission01, submission02, submission03, submission04, submission05, submission06, submission07];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue