From f23f580a25c0a7c777cff9beb38eba153518de6a Mon Sep 17 00:00:00 2001 From: "Engelbart Kai Sven (PEA4-Fe)" Date: Thu, 25 Feb 2021 11:33:14 +0100 Subject: [PATCH] Add simple prediction comparison --- src/models/prediction.ts | 5 ++++- src/routes/prediction.ts | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/models/prediction.ts b/src/models/prediction.ts index 50cad46..dfd2b07 100644 --- a/src/models/prediction.ts +++ b/src/models/prediction.ts @@ -2,7 +2,10 @@ import mongoose from 'mongoose'; const PredictionSchema = new mongoose.Schema({ - name: String, + name: { + type: String, + unique: true + }, value: Number }); diff --git a/src/routes/prediction.ts b/src/routes/prediction.ts index c45db7c..fc50d04 100644 --- a/src/routes/prediction.ts +++ b/src/routes/prediction.ts @@ -16,5 +16,11 @@ 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); +}); + module.exports = router;