// define route for deleting a restaurant router.delete('/:id', (req, res) => {
const reqId = req.params.id
// find the restaurant by id and delete it restaurantModel.findByIdAndRemove(reqId) .exec() .then(() => res.redirect('/')) .catch((error) => console.log(error)) })
// fire a event to swal for showing alert model Swal.fire({ title: `確定移除${restaurantName}嗎?`, showDenyButton: true, confirmButtonText: '確定移除', denyButtonText: '取消移除', }).then((result) => {
// If user click a button for confirming, it just send a request for deleting it if (result.isConfirmed) { Swal.fire('已移除', '', 'success') } else if (result.isDenied) { // If user click a button for cancelling, it just cancel execution of deleting it Swal.fire('別擔心,我沒移除喔 :>', '', 'info') } })
// fire a event to swal for showing alert model Swal.fire({ title: `確定移除${restaurantName}嗎?`, showDenyButton: true, confirmButtonText: '確定移除', denyButtonText: '取消移除', }).then((result) => {
// If user click a button for confirming, it just send a request for deleting it if (result.isConfirmed) { Swal.fire('已移除', '', 'success') // send a data to /restaurants/:id/delete via post method and redirect to / deleteForm.submit()
} else if (result.isDenied) { // If user click a button for cancelling, it just cancel execution of deleting it Swal.fire('別擔心,我沒移除喔 :>', '', 'info') } })
// If user click a button for confirming, it just send a request for deleting it if (result.isConfirmed) { Swal.fire('已移除', '', 'success') } else if (result.isDenied) { // If user click a button for cancelling, it just cancel execution of deleting it Swal.fire('別擔心,我沒移除喔 :>', '', 'info') event.preventDefault() // <- 放在這喔 event.stopPropagation() // <- 放在這喔 } })
// fire a event to swal for showing alert model Swal.fire({ title: `確定移除${restaurantName}嗎?`, showDenyButton: true, confirmButtonText: '確定移除', denyButtonText: '取消移除', }).then((result) => {
// If user click a button for confirming, it just send a request for deleting it if (result.isConfirmed) { Swal.fire('已移除', '', 'success') // send a data to /restaurants/:id/delete via post method and redirect to / deleteForm.submit()
} else if (result.isDenied) { // If user click a button for cancelling, it just cancel execution of deleting it Swal.fire('別擔心,我沒移除喔 :>', '', 'info')
// add sumbit event to each form (button) for deleting // when occuring submit event, it just showing another alert model // to remind user to make sure that each user really want to delete deleteForms.forEach(deleteForm => { ///.... })