Created
August 16, 2020 09:34
-
-
Save rahulCSENITTE/2a22461c97bb82856d491c05e234bcc2 to your computer and use it in GitHub Desktop.
report -- digilab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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