Skip to content
Snippets Groups Projects
Commit 5b37132a authored by Iskandar, Michelle P (UG - Computer Science)'s avatar Iskandar, Michelle P (UG - Computer Science) :ice_skate:
Browse files

Made code clearer, added comments, added error handling

parent 74e40759
No related branches found
No related tags found
1 merge request!2Database
...@@ -36,14 +36,22 @@ app.post('/predict', (req,res) => { ...@@ -36,14 +36,22 @@ app.post('/predict', (req,res) => {
console.log(JSON.parse(body).predictionText) console.log(JSON.parse(body).predictionText)
// res.send(JSON.parse(JSON.parse(body).prediction)); //Display the response on the website // res.send(JSON.parse(JSON.parse(body).prediction)); //Display the response on the website
//Add to db
// Connect to the db // Connect to the db
MongoClient.connect(url, function(err, db) { MongoClient.connect(url, function(err, db) {
if (err) throw err; if(err) { return console.dir(err); }
db.collection('Predictions').insertOne({
Plot: req.body.plot, // Create collection if does not exist
Prediction: JSON.parse(body).predictionText var collection = db.createCollection('Pred_Records');
})
// Get the data to be stored
var plot = req.body.plot;
var prediction = JSON.parse(body).predictionText;
// Get rcord to be inserted
var rec = {'Plot':plot, 'Prediction': prediction};
// Insert the record to the collection, throw error if insert unsuccessful
collection.insert(rec, {w:1}, function(err, result) {});
}); });
res.render('predictions',{predictions:JSON.parse(JSON.parse(body).predictionText)}) res.render('predictions',{predictions:JSON.parse(JSON.parse(body).predictionText)})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment