article.tags.forEach(async t => {
let tag = await Tag.findOneAndUpdate({ _id: t }, {$push: {"articles": article._id}}, {new: true})
if (tag === null) return res.status(404).json({ message: 'Tag not found' })
})
router.post('/upload', Media.uploadImage, Media.answer)
const storage = multer.diskStorage({
destination: 'uploads',
filename: function (req, file, cb) {
cb(null, file.fieldname + '-' + Date.now())
}
})
exports.uploadImage = multer({ storage: storage }).single('fileee')
exports.answer = (req, res, next) => {
if (!req.file) {
console.log("No file received");
return res.send({
success: false
});
} else {
console.log('file received');
return res.send({
success: true,
name: req.file.filename
})
}
}