Archived
2

Throw an error when a prediction cannot be found

This commit is contained in:
Kai S. K. Engelbart 2021-02-25 11:45:38 +01:00
parent f23f580a25
commit 9b75741f22

View File

@ -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);
});