diff --git a/app.js b/app.js index e7ded2f9c..aa75e5c31 100644 --- a/app.js +++ b/app.js @@ -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; diff --git a/models/setting.js b/models/setting.js index dd82b3e42..59de7374e 100644 --- a/models/setting.js +++ b/models/setting.js @@ -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}); }; diff --git a/package.json b/package.json index b7fb48d34..7d561d926 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/routes/api/settings/index.js b/routes/api/settings/index.js index fa5d3a620..cda9a3806 100644 --- a/routes/api/settings/index.js +++ b/routes/api/settings/index.js @@ -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;