diff --git a/src/routes/prediction.ts b/src/routes/prediction.ts index 9fc2bf6..8c26a15 100644 --- a/src/routes/prediction.ts +++ b/src/routes/prediction.ts @@ -7,10 +7,10 @@ import PredictionModel from '../models/prediction'; const router = express.Router(); -router.post('/prediction/new', (req, res, next) => { +router.post('/prediction/new', async (req, res, next) => { console.log("New Prediction"); console.log(JSON.stringify(req.body)); - new PredictionModel(req.body).save((err, data) => { + await PredictionModel.findOneAndUpdate( { name: req.body.name }, { value: req.body.value }, { upsert: true, new: true }, (err, data) => { if(err) return next(err); db.log(req, 'predictions', {_id: data._id}, data.toObject()); });