createThought({ body }, res) {
        Thought.create(body)
            .then(({ _id }) => {
                return User.findOneAndUpdate({
                    _id: body.userId
                }, {
                    $push: { thoughts: _id }
                }, {
                    new: true
                });
            })
            .then(dbUserData => {
                if (!dbUserData) {
                    res.status(404).json({ message: 'No user found with this id.' });
                    return;
                }
                res.json(dbUserData)
            })
            .catch(err => res.json(err));
    }
// create a thought by a user
create a thought by a user
create a thought by a user
createThought({ body }, res) {
        Thought.create(body)
            .then(({ _id }) => {
                return User.findOneAndUpdate({
                    _id: body.userId
                }, {
                    $push: { thoughts: _id }
                }, {
                    new: true
                });
            })
            .then(dbUserData => {
                if (!dbUserData) {
                    res.status(404).json({ message: 'No user found with this id.' });
                    return;
                }
                res.json(dbUserData)
            })
            .catch(err => res.json(err));
    }
createThought ( { body } , res ) { Thought . create ( body ) . then ( ( { _id } ) => { return User . findOneAndUpdate ( { _id : body . userId } , { $push : { thoughts : _id } } , { new : true } ) ; } ) . then ( dbUserData => { if ( ! dbUserData ) { res . status ( 404 ) . json ( { message : 'No user found with this id.' } ) ; return ; } res . json ( dbUserData ) } ) . catch ( err => res . json ( err ) ) ; }
create a thought by a user
create a thought by a user