fix(backend): Foreign constraint probleem bij het verwijderen van leerpaden opgelost

This commit is contained in:
Gerald Schmittinger 2025-05-13 22:51:16 +02:00
parent 63cf60409f
commit 9400b7f33c
7 changed files with 20 additions and 16 deletions

View file

@ -9,6 +9,7 @@ export class Attachment {
@ManyToOne({ @ManyToOne({
entity: () => LearningObject, entity: () => LearningObject,
primary: true, primary: true,
deleteRule: 'cascade'
}) })
learningObject!: LearningObject; learningObject!: LearningObject;

View file

@ -1,6 +1,5 @@
import { import {
ArrayType, ArrayType,
Cascade,
Collection, Collection,
Embedded, Embedded,
Entity, Entity,
@ -93,8 +92,7 @@ export class LearningObject {
@OneToMany({ @OneToMany({
entity: () => Attachment, entity: () => Attachment,
mappedBy: 'learningObject', mappedBy: 'learningObject'
cascade: [Cascade.ALL]
}) })
attachments: Collection<Attachment> = new Collection<Attachment>(this); attachments: Collection<Attachment> = new Collection<Attachment>(this);

View file

@ -72,8 +72,6 @@ const learningObjectService = {
learningObject.hruid = getEnvVar(envVars.UserContentPrefix) + learningObject.hruid; learningObject.hruid = getEnvVar(envVars.UserContentPrefix) + learningObject.hruid;
} }
await learningObjectRepository.getEntityManager().flush();
// Lookup the admin teachers based on their usernames and add them to the admins of the learning object. // Lookup the admin teachers based on their usernames and add them to the admins of the learning object.
const teacherRepo = getTeacherRepository(); const teacherRepo = getTeacherRepository();
const adminTeachers = await Promise.all( const adminTeachers = await Promise.all(
@ -85,7 +83,13 @@ const learningObjectService = {
} }
}); });
try {
await learningObjectRepository.save(learningObject, {preventOverwrite: true}); await learningObjectRepository.save(learningObject, {preventOverwrite: true});
} catch (e: unknown) {
learningObjectRepository.getEntityManager().clear();
throw e;
}
return learningObject; return learningObject;
}, },

View file

@ -138,5 +138,6 @@
"open": "open", "open": "open",
"editLearningPath": "Edit learning path", "editLearningPath": "Edit learning path",
"newLearningPath": "Create a new learning path", "newLearningPath": "Create a new learning path",
"saveChanges": "Save changes" "saveChanges": "Save changes",
"newLearningObject": "Upload learning object"
} }

View file

@ -32,7 +32,13 @@
<template> <template>
<v-dialog max-width="500" v-model="dialogOpen"> <v-dialog max-width="500" v-model="dialogOpen">
<template v-slot:activator="{ props: activatorProps }"> <template v-slot:activator="{ props: activatorProps }">
<v-fab icon="mdi mdi-plus" v-bind="activatorProps" color="rgb(14, 105, 66)" size="large"></v-fab> <v-btn
prepend-icon="mdi mdi-plus"
:text="t('newLearningObject')"
v-bind="activatorProps"
color="rgb(14, 105, 66)"
size="large">
</v-btn>
</template> </template>
<template v-slot:default="{ isActive }"> <template v-slot:default="{ isActive }">

View file

@ -30,6 +30,7 @@
<template> <template>
<div class="root"> <div class="root">
<div class="table-container"> <div class="table-container">
<learning-object-upload-button/>
<v-data-table <v-data-table
class="table" class="table"
v-model="selectedLearningObjects" v-model="selectedLearningObjects"
@ -44,17 +45,9 @@
<learning-object-preview-card class="preview" :selectedLearningObject="selectedLearningObject"/> <learning-object-preview-card class="preview" :selectedLearningObject="selectedLearningObject"/>
</div> </div>
</div> </div>
<div class="fab">
<learning-object-upload-button/>
</div>
</template> </template>
<style scoped> <style scoped>
.fab {
position: absolute;
right: 20px;
bottom: 20px;
}
.root { .root {
display: flex; display: flex;
gap: 20px; gap: 20px;
@ -73,5 +66,6 @@
} }
.table { .table {
width: 100%; width: 100%;
margin-top: 20px;
} }
</style> </style>