From b60ed8f20cec2cbaa0d233f0c882b9f3f49a74f6 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 1 Nov 2017 04:32:18 +0900 Subject: [PATCH] Refactor --- src/api/endpoints/posts/create.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts index 2e9f1d90f..43b503b98 100644 --- a/src/api/endpoints/posts/create.ts +++ b/src/api/endpoints/posts/create.ts @@ -228,13 +228,6 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { // ----------------------------------------------------------- // Post processes - if (channel) { - Channel.update({ _id: channel._id }, { - $inc: { - index: 1 - } - }); - } User.update({ _id: user._id }, { $set: { @@ -260,8 +253,15 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { // Publish event to myself's stream event(user._id, 'post', postObj); - // Publish event to channel if (channel) { + // Increment channel index(posts count) + Channel.update({ _id: channel._id }, { + $inc: { + index: 1 + } + }); + + // Publish event to channel publishChannelStream(channel._id, 'post', postObj); }