Allow predictions to be saved
This commit is contained in:
parent
67d59cedfe
commit
3bad5416a8
11
src/index.ts
11
src/index.ts
@ -110,14 +110,15 @@ if (process.env.NODE_ENV !== 'production') {
|
|||||||
|
|
||||||
|
|
||||||
// Require routes
|
// Require routes
|
||||||
app.use('/', require('./routes/root'));
|
app.use('/', require('./routes/help'));
|
||||||
app.use('/', require('./routes/sample'));
|
|
||||||
app.use('/', require('./routes/material'));
|
app.use('/', require('./routes/material'));
|
||||||
app.use('/', require('./routes/measurement'));
|
app.use('/', require('./routes/measurement'));
|
||||||
app.use('/', require('./routes/template'));
|
|
||||||
app.use('/', require('./routes/model'));
|
app.use('/', require('./routes/model'));
|
||||||
|
app.use('/', require('./routes/prediction'));
|
||||||
|
app.use('/', require('./routes/root'));
|
||||||
|
app.use('/', require('./routes/sample'));
|
||||||
|
app.use('/', require('./routes/template'));
|
||||||
app.use('/', require('./routes/user'));
|
app.use('/', require('./routes/user'));
|
||||||
app.use('/', require('./routes/help'));
|
|
||||||
|
|
||||||
// Static files
|
// Static files
|
||||||
app.use('/static', express.static('static'));
|
app.use('/static', express.static('static'));
|
||||||
@ -140,4 +141,4 @@ const server = app.listen(port, () => {
|
|||||||
console.info(process.env.NODE_ENV === 'test' ? '' : `Listening on http://localhost:${port}`);
|
console.info(process.env.NODE_ENV === 'test' ? '' : `Listening on http://localhost:${port}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = server;
|
module.exports = server;
|
||||||
|
@ -2,7 +2,8 @@ import mongoose from 'mongoose';
|
|||||||
|
|
||||||
|
|
||||||
const PredictionSchema = new mongoose.Schema({
|
const PredictionSchema = new mongoose.Schema({
|
||||||
values: [{ spectrumName: String, value: Number }]
|
name: String,
|
||||||
|
value: Number
|
||||||
});
|
});
|
||||||
|
|
||||||
export default mongoose.model<any, mongoose.Model<any, any>>('prediction', PredictionSchema);
|
export default mongoose.model<any, mongoose.Model<any, any>>('prediction', PredictionSchema);
|
||||||
|
0
src/routes/prediction.spec.ts
Normal file
0
src/routes/prediction.spec.ts
Normal file
20
src/routes/prediction.ts
Normal file
20
src/routes/prediction.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import express from 'express';
|
||||||
|
import mongoose from 'mongoose';
|
||||||
|
|
||||||
|
import db from '../db';
|
||||||
|
import PredictionModel from '../models/prediction';
|
||||||
|
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
|
||||||
|
router.post('/prediction/new', (req, res, next) => {
|
||||||
|
console.log("New Prediction");
|
||||||
|
console.log(JSON.stringify(req.body));
|
||||||
|
new PredictionModel(req.body).save((err, data) => {
|
||||||
|
if(err) return next(err);
|
||||||
|
db.log(req, 'predictions', {_id: data._id}, data.toObject());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = router;
|
Reference in New Issue
Block a user