From 219616f4ee1bb7005da9b3ca8a8c62ca4ec35fb4 Mon Sep 17 00:00:00 2001 From: Joyelle Ndagijimana Date: Wed, 23 Apr 2025 20:53:00 +0200 Subject: [PATCH] fix: foreignKey violation bij delete assignment gefixd --- backend/src/entities/assignments/group.entity.ts | 3 +-- .../src/entities/assignments/submission.entity.ts | 6 +++--- .../src/views/assignments/CreateAssignment.vue | 15 ++++++++++----- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/backend/src/entities/assignments/group.entity.ts b/backend/src/entities/assignments/group.entity.ts index cf4d172a..c877e202 100644 --- a/backend/src/entities/assignments/group.entity.ts +++ b/backend/src/entities/assignments/group.entity.ts @@ -1,4 +1,4 @@ -import {Cascade, 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'; @@ -24,7 +24,6 @@ export class Group { entity: () => Student, owner: true, inversedBy: 'groups', - cascade: [Cascade.ALL], }) members: Collection = new Collection(this); } diff --git a/backend/src/entities/assignments/submission.entity.ts b/backend/src/entities/assignments/submission.entity.ts index 4018c3af..b19a99eb 100644 --- a/backend/src/entities/assignments/submission.entity.ts +++ b/backend/src/entities/assignments/submission.entity.ts @@ -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; diff --git a/frontend/src/views/assignments/CreateAssignment.vue b/frontend/src/views/assignments/CreateAssignment.vue index 0843891b..32cda330 100644 --- a/frontend/src/views/assignments/CreateAssignment.vue +++ b/frontend/src/views/assignments/CreateAssignment.vue @@ -75,12 +75,17 @@ const { valid } = await form.value.validate(); if (!valid) return; + let lp = selectedLearningPath.value; + if (!lpIsSelected) { + lp = selectedLearningPath.value?.hruid; + } + const assignmentDTO: AssignmentDTO = { id: 0, within: selectedClass.value?.id || "", title: assignmentTitle.value, description: description.value, - learningPath: selectedLearningPath.value?.hruid || "", + learningPath: lp || "", language: language.value, groups: groups.value, }; @@ -188,14 +193,14 @@ color="secondary" type="submit" block - >{{ t("submit") }} + >{{ t("submit") }} + {{ t("cancel") }} + >{{ t("cancel") }} +