Skip to content

Instantly share code, notes, and snippets.

@rahulCSENITTE
Created August 16, 2020 09:34
Show Gist options
  • Save rahulCSENITTE/2a22461c97bb82856d491c05e234bcc2 to your computer and use it in GitHub Desktop.
Save rahulCSENITTE/2a22461c97bb82856d491c05e234bcc2 to your computer and use it in GitHub Desktop.
report -- digilab
router.post('/upreport/:ReId', multer.single('reportfile'), function (req, res, next) {
if (!req.file) {
req.flash('error', "Report file not selected")
res.redirect('/hospital/report')
} else {
db.collection("request").doc(req.params.ReId)
.get()
.then((doc) => {
var mailOptions = {
from: '4nm17cs141@gmail.com',
to: doc.data().email,
subject: 'Sending Email using Node.js',
html: '<h1>Report Gnerated</h1><p>Thank you for using Digilab!</p>',
attachments: [{
filename: req.file.originalname,
path: "./public/reports/" + req.file.originalname
}]
}
mail.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error)
}
bucket.upload("./public/reports/" + req.file.originalname, {
destination: req.params.ReId
})
.then(() => {
fs.unlinkSync("./public/reports/" + req.file.originalname);
db.collection("request").doc(req.params.ReId).update({
"status": 4
})
.then(() => {
req.flash("success", "Report uploaded for request ID: " + req.params.ReId);
res.redirect('/hospital/report');
})
.catch(() => {
req.flash('error', "Report file not uploaded")
res.redirect('/hospital/report')
})
})
.catch((er) => {
console.log(er);
req.flash('error', "Report file not uploaded")
res.redirect('/hospital/report')
})
})
})
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment