fix(backend): Update MikroORM, Fix voor 'pks not iterable' problem in Groups

This commit is contained in:
Gerald Schmittinger 2025-04-15 11:03:41 +02:00
parent 451ac7546f
commit 9c638b11f6
5 changed files with 57 additions and 53 deletions

View file

@ -35,5 +35,5 @@ export class Assignment {
entity: () => Group,
mappedBy: 'assignment',
})
groups!: Collection<Group>;
groups: Collection<Group> = new Collection<Group>(this);
}

View file

@ -7,15 +7,19 @@ import { GroupRepository } from '../../data/assignments/group-repository.js';
repository: () => GroupRepository,
})
export class Group {
@ManyToOne({
entity: () => Assignment,
primary: true,
})
assignment!: Assignment;
/*
WARNING: Don't move the definition of groupNumber! If it does not come before the definition of assignment,
creating groups fails because of a MikroORM bug!
*/
@PrimaryKey({ type: 'integer', autoincrement: true })
groupNumber?: number;
@ManyToOne({
entity: () => Assignment,
primary: true
})
assignment!: Assignment;
@ManyToMany({
entity: () => Student,
owner: true,

View file

@ -1,6 +1,6 @@
import { Group } from '../entities/assignments/group.entity.js';
import { Class } from '../entities/classes/class.entity.js';
import { mapToAssignmentDTO } from './assignment.js';
import {mapToAssignmentDTOId} from './assignment.js';
import { mapToClassDTO } from './class.js';
import { mapToStudentDTO } from './student.js';
import { GroupDTO } from '@dwengo-1/common/interfaces/group';
@ -8,7 +8,7 @@ import { GroupDTO } from '@dwengo-1/common/interfaces/group';
export function mapToGroupDTO(group: Group, cls: Class): GroupDTO {
return {
class: mapToClassDTO(cls),
assignment: mapToAssignmentDTO(group.assignment),
assignment: mapToAssignmentDTOId(group.assignment),
groupNumber: group.groupNumber!,
members: group.members.map(mapToStudentDTO),
};