fixes bug when getting all the profil update requests and makes it possible to add a message when dening or accepting a profil update

This commit is contained in:
SimonGschnell
2024-01-23 11:00:43 +01:00
parent 7abe04a69f
commit df74bade9b
12 changed files with 133 additions and 64 deletions
+9 -6
View File
@@ -69,8 +69,11 @@ class Profil extends Auth_Controller
public function selectProfilRequest(){
$uid =json_decode($this->input->get("uid"));
$id =json_decode($this->input->get("id"));
$_GET = json_decode($this->input->raw_input_stream, true);
$uid = $this->input->get('uid');
$id = $this->input->get('id');
echo $uid;
echo $id;
if($uid && $id){
$res= $this->ProfilChangeModel->getProfilUpdate($uid, $id);
@@ -93,7 +96,8 @@ class Profil extends Auth_Controller
$json = json_decode($this->input->raw_input_stream);
$payload = $json->payload;
$type = isset($json->payload->kontakt_id)? "kontakt_id" : "adresse_id";
$type = property_exists($json->payload,"kontakt_id")? "kontakt_id" : "adresse_id";
$data = ["topic"=>$json->topic,"uid" => $this->uid, "requested_change" => json_encode($payload), "change_timestamp" => "NOW()","status"=>"pending" ];
@@ -104,10 +108,9 @@ class Profil extends Auth_Controller
if($res){
foreach($res as $update_request){
$existing_change = json_decode($update_request->requested_change);
echo json_encode($existing_change);
echo property_exists($existing_change,$type);
if(property_exists($existing_change,$type) && $existing_change->$type == $payload->$type){
if(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"));
+8 -12
View File
@@ -37,28 +37,24 @@ class ProfilUpdate extends Auth_Controller
public function acceptProfilRequest(){
$_POST = json_decode($this->input->raw_input_stream,true);
$id = $this->input->post('requestID',true);
$id = $this->input->post('profil_update_id',true);
$status_message = $this->input->post('status_message',true);
if(isset($id)){
$res =$this->ProfilChangeModel->update([$id], ["status"=>"accepted","status_timestamp"=>"NOW()"]);
$res =$this->ProfilChangeModel->update([$id], ["status"=>"accepted","status_timestamp"=>"NOW()","status_message"=>$status_message]);
echo json_encode($res);
}
}
}
public function denyProfilRequest(){
$_POST = json_decode($this->input->raw_input_stream,true);
$id = $this->input->post('requestID',true);
$id = $this->input->post('profil_update_id',true);
$status_message = $this->input->post('status_message',true);
if(isset($id)){
var_dump($id);
//! instead of deleting the rejected profil update, the status of the db entry is set to rejected
//$res = $this->ProfilChangeModel->delete([$id]);
$res = $this->ProfilChangeModel->update([$id],["status"=>"rejected","status_timestamp"=>"NOW()"]);
$res = $this->ProfilChangeModel->update([$id],["status"=>"rejected","status_timestamp"=>"NOW()","status_mesage"=>$status_message]);
echo json_encode($res);
}
@@ -49,6 +49,7 @@ class Profil_change_model extends DB_Model
foreach($res->retval as $update){
$update->requested_change = json_decode($update->requested_change);
$update->change_timestamp = date_create($update->change_timestamp)->format('d.m.Y');
$update->status_timestamp = date_create($update->status_timestamp)->format('d.m.Y');
}
}
}