Fix Deletion Constraint (No Child)

This commit is contained in:
jbrass 2025-02-10 00:57:17 +01:00
parent 7a35c951ed
commit a8d390ffe3

View file

@ -247,7 +247,15 @@ namespace util
if (this->tasks.count(id) == 0) if (this->tasks.count(id) == 0)
throw Error(402, "Eine solche Aufgabe existiert nicht."); throw Error(402, "Eine solche Aufgabe existiert nicht.");
if (!this->get_assignments_for_task(id).empty()) { if (!this->get_assignments_for_task(id).empty()) {
throw Error(201, "Aufgabe kann nicht gelöscht werden."); throw Error(202, "Aufgabe kann nicht gelöscht werden.");
}
//TODO: Zudem kann eine Aufgabe nur gelöscht werden, wenn Sie nicht Nachfolgerin einer anderen Aufgabe ist -> Ensure its no Child
for (Task* task : this->get_tasks()) {
for (int child_id : task->get_children()) {
if (id == child_id) {
throw Error(202, "Aufgabe kann nicht gelöscht werden.");
}
}
} }
this->tasks.erase(id); this->tasks.erase(id);
} }