mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 20:29:29 +00:00
updates kontakt_id / adresse_id in profilUpdateRequest after inserting new kontakt/adresse in db
This commit is contained in:
@@ -115,7 +115,7 @@ class Profil extends Auth_Controller
|
||||
$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
|
||||
|
||||
echo json_encode(error("cannot change the same resource twice"));
|
||||
|
||||
@@ -38,63 +38,66 @@ class ProfilUpdate extends Auth_Controller
|
||||
}
|
||||
|
||||
public function acceptProfilRequest(){
|
||||
|
||||
$_POST = json_decode($this->input->raw_input_stream,true);
|
||||
|
||||
$id = $this->input->post('profil_update_id',true);
|
||||
$uid = $this->input->post('uid',true);
|
||||
|
||||
//? fetching person_id using UID
|
||||
$personID = $this->PersonModel->getByUid($uid);
|
||||
$personID = hasData($personID)? getData($personID)[0]->person_id : null;
|
||||
$status_message = $this->input->post('status_message',true);
|
||||
$topic = $this->input->post('topic',true);
|
||||
|
||||
//! somehow the xss check converted boolean false to empty string
|
||||
$requested_change = $this->input->post('requested_change');
|
||||
|
||||
|
||||
//! check for required information
|
||||
if(!isset($id) || !isset($uid) || !isset($personID) || !isset($requested_change) || !isset($topic)){
|
||||
return json_encode(error("missing required information"));
|
||||
}
|
||||
|
||||
|
||||
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)){
|
||||
$this->handleKontakt($requested_change, $personID);
|
||||
$resID = $this->handleKontakt($requested_change, $personID);
|
||||
$resID = hasData($resID) ? getData($resID)[0] : null;
|
||||
$requested_change['kontakt_id'] = $resID;
|
||||
|
||||
}else{
|
||||
|
||||
|
||||
switch($topic){
|
||||
case "titel": $topic ="titelpre"; break;
|
||||
case "postnomen": $topic = "titelpost"; break;
|
||||
}
|
||||
$res = $this->PersonModel->update($personID,[$topic=>$requested_change]);
|
||||
|
||||
echo json_encode($res);
|
||||
$result = $this->PersonModel->update($personID,[$topic=>$requested_change]);
|
||||
if(isError($result)){
|
||||
echo json_encode($result);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
echo json_encode($this->setStatusOnUpdateRequest($id, "accepted", $status_message));
|
||||
|
||||
|
||||
echo json_encode($this->setStatusOnUpdateRequest($id, "accepted", $status_message, $requested_change));
|
||||
}
|
||||
|
||||
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);
|
||||
$status_message = $this->input->post('status_message',true);
|
||||
|
||||
|
||||
echo json_encode($this->setStatusOnUpdateRequest($id, "rejected", $status_message));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function setStatusOnUpdateRequest($id, $status, $status_message){
|
||||
return $this->ProfilChangeModel->update([$id],["status"=>$status,"status_timestamp"=>"NOW()","status_message"=>$status_message]);
|
||||
private function setStatusOnUpdateRequest($id, $status, $status_message, $requested_change=NULL){
|
||||
$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){
|
||||
$kontakt_id = $requested_change["kontakt_id"];
|
||||
//? 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
|
||||
this.topic = this.editData.topic;
|
||||
}
|
||||
console.log("here",this.editData);
|
||||
|
||||
|
||||
},
|
||||
|
||||
@@ -134,7 +134,7 @@ export default {
|
||||
created() {
|
||||
this.data = JSON.parse(JSON.stringify(this.list.data));
|
||||
this.view = JSON.parse(JSON.stringify(this.list.view));
|
||||
|
||||
|
||||
|
||||
},
|
||||
mounted() {
|
||||
|
||||
@@ -278,7 +278,7 @@ export default {
|
||||
view:"text_input",
|
||||
data:{
|
||||
titel:"postnomen",
|
||||
value:this.data.titel,
|
||||
value:this.data.postnomen,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -40,7 +40,6 @@ export default {
|
||||
}
|
||||
},
|
||||
openModal(updateRequest) {
|
||||
console.log(JSON.stringify(updateRequest));
|
||||
|
||||
let view = this.getView(updateRequest.topic,updateRequest.status);
|
||||
let data = null;
|
||||
@@ -74,7 +73,6 @@ export default {
|
||||
content['status_timestamp']=updateRequest.status_timestamp;
|
||||
}
|
||||
|
||||
|
||||
//? only show the popup if also the right content is available
|
||||
if(content){
|
||||
EditProfil.popup({
|
||||
|
||||
@@ -1,10 +1,31 @@
|
||||
export default {
|
||||
import Adresse from "./Adresse.js";
|
||||
import Kontakt from "./Kontakt.js";
|
||||
|
||||
export default {
|
||||
components:{
|
||||
Adresse,
|
||||
Kontakt,
|
||||
},
|
||||
data(){
|
||||
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:{
|
||||
data:{type:Object},
|
||||
view:{type:String},
|
||||
@@ -12,11 +33,12 @@ export default {
|
||||
status_message:{type:String},
|
||||
status_timestamp:{type:String},
|
||||
update:{type:Boolean},
|
||||
topic:{type:String},
|
||||
},
|
||||
created(){
|
||||
|
||||
|
||||
},template:`
|
||||
|
||||
<div class="form-underline mb-2">
|
||||
<div class="form-underline-titel">Status</div>
|
||||
<span class="form-underline-content">{{status}} </span>
|
||||
@@ -30,6 +52,22 @@ export default {
|
||||
<div class="form-underline mb-2">
|
||||
<div class="form-underline-titel">Date</div>
|
||||
<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>
|
||||
`,
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user