fix: leerling kon alle opdrachten zien + test
This commit is contained in:
parent
2f67033251
commit
29f6bd9cad
2 changed files with 24 additions and 5 deletions
|
@ -10,7 +10,7 @@ import { mapToClassDTO } from '../interfaces/class.js';
|
||||||
import { mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js';
|
import { mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js';
|
||||||
import { mapToStudent, mapToStudentDTO } from '../interfaces/student.js';
|
import { mapToStudent, mapToStudentDTO } from '../interfaces/student.js';
|
||||||
import { mapToSubmissionDTO, mapToSubmissionDTOId } from '../interfaces/submission.js';
|
import { mapToSubmissionDTO, mapToSubmissionDTOId } from '../interfaces/submission.js';
|
||||||
import { getAllAssignments } from './assignments.js';
|
import {fetchAssignment, getAllAssignments} from './assignments.js';
|
||||||
import { mapToQuestionDTO, mapToQuestionDTOId } from '../interfaces/question.js';
|
import { mapToQuestionDTO, mapToQuestionDTOId } from '../interfaces/question.js';
|
||||||
import { mapToStudentRequest, mapToStudentRequestDTO } from '../interfaces/student-request.js';
|
import { mapToStudentRequest, mapToStudentRequestDTO } from '../interfaces/student-request.js';
|
||||||
import { Student } from '../entities/users/student.entity.js';
|
import { Student } from '../entities/users/student.entity.js';
|
||||||
|
@ -26,6 +26,7 @@ import { ClassJoinRequestDTO } from '@dwengo-1/common/interfaces/class-join-requ
|
||||||
import { ConflictException } from '../exceptions/conflict-exception.js';
|
import { ConflictException } from '../exceptions/conflict-exception.js';
|
||||||
import { Submission } from '../entities/assignments/submission.entity.js';
|
import { Submission } from '../entities/assignments/submission.entity.js';
|
||||||
import { mapToUsername } from '../interfaces/user.js';
|
import { mapToUsername } from '../interfaces/user.js';
|
||||||
|
import {mapToAssignmentDTO, mapToAssignmentDTOId} from "../interfaces/assignment";
|
||||||
|
|
||||||
export async function getAllStudents(full: boolean): Promise<StudentDTO[] | string[]> {
|
export async function getAllStudents(full: boolean): Promise<StudentDTO[] | string[]> {
|
||||||
const studentRepository = getStudentRepository();
|
const studentRepository = getStudentRepository();
|
||||||
|
@ -102,10 +103,14 @@ export async function getStudentClasses(username: string, full: boolean): Promis
|
||||||
export async function getStudentAssignments(username: string, full: boolean): Promise<AssignmentDTO[] | AssignmentDTOId[]> {
|
export async function getStudentAssignments(username: string, full: boolean): Promise<AssignmentDTO[] | AssignmentDTOId[]> {
|
||||||
const student = await fetchStudent(username);
|
const student = await fetchStudent(username);
|
||||||
|
|
||||||
const classRepository = getClassRepository();
|
const groupRepository = getGroupRepository();
|
||||||
const classes = await classRepository.findByStudent(student);
|
const groups = await groupRepository.findAllGroupsWithStudent(student);
|
||||||
|
const assignments = await Promise.all(groups.map( async group => await fetchAssignment(group.assignment.within.classId, group.assignment.id)));
|
||||||
|
|
||||||
return (await Promise.all(classes.map(async (cls) => await getAllAssignments(cls.classId!, full)))).flat();
|
if (full) {
|
||||||
|
return assignments.map(mapToAssignmentDTO);
|
||||||
|
}
|
||||||
|
return assignments.map(mapToAssignmentDTOId);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getStudentGroups(username: string, full: boolean): Promise<GroupDTO[] | GroupDTOId[]> {
|
export async function getStudentGroups(username: string, full: boolean): Promise<GroupDTO[] | GroupDTOId[]> {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import {
|
||||||
createStudentRequestHandler,
|
createStudentRequestHandler,
|
||||||
getStudentRequestsHandler,
|
getStudentRequestsHandler,
|
||||||
deleteClassJoinRequestHandler,
|
deleteClassJoinRequestHandler,
|
||||||
getStudentRequestHandler,
|
getStudentRequestHandler, getStudentAssignmentsHandler,
|
||||||
} from '../../src/controllers/students.js';
|
} from '../../src/controllers/students.js';
|
||||||
import { getDireStraits, getNoordkaap, getTheDoors, TEST_STUDENTS } from '../test_assets/users/students.testdata.js';
|
import { getDireStraits, getNoordkaap, getTheDoors, TEST_STUDENTS } from '../test_assets/users/students.testdata.js';
|
||||||
import { NotFoundException } from '../../src/exceptions/not-found-exception.js';
|
import { NotFoundException } from '../../src/exceptions/not-found-exception.js';
|
||||||
|
@ -150,6 +150,20 @@ describe('Student controllers', () => {
|
||||||
expect(result.groups).to.have.length.greaterThan(0);
|
expect(result.groups).to.have.length.greaterThan(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Student assignments', async () => {
|
||||||
|
const group = getTestGroup01();
|
||||||
|
const member = group.members[0];
|
||||||
|
req = { params: { username: member.username }, query: {} };
|
||||||
|
|
||||||
|
await getStudentAssignmentsHandler(req as Request, res as Response);
|
||||||
|
|
||||||
|
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ assignments: expect.anything() }));
|
||||||
|
|
||||||
|
const result = jsonMock.mock.lastCall?.[0];
|
||||||
|
expect(result.assignments).to.have.length.greaterThan(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
it('Student submissions', async () => {
|
it('Student submissions', async () => {
|
||||||
const submission = getSubmission01();
|
const submission = getSubmission01();
|
||||||
req = { params: { username: submission.submitter.username }, query: { full: 'true' } };
|
req = { params: { username: submission.submitter.username }, query: { full: 'true' } };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue