mirror of
https://github.com/wassname/talk.git
synced 2026-07-18 12:40:13 +08:00
Through error instead of process.exit(1) http://eslint.org/docs/rules/no-process-exit
This commit is contained in:
@@ -4,3 +4,4 @@ dist
|
||||
.DS_Store
|
||||
*.iml
|
||||
.env
|
||||
gaba.cfg
|
||||
|
||||
+1
-2
@@ -2,6 +2,5 @@ const Setting = require('../models/setting');
|
||||
const defaults = {id: '1', moderation: 'pre'};
|
||||
|
||||
Setting.update({id: '1'}, {$setOnInsert: defaults}, {upsert: true}).then(() => {
|
||||
console.log('created settings object.');
|
||||
process.exit();
|
||||
throw new Error('It was not able to update settings.');
|
||||
}).catch(console.error);
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
const mongoose = require('../mongoose');
|
||||
const uuid = require('uuid');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
+1
-4
@@ -1,5 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
const mongoose = require('../mongoose');
|
||||
const uuid = require('uuid');
|
||||
const Schema = mongoose.Schema;
|
||||
@@ -13,7 +11,7 @@ const CommentSchema = new Schema({
|
||||
body: {
|
||||
type: String,
|
||||
required: [true, 'The body is required.'],
|
||||
minlength: 50
|
||||
minlength: 10
|
||||
},
|
||||
asset_id: String,
|
||||
author_id: String,
|
||||
@@ -24,7 +22,6 @@ const CommentSchema = new Schema({
|
||||
},
|
||||
parent_id: String
|
||||
},{
|
||||
_id: false,
|
||||
timestamps: {
|
||||
createdAt: 'created_at',
|
||||
updatedAt: 'updated_at'
|
||||
|
||||
@@ -1,7 +1,23 @@
|
||||
const express = require('express');
|
||||
const Comment = require('../../../models/comment');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
//==============================================================================
|
||||
// Validations on parameters
|
||||
//==============================================================================
|
||||
|
||||
router.param('comment_id', function(res, req, next, comment_id) {
|
||||
console.log('validations on comment id ');
|
||||
req.comment_id = comment_id;
|
||||
next();
|
||||
});
|
||||
|
||||
//==============================================================================
|
||||
// Routes
|
||||
//==============================================================================
|
||||
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
res.send('Read all of the comments ever');
|
||||
});
|
||||
@@ -10,8 +26,23 @@ router.get('/:comment_id', (req, res) => {
|
||||
res.send('Read a comment');
|
||||
});
|
||||
|
||||
router.post('/', (req, res) => {
|
||||
res.send('Write a comment');
|
||||
router.post('/', (req, res, next) => {
|
||||
let comment = new Comment({
|
||||
body: req.query.comment,
|
||||
author_id: req.query.author_id,
|
||||
asset_id: req.query.asset_id,
|
||||
parent_id: req.query.parent_id,
|
||||
status: req.query.status
|
||||
});
|
||||
comment.save(function(err, comment) {
|
||||
if(err) {
|
||||
res.status(500);
|
||||
return next(err);
|
||||
}
|
||||
res.status(201);
|
||||
res.send(comment.id);
|
||||
next();
|
||||
});
|
||||
});
|
||||
|
||||
router.put('/:comment_id', (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user