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;