mirror of
https://github.com/wassname/talk.git
synced 2026-09-11 12:51:33 +08:00
Merge branch 'master' of https://github.com/coralproject/talk into post-comment
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const Asset = require('../../../models/asset');
|
||||
|
||||
// Search assets.
|
||||
router.get('/', (req, res, next) => {
|
||||
|
||||
let query = {};
|
||||
|
||||
if (typeof req.query.url !== 'undefined') {
|
||||
query.url = req.query.url;
|
||||
}
|
||||
|
||||
Asset.search(query)
|
||||
.then((asset) => {
|
||||
res.json(asset);
|
||||
})
|
||||
.catch(next);
|
||||
|
||||
});
|
||||
|
||||
// Get an asset by id
|
||||
router.get('/:id', (req, res, next) => {
|
||||
|
||||
Asset.findById(req.params.id)
|
||||
.then((asset) => {
|
||||
res.json(asset);
|
||||
})
|
||||
.catch(next);
|
||||
|
||||
});
|
||||
|
||||
// Upsert an asset and return the affected document.
|
||||
router.put('/', (req, res, next) => {
|
||||
|
||||
Asset.upsert(req.body)
|
||||
.then((asset) => {
|
||||
res.json(asset);
|
||||
})
|
||||
.catch(next);
|
||||
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@@ -7,7 +7,6 @@ const router = express.Router();
|
||||
// Routes
|
||||
//==============================================================================
|
||||
|
||||
|
||||
router.get('/', (req, res, next) => {
|
||||
Comment.find({}).then((comments) => {
|
||||
res.status(200).json(comments);
|
||||
@@ -25,16 +24,10 @@ router.get('/:comment_id', (req, res, next) => {
|
||||
});
|
||||
|
||||
router.post('/', (req, res, next) => {
|
||||
let comment = new Comment({
|
||||
body: req.body.body,
|
||||
author_id: req.body.author_id,
|
||||
asset_id: req.body.asset_id,
|
||||
parent_id: req.body.parent_id,
|
||||
status: req.body.status,
|
||||
username: req.body.username
|
||||
});
|
||||
const {body, author_id, asset_id, parent_id, status, username} = req.body;
|
||||
let comment = new Comment({body, author_id, asset_id, parent_id, status, username});
|
||||
comment.save().then(({id}) => {
|
||||
res.status(200).send(id);
|
||||
res.status(200).send({'id': id});
|
||||
}).catch(error => {
|
||||
next(error);
|
||||
});
|
||||
@@ -47,20 +40,17 @@ router.post('/:comment_id', (req, res, next) => {
|
||||
comment.asset_id = req.body.asset_id;
|
||||
comment.parent_id = req.body.parent_id;
|
||||
comment.status = req.body.status;
|
||||
|
||||
comment.save().then((comment) => {
|
||||
res.status(200).send(comment);
|
||||
});
|
||||
return comment.save();
|
||||
}).then((comment) => {
|
||||
res.status(200).send(comment);
|
||||
}).catch(error => {
|
||||
next(error);
|
||||
});
|
||||
});
|
||||
|
||||
router.delete('/:comment_id', (req, res, next) => {
|
||||
Comment.findById(req.params.comment_id).then((comment) => {
|
||||
comment.remove().then(() => {
|
||||
res.status(201).send('OK. Deleted');
|
||||
});
|
||||
Comment.remove(req.params.comment_id).then(() => {
|
||||
res.status(201).send('OK. Deleted');
|
||||
}).catch(error => {
|
||||
next(error);
|
||||
});
|
||||
|
||||
+3
-2
@@ -2,9 +2,10 @@ const express = require('express');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.use('/asset', require('./asset'));
|
||||
router.use('/comments', require('./comments'));
|
||||
router.use('/stream', require('./stream'));
|
||||
router.use('/settings', require('./settings'));
|
||||
router.use('/queue', require('./queue'));
|
||||
router.use('/settings', require('./settings'));
|
||||
router.use('/stream', require('./stream'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -3,13 +3,14 @@ const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const defaultComment = {
|
||||
_id: '23423423432aa',
|
||||
body: 'This is a comment!',
|
||||
name: 'John Doe',
|
||||
createdAt: Date.now()
|
||||
};
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
const status = req.query.type || 'pending';
|
||||
const status = req.query.type;
|
||||
res.json([Object.assign({}, defaultComment, {status})]);
|
||||
});
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ router.get('/', (req, res, next) => {
|
||||
Action.findByItemIdArray(comments.map((comment) => comment.id))
|
||||
]);
|
||||
}).then(([comments, users, actions]) => {
|
||||
res.json([...comments,...users,...actions]);
|
||||
res.json([...comments, ...users, ...actions]);
|
||||
}).catch(error => {
|
||||
next(error);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user