From b21d3448cb85027565909b81caaf05fcfa5231fc Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Mon, 12 Feb 2024 09:07:51 +0100 Subject: [PATCH] fixes some data handling errors in controller functions --- application/controllers/Cis/ProfilUpdate.php | 8 ++++---- application/models/person/Profil_update_model.php | 1 + public/js/components/Cis/Profil/MitarbeiterProfil.js | 10 ++++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/application/controllers/Cis/ProfilUpdate.php b/application/controllers/Cis/ProfilUpdate.php index b2c2d3c1b..6f2aa2bc0 100755 --- a/application/controllers/Cis/ProfilUpdate.php +++ b/application/controllers/Cis/ProfilUpdate.php @@ -206,22 +206,22 @@ class ProfilUpdate extends Auth_Controller //? loops over all updateRequests from a user to validate if the new request is valid $res = $this->ProfilUpdateModel->getProfilUpdatesWhere(["uid"=>$this->uid]); - $res = hasData($res) ? getData($res) : null; if($res){ $pending_changes = array_filter($res, function($element) { return $element->status == 'pending'; }); foreach($pending_changes as $update_request){ - $existing_change = json_decode($update_request->requested_change); + $existing_change = $update_request->requested_change; //? the user can add as many new kontakt/adresse as he likes - if( !isset($payload->add) && property_exists($existing_change,$identifier) && property_exists($payload,$identifier) && $existing_change->$identifier == $payload->$identifier){ + + if( !isset($payload->add) && property_exists($existing_change,$identifier) && property_exists($payload,$identifier) && $existing_change->$identifier == $payload->$identifier){ //? the kontakt_id / adresse_id of a change has to be unique echo json_encode(error("cannot change the same resource twice")); return; } - + elseif(!$identifier && $update_request->topic == $json->topic ){ //? if it is not a delete or add request than the topic has to be unique echo json_encode(error("A request to change " . $json->topic . " is already open")); diff --git a/application/models/person/Profil_update_model.php b/application/models/person/Profil_update_model.php index f9aa59c1c..05643af59 100755 --- a/application/models/person/Profil_update_model.php +++ b/application/models/person/Profil_update_model.php @@ -51,6 +51,7 @@ class Profil_update_model extends DB_Model //? queries the tbl_profil_updates without permissions of the user public function getProfilUpdatesWhere($whereClause){ + $res = $this->loadWhere($whereClause); if(isError($res)){ return error("Could not load public.tbl_profil_update with whereClause"); diff --git a/public/js/components/Cis/Profil/MitarbeiterProfil.js b/public/js/components/Cis/Profil/MitarbeiterProfil.js index db650ec7a..a17c9a235 100755 --- a/public/js/components/Cis/Profil/MitarbeiterProfil.js +++ b/public/js/components/Cis/Profil/MitarbeiterProfil.js @@ -149,7 +149,7 @@ export default { Vue.$fhcapi.ProfilUpdate.selectProfilRequest().then((res)=>{ if(!res.error){ - this.data.profilUpdates = res.data.retval?.length ? res.data.retval.sort(this.sortProfilUpdates) : null ; + this.data.profilUpdates = res.data?.length ? res.data.sort(this.sortProfilUpdates) : null ; } }); }, @@ -164,14 +164,16 @@ export default { Vue.$fhcapi.ProfilUpdate.selectProfilRequest() .then((res) =>{ if(!res.error){ - this.data.profilUpdates = res.data.retval; + this.data.profilUpdates = res.data; this.data.profilUpdates.sort(this.sortProfilUpdates); }else{ - alert("Error when fetching profile updates: " +res.data.retval); + console.log("Error when fetching profile updates: " +res.data); } }) - .catch(err=>alert(err)); + .catch(err=>{ + console.log(err); + }); } }).catch((e) => { // Wenn der User das Modal abbricht ohne Änderungen