diff --git a/src/routes/prediction.ts b/src/routes/prediction.ts index fc50d04..9fc2bf6 100644 --- a/src/routes/prediction.ts +++ b/src/routes/prediction.ts @@ -17,9 +17,10 @@ router.post('/prediction/new', (req, res, next) => { }); router.post('/prediction/compare', async (req, res, next) => { - const valA = (await PredictionModel.findOne({ name: req.body.nameA })).value; - const valB = (await PredictionModel.findOne({ name: req.body.nameB })).value; - res.json(valB - valA); + const valA = await PredictionModel.findOne({ name: req.body.nameA }); + const valB = await PredictionModel.findOne({ name: req.body.nameB }); + if(!valA || !valB) next(new Error("invalid prediction name")); + res.json(valB.value - valA.value); });