updates kontakt_id / adresse_id in profilUpdateRequest after inserting new kontakt/adresse in db

This commit is contained in:
SimonGschnell
2024-01-25 16:43:47 +01:00
parent 20672cd311
commit 15cd9155f1
7 changed files with 68 additions and 30 deletions
+1 -1
View File
@@ -115,7 +115,7 @@ class Profil extends Auth_Controller
$existing_change = json_decode($update_request->requested_change); $existing_change = json_decode($update_request->requested_change);
if(property_exists($existing_change,$type) && property_exists($payload,$type) && $existing_change->$type == $payload->$type){ if(!isset($existing_change->add) && property_exists($existing_change,$type) && property_exists($payload,$type) && $existing_change->$type == $payload->$type){
//? the kontakt_id / adresse_id of a change has to be unique //? the kontakt_id / adresse_id of a change has to be unique
echo json_encode(error("cannot change the same resource twice")); echo json_encode(error("cannot change the same resource twice"));
+23 -20
View File
@@ -38,15 +38,17 @@ class ProfilUpdate extends Auth_Controller
} }
public function acceptProfilRequest(){ public function acceptProfilRequest(){
$_POST = json_decode($this->input->raw_input_stream,true);
$_POST = json_decode($this->input->raw_input_stream,true);
$id = $this->input->post('profil_update_id',true); $id = $this->input->post('profil_update_id',true);
$uid = $this->input->post('uid',true); $uid = $this->input->post('uid',true);
//? fetching person_id using UID //? fetching person_id using UID
$personID = $this->PersonModel->getByUid($uid); $personID = $this->PersonModel->getByUid($uid);
$personID = hasData($personID)? getData($personID)[0]->person_id : null; $personID = hasData($personID)? getData($personID)[0]->person_id : null;
$status_message = $this->input->post('status_message',true); $status_message = $this->input->post('status_message',true);
$topic = $this->input->post('topic',true); $topic = $this->input->post('topic',true);
//! somehow the xss check converted boolean false to empty string //! somehow the xss check converted boolean false to empty string
$requested_change = $this->input->post('requested_change'); $requested_change = $this->input->post('requested_change');
@@ -55,46 +57,47 @@ class ProfilUpdate extends Auth_Controller
return json_encode(error("missing required information")); return json_encode(error("missing required information"));
} }
if(is_array($requested_change) && array_key_exists("adresse_id",$requested_change)){ if(is_array($requested_change) && array_key_exists("adresse_id",$requested_change)){
$this->handleAdresse($requested_change, $personID); $resID = $this->handleAdresse($requested_change, $personID);
$resID = hasData($resID) ? getData($resID) : null;
$requested_change['adresse_id'] = $resID;
}else if (is_array($requested_change) && array_key_exists("kontakt_id", $requested_change)){ }else if (is_array($requested_change) && array_key_exists("kontakt_id", $requested_change)){
$this->handleKontakt($requested_change, $personID); $resID = $this->handleKontakt($requested_change, $personID);
$resID = hasData($resID) ? getData($resID)[0] : null;
$requested_change['kontakt_id'] = $resID;
}else{ }else{
switch($topic){ switch($topic){
case "titel": $topic ="titelpre"; break; case "titel": $topic ="titelpre"; break;
case "postnomen": $topic = "titelpost"; break; case "postnomen": $topic = "titelpost"; break;
} }
$res = $this->PersonModel->update($personID,[$topic=>$requested_change]); $result = $this->PersonModel->update($personID,[$topic=>$requested_change]);
if(isError($result)){
echo json_encode($res); echo json_encode($result);
return;
}
} }
echo json_encode($this->setStatusOnUpdateRequest($id, "accepted", $status_message, $requested_change));
echo json_encode($this->setStatusOnUpdateRequest($id, "accepted", $status_message));
} }
public function denyProfilRequest(){ public function denyProfilRequest(){
$_POST = json_decode($this->input->raw_input_stream,true);
$_POST = json_decode($this->input->raw_input_stream,true);
$id = $this->input->post('profil_update_id',true); $id = $this->input->post('profil_update_id',true);
$status_message = $this->input->post('status_message',true); $status_message = $this->input->post('status_message',true);
echo json_encode($this->setStatusOnUpdateRequest($id, "rejected", $status_message)); echo json_encode($this->setStatusOnUpdateRequest($id, "rejected", $status_message));
} }
private function setStatusOnUpdateRequest($id, $status, $status_message){ private function setStatusOnUpdateRequest($id, $status, $status_message, $requested_change=NULL){
return $this->ProfilChangeModel->update([$id],["status"=>$status,"status_timestamp"=>"NOW()","status_message"=>$status_message]); $update = ["status"=>$status,"status_timestamp"=>"NOW()","status_message"=>$status_message];
if(isset($requested_change)) { $update['requested_change'] = $requested_change; }
return $this->ProfilChangeModel->update([$id], $update);
} }
private function handleKontakt($requested_change, $personID){ private function handleKontakt($requested_change, $personID){
$kontakt_id = $requested_change["kontakt_id"]; $kontakt_id = $requested_change["kontakt_id"];
//? removes the kontakt_id because we don't want to update the kontakt_id in the database //? removes the kontakt_id because we don't want to update the kontakt_id in the database
@@ -69,7 +69,6 @@ export default {
//? if the topic was passed through the prop add it to the component //? if the topic was passed through the prop add it to the component
this.topic = this.editData.topic; this.topic = this.editData.topic;
} }
console.log("here",this.editData);
}, },
@@ -278,7 +278,7 @@ export default {
view:"text_input", view:"text_input",
data:{ data:{
titel:"postnomen", titel:"postnomen",
value:this.data.titel, value:this.data.postnomen,
} }
}, },
} }
@@ -40,7 +40,6 @@ export default {
} }
}, },
openModal(updateRequest) { openModal(updateRequest) {
console.log(JSON.stringify(updateRequest));
let view = this.getView(updateRequest.topic,updateRequest.status); let view = this.getView(updateRequest.topic,updateRequest.status);
let data = null; let data = null;
@@ -74,7 +73,6 @@ export default {
content['status_timestamp']=updateRequest.status_timestamp; content['status_timestamp']=updateRequest.status_timestamp;
} }
//? only show the popup if also the right content is available //? only show the popup if also the right content is available
if(content){ if(content){
EditProfil.popup({ EditProfil.popup({
@@ -1,10 +1,31 @@
export default { import Adresse from "./Adresse.js";
import Kontakt from "./Kontakt.js";
export default {
components:{
Adresse,
Kontakt,
},
data(){ data(){
return { return {
} }
}, },
computed:{
getComponentView: function(){
let title = this.topic.toLowerCase();
if(title.includes("adressen")) return "Adresse";
else if(title.includes("kontakte"))return "Kontakt";
else return "text_input";
},
cardHeader: function(){
let title = this.topic.toLowerCase();
if(title.includes("delete")) return "Delete";
else if(title.includes("add")) return "Add";
else return "Update";
}
},
props:{ props:{
data:{type:Object}, data:{type:Object},
view:{type:String}, view:{type:String},
@@ -12,11 +33,12 @@ export default {
status_message:{type:String}, status_message:{type:String},
status_timestamp:{type:String}, status_timestamp:{type:String},
update:{type:Boolean}, update:{type:Boolean},
topic:{type:String},
}, },
created(){ created(){
},template:` },template:`
<div class="form-underline mb-2"> <div class="form-underline mb-2">
<div class="form-underline-titel">Status</div> <div class="form-underline-titel">Status</div>
<span class="form-underline-content">{{status}} </span> <span class="form-underline-content">{{status}} </span>
@@ -30,6 +52,22 @@ export default {
<div class="form-underline mb-2"> <div class="form-underline mb-2">
<div class="form-underline-titel">Date</div> <div class="form-underline-titel">Date</div>
<span class="form-underline-content">{{status_timestamp}} </span> <span class="form-underline-content">{{status_timestamp}} </span>
</div>`, </div>
<div class="card mt-4">
<div class="card-header">
<i class="fa" :class="{'fa-trash':cardHeader==='Delete', 'fa-edit':cardHeader==='Update', 'fa-plus':cardHeader==='Add'}" ></i>
{{cardHeader}}
</div>
<div class="card-body">
<div v-if="getComponentView === 'text_input'" class="form-underline mb-2">
<div class="form-underline-titel">{{topic}}</div>
<span class="form-underline-content">{{data}} </span>
</div>
<component v-else :is="getComponentView" :data="data"></component>
</div>
</div>
`,
} }