make the settings routes actually work

This commit is contained in:
Riley Davis
2016-11-03 16:34:01 -06:00
parent e9f5ec7a3d
commit 7facdf0840
4 changed files with 18 additions and 3 deletions
+4
View File
@@ -2,9 +2,13 @@
// Initialize application framework.
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use('/api/v1', require('./routes/api'));
module.exports = app;
+11 -1
View File
@@ -12,12 +12,22 @@ const SettingSchema = new Schema({
}
});
/**
* gets the entire settings record and sends it back
* @return {Promise} settings the whole settings record
*/
SettingSchema.statics.getSettings = function () {
return this.findOne();
return this.findOne({id: '1'});
};
/**
* this will update the settings object with whatever you pass in
* @param {object} setting a hash of whatever settings you want to update
* @return {Promise} settings Promise that resolves to the entire (updated) settings object.
*/
SettingSchema.statics.updateSettings = function (setting) {
// there should only ever be one record unless something has gone wrong.
console.log('new setting', setting);
return this.findOneAndUpdate({id: '1'}, {$set: setting}, {new: true});
};
+1
View File
@@ -40,6 +40,7 @@
},
"homepage": "https://github.com/coralproject/talk#readme",
"dependencies": {
"body-parser": "^1.15.2",
"debug": "^2.2.0",
"express": "^4.14.0",
"mongoose": "^4.6.5"
+2 -2
View File
@@ -3,11 +3,11 @@ const router = express.Router();
const Setting = require('../../../models/setting');
router.get('/', (req, res, next) => {
Setting.getSettings().then(res.json).catch(next);
Setting.getSettings().then(res.json.bind(res)).catch(next);
});
router.put('/', (req, res, next) => {
Setting.updateSettings(req.body).then(res.json).catch(next);
Setting.updateSettings(req.body).then(res.json.bind(res)).catch(next);
});
module.exports = router;