fix: assignment verwijderen gefixd

This commit is contained in:
Joyelle Ndagijimana 2025-04-22 08:55:50 +02:00
parent fac31b3f64
commit a963cf472c
2 changed files with 14 additions and 16 deletions

View file

@ -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 {Class} from '../classes/class.entity.js';
import {Group} from './group.entity.js'; import {Group} from './group.entity.js';
import {Language} from '@dwengo-1/common/util/language'; import {Language} from '@dwengo-1/common/util/language';
@ -34,6 +34,7 @@ export class Assignment {
@OneToMany({ @OneToMany({
entity: () => Group, entity: () => Group,
mappedBy: 'assignment', mappedBy: 'assignment',
cascade: [Cascade.ALL]
}) })
groups: Collection<Group> = new Collection<Group>(this); groups: Collection<Group> = new Collection<Group>(this);
} }

View file

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, onMounted, watch } from "vue"; import { ref, computed, onMounted } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
import auth from "@/services/auth/auth-service.ts"; import auth from "@/services/auth/auth-service.ts";
@ -30,6 +30,7 @@
//TODO: remove later //TODO: remove later
const classController = new ClassController(); const classController = new ClassController();
const deletedAssignments = ref<Set<number>>(new Set());
//TODO: replace by query that fetches all user's assignment //TODO: replace by query that fetches all user's assignment
const assignments = asyncComputed(async () => { const assignments = asyncComputed(async () => {
const classes = classesQueryResults?.data?.value?.classes; const classes = classesQueryResults?.data?.value?.classes;
@ -49,7 +50,7 @@
}), }),
); );
return result.flat(); return result.flat().filter(a => !deletedAssignments.value.has(a.id));
}, []); }, []);
async function goToCreateAssignment(): Promise<void> { async function goToCreateAssignment(): Promise<void> {
@ -60,17 +61,13 @@
await router.push(`/assignment/${clsId}/${id}`); await router.push(`/assignment/${clsId}/${id}`);
} }
const { mutate, isSuccess } = useDeleteAssignmentMutation(); const { mutate } = useDeleteAssignmentMutation();
watch(isSuccess, async (success) => {
if (success) {
await router.push("/user/assignment");
}
});
async function goToDeleteAssignment(num: number, clsId: string): Promise<void> { async function goToDeleteAssignment(num: number, clsId: string): Promise<void> {
mutate({ mutate({ cid: clsId, an: num }, {
cid: clsId, onSuccess: () => {
an: num, deletedAssignments.value.add(num);
},
}); });
} }