adds functionality to delete a Kontakt or an Adress

This commit is contained in:
SimonGschnell
2024-01-17 12:07:06 +01:00
parent b53dec6a31
commit a5c77543b1
6 changed files with 58 additions and 37 deletions
+21 -4
View File
@@ -97,16 +97,33 @@ class Profil extends Auth_Controller
$res = $this->ProfilChangeModel->loadWhere(["uid"=>$this->uid]);
$res = hasData($res) ? getData($res) : null;
//? checks if the user already made a request to change a topic
//! which is an constraint added to the public.tbl_cis_profil_update table
if($res){
//* Exception: a user can have multiple delete or add requests
foreach($res as $update_request){
if($update_request->topic == $json->topic && $update_request->uid == $this->uid){
//TODO: Check if a change request already exists before adding the delete request
if(property_exists($json->payload, "delete")){
if(json_decode($update_request->requested_change) == $json->payload){
//? Check if the delete request for this resource already exists before adding the new delete request
echo json_encode(error("this delete request already exists"));
return;
}
}elseif(property_exists($json->payload, "add")){
}elseif($update_request->topic == $json->topic && $update_request->uid == $this->uid){
echo json_encode(error("uid and topic combination exists already"));
return;
}
}}
}
$insert_res = $this->ProfilChangeModel->insert($data);
+8 -27
View File
@@ -38,17 +38,15 @@ export default {
},
methods: {
submitProfilChange(){
if(this.topic && this.profilUpdate){
//? inserts new row in public.tbl_cis_profil_update
if(this.editData.update){
Vue.$fhcapi.UserData.updateProfilRequest(this.topic,this.profilUpdate).then((res)=>{
//* calls the update api call if an update field is present in the data that was passed to the module
Vue.$fhcapi.UserData[this.editData.update?'updateProfilRequest':'insertProfilRequest'](this.topic,this.profilUpdate).then((res)=>{
console.log("topic",this.topic);
console.log("profilUpdate",this.profilUpdate);
if(res.data.error == 0){
this.result= true;
this.hide();
@@ -60,26 +58,6 @@ export default {
}
});
}else{
Vue.$fhcapi.UserData.insertProfilRequest(this.topic,this.profilUpdate).then((res)=>{
if(res.data.error == 0){
this.result= true;
this.hide();
Alert.popup("Ihre Anfrage wurde erfolgreich gesendet. Bitte warten Sie, während sich das Team um Ihre Anfrage kümmert.");
}else{
this.result= false;
this.hide();
Alert.popup("Ein Fehler ist aufgetreten: "+ JSON.stringify(res.data.retval));
}
});
}
}
},
},
@@ -116,7 +94,10 @@ export default {
</ol>
</nav>
<edit-profil-select v-model:breadcrumb="breadcrumb" v-model:topic="topic" v-model:profilUpdate="profilUpdate" ariaLabel="test" :list="editData"></edit-profil-select>
<pre>{{JSON.stringify(profilUpdate,null,2)}}</pre>
<pre>{{JSON.stringify(topic,null,2)}}</pre>
<edit-profil-select @submit="submitProfilChange" v-model:breadcrumb="breadcrumb" v-model:topic="topic" v-model:profilUpdate="profilUpdate" ariaLabel="test" :list="editData"></edit-profil-select>
</template>
@@ -34,6 +34,7 @@ export default {
['update:profilUpdate']:null,
['update:topic']:null,
['update:breadcrumb']:null,
submit:null,
select:null,
},
@@ -46,6 +47,16 @@ export default {
},
methods: {
deleteItem: function(item){
let data = item.data;
data.delete = true;
this.$emit('update:profilUpdate',item.data);
//? updates the topic when a Kontakt or an Address should be deleted
this.$emit('update:topic',item.data.kontakt?"Delete Kontakte":"Delete Adressen");
this.$emit('submit');
},
profilUpdateEmit: function(event){
console.log(event);
//? passes the updated profil information to the parent component
@@ -92,11 +103,15 @@ export default {
<div v-if="!view" class="list-group">
<button type="button" class=" list-group-item list-group-item-action" @click="updateOptions($event,item)" v-for="item in data">
<button style="position:relative" type="button" class=" list-group-item list-group-item-action" @click="updateOptions($event,item)" v-for="item in data">
<p v-if="item.title" class="my-1" >{{item.title}}</p>
<!-- this is used for multiple elements in the select -->
<component class="my-2" :is="item.listview" v-bind="item"></component>
<div class="my-2 me-4" v-else>
<component :is="item.listview" v-bind="item"></component>
<i @click="deleteItem(item)" style="color:lightcoral; position:absolute; top:10px; right:10px;" class="fa fa-trash"></i>
</div>
</button>
</div>
@@ -325,6 +325,9 @@ export default {
};
console.log(JSON.stringify(this.data.editData,null,2));
},
mounted() {
@@ -10,7 +10,7 @@ const Adresse = {
},
template:`
<div class="my-2 row justify-content-center align-items-center">
<div class="gy-2 row justify-content-center align-items-center">
<!-- column 1 in the address row -->
@@ -166,6 +166,9 @@ const Kontakt = {
<i v-if="data.zustellung" class="fa-solid fa-check"></i>
<i v-else="data.zustellung" class="fa-solid fa-xmark"></i>
</div>
</div>
</div>
@@ -344,13 +347,14 @@ const FetchProfilUpdates = {
},
template:`
<pre>{{JSON.stringify(data,null,2)}}</pre>
<div class="table-responsive">
<table class="m-0 table table-hover">
<thead>
<tr >
<th scope="col">Topic</th>
<th scope="col">Date of Request</th>
<th scope="col">Bearbeiten</th>
<th scope="col">Bearbeiten</th>
<th style="white-space:normal" scope="col">Löschen</th>
</tr>
</thead>
@@ -358,7 +362,8 @@ const FetchProfilUpdates = {
<tr v-for="item in data">
<td class="align-middle">{{item.topic}}</td>
<td class="align-middle">{{item.change_timestamp}}</td>
<td class="align-middle text-center" ><i style="color:#00639c" @click="openModal(item)" role="button" class="fa fa-edit"></i></td>
<td v-if="item.topic.toLowerCase().includes('delete')" class="align-middle text-center" >{{item.requested_change.adr_typ?item.requested_change.adr_typ:item.requested_change.kontakt}}</td>
<td v-else class="align-middle text-center" ><i style="color:#00639c" @click="openModal(item)" role="button" class="fa fa-edit"></i></td>
<td class="align-middle text-center"><i style="color:red" role="button" @click="deleteRequest(item)" class="fa fa-trash"></i></td>
</tr>
</tbody>
+1 -1
View File
@@ -19,7 +19,7 @@
CACHE 1;
ALTER TABLE public.tbl_cis_profil_update ALTER COLUMN profil_update_id SET DEFAULT nextval('public.tbl_cis_profil_update_id_seq');
ALTER TABLE public.tbl_cis_profil_update ADD CONSTRAINT cis_profil_udpate_topic_uid_unique UNIQUE (uid,topic);
--ALTER TABLE public.tbl_cis_profil_update ADD CONSTRAINT cis_profil_udpate_topic_uid_unique UNIQUE (uid,topic);
GRANT SELECT, INSERT, UPDATE, DELETE ON public.tbl_cis_profil_update TO vilesci;
GRANT SELECT, INSERT, UPDATE, DELETE ON public.tbl_cis_profil_update TO web;