diff --git a/app.js b/app.js index 7ce7c91ab..30dec4c45 100644 --- a/app.js +++ b/app.js @@ -2,9 +2,12 @@ // Initialize application framework. const express = require('express'); +const bodyParser = require('body-parser'); const app = express(); +app.use(bodyParser.json()); + app.use('/api/v1', require('./routes/api')); app.use('/client/', express.static('./dist')); diff --git a/models/setting.js b/models/setting.js index dd82b3e42..b47b6e9e2 100644 --- a/models/setting.js +++ b/models/setting.js @@ -12,10 +12,19 @@ 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. return this.findOneAndUpdate({id: '1'}, {$set: setting}, {new: true}); diff --git a/package.json b/package.json index 4dc96b911..4bd9ddb7a 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,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..53bf53f3c 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(settings => res.json(settings)).catch(next); }); router.put('/', (req, res, next) => { - Setting.updateSettings(req.body).then(res.json).catch(next); + Setting.updateSettings(req.body).then(() => res.status(204).end()).catch(next); }); module.exports = router; diff --git a/swagger.yaml b/swagger.yaml index a7fdc973d..3ab5a21df 100644 --- a/swagger.yaml +++ b/swagger.yaml @@ -150,16 +150,18 @@ paths: description: Settings responses: 200: - description: OK + description: Get Setting + schema: + type: array + items: + $ref: '#/definitions/Setting' put: tags: - Settings description: Settings responses: 204: - description: OK - - + description: Updated Setting definitions: Item: @@ -212,3 +214,21 @@ definitions: type: string user_id: type: string + Setting: + type: object + properties: + id: + type: string + moderation: + type: string + enum: + - pre + - post + created_at: + type: string + format: date-time + description: Creation Date-Time + updated_at: + type: string + format: date-time + description: Updated Date-Time