From 29aa7f505644f5f92552b20b28292c7d453cbe75 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Thu, 18 Jul 2024 09:36:30 +0200 Subject: [PATCH] adds isMitarbeiter to the new Profil FhcAPIController --- .../controllers/api/frontend/v1/Profil.php | 26 +++++- public/js/api/profil.js | 6 +- .../ProfilComponents/FetchProfilUpdates.js | 82 +------------------ 3 files changed, 29 insertions(+), 85 deletions(-) diff --git a/application/controllers/api/frontend/v1/Profil.php b/application/controllers/api/frontend/v1/Profil.php index 00e2b9219..ffb7449f8 100644 --- a/application/controllers/api/frontend/v1/Profil.php +++ b/application/controllers/api/frontend/v1/Profil.php @@ -36,6 +36,7 @@ class Profil extends FHCAPI_Controller 'fotoSperre' => self::PERM_LOGGED, 'getGemeinden' => self::PERM_LOGGED, 'getAllNationen' => self::PERM_LOGGED, + 'isMitarbeiter' => self::PERM_LOGGED, ]); @@ -160,7 +161,7 @@ class Profil extends FHCAPI_Controller $nation_res = $this->NationModel->load(); if (isError($nation_res)) { - show_error("error while trying to query table codex.tbl_nation"); + $this->terminateWithError("error while trying to query table codex.tbl_nation", self::ERROR_TYPE_GENERAL); } $nation_res = $this->getDataOrTerminateWithError($nation_res); @@ -278,6 +279,29 @@ class Profil extends FHCAPI_Controller return $res; } + /** + * checks whether a specific userID is a mitarbeiter or not (foreword declaration of the function isMitarbeiter in Mitarbeiter_model.php) + * @access public + * @param $uid the userID used to check if it is a mitarbeiter + * @return boolean + */ + public function isMitarbeiter($uid) + { + + if(!$uid) $this->terminateWithError("No uid provided", self::ERROR_TYPE_GENERAL); + + + $result = $this->MitarbeiterModel->isMitarbeiter($uid); + + if (isError($result)) { + $this->terminateWithError("error when calling Mitarbeiter_model function isMitarbeiter with uid " . $uid, self::ERROR_TYPE_GENERAL); + } + + $result = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($result); + } + /** * function that returns the data used for the mitarbeiter profile * @access private diff --git a/public/js/api/profil.js b/public/js/api/profil.js index eefe7d880..3cb9f34cd 100755 --- a/public/js/api/profil.js +++ b/public/js/api/profil.js @@ -33,10 +33,8 @@ export default { return this.$fhcApi.get( FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/api/frontend/v1/Profil/isMitarbeiter`, - { - uid:uid, - } + `/api/frontend/v1/Profil/isMitarbeiter/${uid}`, + {} ); }, diff --git a/public/js/components/Cis/Profil/ProfilComponents/FetchProfilUpdates.js b/public/js/components/Cis/Profil/ProfilComponents/FetchProfilUpdates.js index 0159f772b..9ae5c5a00 100755 --- a/public/js/components/Cis/Profil/ProfilComponents/FetchProfilUpdates.js +++ b/public/js/components/Cis/Profil/ProfilComponents/FetchProfilUpdates.js @@ -74,11 +74,9 @@ export default { files: files, }; - //?TODO: check if updateRequest.uid is a mitarbeiter, if so add the flag isMitarbeiter:true if (view === "EditAdresse") { - const isMitarbeiter = await Vue.$fhcapi.UserData.isMitarbeiter( - updateRequest.uid - ).then((res) => res.data); + + const isMitarbeiter = await this.$fhcApi.factory.profil.isMitarbeiter(updateRequest.uid).then((res)=>res.data); if (isMitarbeiter) { content["isMitarbeiter"] = isMitarbeiter; @@ -141,83 +139,7 @@ export default { } }, - // OLD way to open the editProfil modal, which was dynamically added to the html and then removed - async openModal(updateRequest) { - let view = this.getView(updateRequest.topic, updateRequest.status); - - let data = null; - let content = null; - let files = null; - let withFiles = false; - - if (view === "TextInputDokument") { - data = { - titel: updateRequest.topic, - value: updateRequest.requested_change.value, - }; - - const filesFromDatabase = - await Vue.$fhcapi.ProfilUpdate.getProfilRequestFiles( - updateRequest.profil_update_id - ).then((res) => { - return res.data; - }); - - files = filesFromDatabase; - if (files) { - withFiles = true; - } - } else { - data = updateRequest.requested_change; - } - - content = { - updateID: updateRequest.profil_update_id, - view: view, - data: data, - withFiles: withFiles, - topic: updateRequest.topic, - files: files, - }; - - //?TODO: check if updateRequest.uid is a mitarbeiter, if so add the flag isMitarbeiter:true - if (view === "EditAdresse") { - const isMitarbeiter = await Vue.$fhcapi.UserData.isMitarbeiter( - updateRequest.uid - ).then((res) => res.data); - - if (isMitarbeiter) { - content["isMitarbeiter"] = isMitarbeiter; - } - } - - //? adds the status information if the profil update request was rejected or accepted - if (updateRequest.status !== this.profilUpdateStates["Pending"]) { - content["status"] = updateRequest.status; - content["status_message"] = updateRequest.status_message; - content["status_timestamp"] = updateRequest.status_timestamp; - } - - //? only show the popup if also the right content is available - if (content) { - EditProfil.popup({ - value: content, - title: updateRequest.topic, - zustellkontakteCount: this.getZustellkontakteCount, - zustelladressenCount: this.getZustelladressenCount, - }) - .then((res) => { - if (res === true) { - this.$emit("fetchUpdates"); - } - }) - .catch((e) => { - // Wenn der User das Modal abbricht ohne Änderungen - }); - } - }, }, - created() {}, computed: {},