From f49b18d19b5667b1ebfdc26a3c72703a9aef3b68 Mon Sep 17 00:00:00 2001 From: "Engelbart Kai Sven (PEA4-Fe)" Date: Tue, 9 Mar 2021 16:25:50 +0100 Subject: [PATCH] Override existing predictions --- src/routes/prediction.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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()); });