I'm trying to switch from the first code to the second one I hope you can guide me. speak more clearly I'm trying to change the first 'req.body.dharma' to the second 'return async (req, res) => { let article = req.article article.title = req.body.title article.description = req.body.description article.markdown = req.body.markdown'.
first code: module.exports.updateDharma = async (req, res) => { const { id } = req.params; console.log(req.body); const dharma = await Dharma.findByIdAndUpdate(id, { ...req.body.dharma }); const imgs = req.files.map(f => ({ url: f.path, filename: f.filename })); dharma.images.push(...imgs); await dharma.save() if(req.body.deleteImages){ for(let filename of req.body.deleteImages){ await cloudinary.uploader.destroy(filename); } await dharma.updateOne({ $pull: { images: {filename: { $in: req.body.deleteImages } } } } ) } req.flash('infoDharma', 'อัปเดตสำเร็จ'); res.redirect(`${dharma._id}`) } second code: function saveArticleAndRedirect(path) { return async (req, res) => { let article = req.article article.title = req.body.title article.description = req.body.description article.markdown = req.body.markdown try { article = await article.save() res.redirect(`/articles/${article.slug}`) } catch (e) { res.render(`articles/${path}`, { article: article }) } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)