Adamtpacz / sei-pets-alive

🐶 Full-stack dog adoption app built with JavaScript/Node.js, Express.js, MongoDB, and Google Cloud Platform
https://sei-pets-alive.herokuapp.com/dogs
1 stars 0 forks source link

Glow Snippet #36

Open Adamtpacz opened 1 year ago

Adamtpacz commented 1 year ago

Code - Application Creation Controller Function

function create(req, res) {
    Dog.findById(req.params.id)
        .then(function (dog) {
            Application.create({
                name: req.body.name,
                phone: req.body.phone,
                emailAddress: req.body.emailAddress,
                numberOfPets: req.body.numberOfPets,
                address: req.body.address,
                message: req.body.message,
                dog: dog._id,
                user: req.user._id,
                userName: req.user.name,
                userAvatar: req.user.avatar
            }).then(function () {
                res.redirect(`/dogs/${req.params.id}`)
            })
                .catch(function (err) {
                    console.log(err)
                    res.redirect(`/dogs/${req.params.id}`)
                })
        }).catch(function (err) {
            console.log(err)
            res.redirect(`/dogs/${req.params.id}`)

        })
}

Comments