Merge branch 'dev' into test/e2e-setup
This commit is contained in:
commit
2710e1354e
37 changed files with 11109 additions and 600 deletions
|
@ -66,7 +66,7 @@ export async function putAssignmentHandler(req: Request, res: Response): Promise
|
|||
res.json({ assignment });
|
||||
}
|
||||
|
||||
export async function deleteAssignmentHandler(req: Request, _res: Response): Promise<void> {
|
||||
export async function deleteAssignmentHandler(req: Request, res: Response): Promise<void> {
|
||||
const id = Number(req.params.id);
|
||||
const classid = req.params.classid;
|
||||
requireFields({ id, classid });
|
||||
|
@ -75,7 +75,8 @@ export async function deleteAssignmentHandler(req: Request, _res: Response): Pro
|
|||
throw new BadRequestException('Assignment id should be a number');
|
||||
}
|
||||
|
||||
await deleteAssignment(classid, id);
|
||||
const assignment = await deleteAssignment(classid, id);
|
||||
res.json({ assignment });
|
||||
}
|
||||
|
||||
export async function getAssignmentsSubmissionsHandler(req: Request, res: Response): Promise<void> {
|
||||
|
|
|
@ -3,8 +3,6 @@ import { createGroup, deleteGroup, getAllGroups, getGroup, getGroupSubmissions,
|
|||
import { GroupDTO } from '@dwengo-1/common/interfaces/group';
|
||||
import { requireFields } from './error-helper.js';
|
||||
import { BadRequestException } from '../exceptions/bad-request-exception.js';
|
||||
import { EntityDTO } from '@mikro-orm/core';
|
||||
import { Group } from '../entities/assignments/group.entity.js';
|
||||
|
||||
function checkGroupFields(classId: string, assignmentId: number, groupId: number): void {
|
||||
requireFields({ classId, assignmentId, groupId });
|
||||
|
@ -35,7 +33,11 @@ export async function putGroupHandler(req: Request, res: Response): Promise<void
|
|||
const groupId = parseInt(req.params.groupid);
|
||||
checkGroupFields(classId, assignmentId, groupId);
|
||||
|
||||
const group = await putGroup(classId, assignmentId, groupId, req.body as Partial<EntityDTO<Group>>);
|
||||
// Only members field can be changed
|
||||
const members = req.body.members;
|
||||
requireFields({ members });
|
||||
|
||||
const group = await putGroup(classId, assignmentId, groupId, { members } as Partial<GroupDTO>);
|
||||
|
||||
res.json({ group });
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { Cascade, 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';
|
||||
|
@ -34,6 +34,7 @@ export class Assignment {
|
|||
@OneToMany({
|
||||
entity: () => Group,
|
||||
mappedBy: 'assignment',
|
||||
cascade: [Cascade.ALL],
|
||||
})
|
||||
groups: Collection<Group> = new Collection<Group>(this);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Student } from '../users/student.entity.js';
|
||||
import { Group } from './group.entity.js';
|
||||
import { Entity, Enum, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { Entity, Enum, ManyToOne, PrimaryKey, Property, Cascade } from '@mikro-orm/core';
|
||||
import { SubmissionRepository } from '../../data/assignments/submission-repository.js';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
|
||||
|
@ -21,8 +21,8 @@ export class Submission {
|
|||
@PrimaryKey({ type: 'numeric', autoincrement: false })
|
||||
learningObjectVersion = 1;
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => Group,
|
||||
@ManyToOne(() => Group, {
|
||||
cascade: [Cascade.REMOVE],
|
||||
})
|
||||
onBehalfOf!: Group;
|
||||
|
||||
|
|
|
@ -7,8 +7,17 @@ import { GroupDTO, GroupDTOId } from '@dwengo-1/common/interfaces/group';
|
|||
import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission';
|
||||
import { fetchAssignment } from './assignments.js';
|
||||
import { NotFoundException } from '../exceptions/not-found-exception.js';
|
||||
import { putObject } from './service-helper.js';
|
||||
import { fetchStudents } from './students.js';
|
||||
import { fetchClass } from './classes.js';
|
||||
import { BadRequestException } from '../exceptions/bad-request-exception.js';
|
||||
import { Student } from '../entities/users/student.entity.js';
|
||||
import { Class } from '../entities/classes/class.entity.js';
|
||||
|
||||
async function assertMembersInClass(members: Student[], cls: Class): Promise<void> {
|
||||
if (!members.every((student) => cls.students.contains(student))) {
|
||||
throw new BadRequestException('Student does not belong to class');
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchGroup(classId: string, assignmentNumber: number, groupNumber: number): Promise<Group> {
|
||||
const assignment = await fetchAssignment(classId, assignmentNumber);
|
||||
|
@ -28,15 +37,18 @@ export async function getGroup(classId: string, assignmentNumber: number, groupN
|
|||
return mapToGroupDTO(group, group.assignment.within);
|
||||
}
|
||||
|
||||
export async function putGroup(
|
||||
classId: string,
|
||||
assignmentNumber: number,
|
||||
groupNumber: number,
|
||||
groupData: Partial<EntityDTO<Group>>
|
||||
): Promise<GroupDTO> {
|
||||
export async function putGroup(classId: string, assignmentNumber: number, groupNumber: number, groupData: Partial<GroupDTO>): Promise<GroupDTO> {
|
||||
const group = await fetchGroup(classId, assignmentNumber, groupNumber);
|
||||
|
||||
await putObject<Group>(group, groupData, getGroupRepository());
|
||||
const memberUsernames = groupData.members as string[];
|
||||
const members = await fetchStudents(memberUsernames);
|
||||
|
||||
const cls = await fetchClass(classId);
|
||||
await assertMembersInClass(members, cls);
|
||||
|
||||
const groupRepository = getGroupRepository();
|
||||
groupRepository.assign(group, { members } as Partial<EntityDTO<Group>>);
|
||||
await groupRepository.getEntityManager().persistAndFlush(group);
|
||||
|
||||
return mapToGroupDTO(group, group.assignment.within);
|
||||
}
|
||||
|
@ -63,6 +75,9 @@ export async function createGroup(groupData: GroupDTO, classid: string, assignme
|
|||
const memberUsernames = (groupData.members as string[]) || [];
|
||||
const members = await fetchStudents(memberUsernames);
|
||||
|
||||
const cls = await fetchClass(classid);
|
||||
await assertMembersInClass(members, cls);
|
||||
|
||||
const assignment = await fetchAssignment(classid, assignmentNumber);
|
||||
|
||||
const groupRepository = getGroupRepository();
|
||||
|
|
|
@ -17,6 +17,7 @@ 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 { testLearningObject01 } from '../../test_assets/content/learning-objects.testdata';
|
||||
|
||||
describe('SubmissionRepository', () => {
|
||||
let submissionRepository: SubmissionRepository;
|
||||
|
@ -106,7 +107,7 @@ describe('SubmissionRepository', () => {
|
|||
});
|
||||
|
||||
it('should not find a deleted submission', async () => {
|
||||
const id = new LearningObjectIdentifier('id01', Language.English, 1);
|
||||
const id = new LearningObjectIdentifier(testLearningObject01.hruid, testLearningObject01.language, testLearningObject01.version);
|
||||
await submissionRepository.deleteSubmissionByLearningObjectAndSubmissionNumber(id, 1);
|
||||
|
||||
const submission = await submissionRepository.findSubmissionByLearningObjectAndSubmissionNumber(id, 1);
|
||||
|
|
|
@ -61,7 +61,7 @@ export function makeTestGroups(em: EntityManager, students: Student[], assignmen
|
|||
*/
|
||||
group1ConditionalLearningPath = em.create(Group, {
|
||||
assignment: getConditionalPathAssignment(),
|
||||
groupNumber: 1,
|
||||
groupNumber: 21005,
|
||||
members: [getTestleerling1()],
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue