mirror of
https://github.com/wassname/talk.git
synced 2026-09-10 12:43:11 +08:00
refactored publicCreate
This commit is contained in:
+4
-11
@@ -13,15 +13,11 @@ const { COMMENTS_NEW, COMMENTS_EDIT } = require('./events/constants');
|
||||
module.exports = class CommentsService {
|
||||
/**
|
||||
* Creates a new Comment that came from a public source.
|
||||
* @param {Mixed} input either a single comment or an array of comments.
|
||||
* @param {Object} input either a single comment or an array of comments.
|
||||
* @return {Promise}
|
||||
*/
|
||||
static async publicCreate(input) {
|
||||
// Check to see if this is an array of comments, if so map it out.
|
||||
if (Array.isArray(input)) {
|
||||
return Promise.all(input.map(CommentsService.publicCreate));
|
||||
}
|
||||
|
||||
// Extract the parent_id from the comment, if there is one.
|
||||
const { status = 'NONE', parent_id = null } = input;
|
||||
|
||||
// Check to see if we are replying to a comment, and if that comment is
|
||||
@@ -33,8 +29,8 @@ module.exports = class CommentsService {
|
||||
}
|
||||
}
|
||||
|
||||
// Turn the comment into a new object.
|
||||
const comment = new CommentModel(
|
||||
// Create the comment in the database.
|
||||
const comment = await CommentModel.create(
|
||||
merge(
|
||||
{
|
||||
status_history: status
|
||||
@@ -56,9 +52,6 @@ module.exports = class CommentsService {
|
||||
)
|
||||
);
|
||||
|
||||
// Save the comment to the database.
|
||||
await comment.save();
|
||||
|
||||
// Emit that the comment was created!
|
||||
await events.emitAsync(COMMENTS_NEW, comment);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user