mirror of
https://github.com/wassname/talk.git
synced 2026-07-20 12:40:47 +08:00
make the settings routes actually work
This commit is contained in:
@@ -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
@@ -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});
|
||||
};
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user