DEV Community

dev_phane
dev_phane

Posted on

How to save data from real-time database to Firebase and delete it in real-time database?

Below is my code to be able to save the data in the Firestore. Mais ça ne fonctionne pas
saveColis(key) {
if (this.access == 5 || this.access == 4 || this.access == 3) {
Swal.fire({
title: "Has the delivery been made?",
text: "The delivery will be saved forever!",
icon: "success",
showCancelButton: true,
confirmButtonColor: "#34B76E",
cancelButtonColor: "#BEBEBE",
cancelButtonText: "Non",
confirmButtonText: "Oui",
}).then(async (result) => {
if (result.isConfirmed) {
return db.ref("Colis Requetes").child(key).once("value").then(function (snapshot) {
snapshot.forEach(function (childSnapshot) {
let childData = childSnapshot.val();
dbstore.collection("delivery_completed").add({
client_name: childData.client_name,
client_phone: childData.client_phone,
colis_type: childData.colis_type,
contact_recup: childData.contact_recup,
created_at: childData.created_at,
depart_address: childData.depart_address,
dest_address: childData.depart_address,
dest_contact: childData.dest_contact,
id_colis: childData.id_colis,
livreur_id: childData.livreur_id,
montant: Number(childData.montant),
valeur: Number(childData.valeur),
nature: childData.nature,
categorie: childData.categorie,
payment_method: childData.payment_method,
boutique_id: childData.boutique_id,
statut: "delivered",
});
db.ref("Colis Requetes").child(key).remove(),
Swal.fire(
"Registered delivery!",
"The delivery has been registered successfully.",
"success"
);
});
});
}
});
} else {
const Toast = Swal.mixin({
toast: true,
position: "top-end",
showConfirmButton: false,
timer: 5000,
timerProgressBar: true,
didOpen: (toast) => {
toast.addEventListener("mouseenter", Swal.stopTimer);
toast.addEventListener("mouseleave", Swal.resumeTimer);
},
});
Toast.fire({
icon: "error",
title: '<span style="color:#B74334">Unauthorized action!</span>',
});
}
},

Top comments (0)