mirror of
https://github.com/wassname/talk.git
synced 2026-07-23 13:10:20 +08:00
Merge branch 'comment-api' of github.com:coralproject/talk into comment-api
This commit is contained in:
@@ -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'));
|
||||
|
||||
|
||||
+10
-1
@@ -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});
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
+24
-4
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user