diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-03-04 04:28:38 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-03-04 04:28:38 +0900 |
| commit | 3c1b92baa1ac15c23fe63e2f50739105252ca516 (patch) | |
| tree | 35a0ae58802891f05209c83e780440775075e088 /src/api/endpoints/posts/likes/delete.ts | |
| parent | Merge pull request #233 from syuilo/greenkeeper/inquirer-3.0.6 (diff) | |
| download | misskey-3c1b92baa1ac15c23fe63e2f50739105252ca516.tar.gz misskey-3c1b92baa1ac15c23fe63e2f50739105252ca516.tar.bz2 misskey-3c1b92baa1ac15c23fe63e2f50739105252ca516.zip | |
Follow linter
Diffstat (limited to 'src/api/endpoints/posts/likes/delete.ts')
| -rw-r--r-- | src/api/endpoints/posts/likes/delete.ts | 99 |
1 files changed, 48 insertions, 51 deletions
diff --git a/src/api/endpoints/posts/likes/delete.ts b/src/api/endpoints/posts/likes/delete.ts index 2b642c107f..bd2f83e21d 100644 --- a/src/api/endpoints/posts/likes/delete.ts +++ b/src/api/endpoints/posts/likes/delete.ts @@ -1,5 +1,3 @@ -'use strict'; - /** * Module dependencies */ @@ -16,62 +14,61 @@ import User from '../../../models/user'; * @param {any} user * @return {Promise<any>} */ -module.exports = (params, user) => - new Promise(async (res, rej) => { - // Get 'post_id' parameter - const [postId, postIdErr] = it(params.post_id, 'id', true); - if (postIdErr) return rej('invalid post_id param'); - - // Get likee - const post = await Post.findOne({ - _id: postId - }); - - if (post === null) { - return rej('post not found'); - } +module.exports = (params, user) => new Promise(async (res, rej) => { + // Get 'post_id' parameter + const [postId, postIdErr] = it(params.post_id, 'id', true); + if (postIdErr) return rej('invalid post_id param'); - // if already liked - const exist = await Like.findOne({ - post_id: post._id, - user_id: user._id, - deleted_at: { $exists: false } - }); + // Get likee + const post = await Post.findOne({ + _id: postId + }); - if (exist === null) { - return rej('already not liked'); - } + if (post === null) { + return rej('post not found'); + } - // Delete like - await Like.update({ - _id: exist._id - }, { - $set: { - deleted_at: new Date() - } - }); + // if already liked + const exist = await Like.findOne({ + post_id: post._id, + user_id: user._id, + deleted_at: { $exists: false } + }); - // Send response - res(); + if (exist === null) { + return rej('already not liked'); + } - // Decrement likes count - Post.update({ _id: post._id }, { - $inc: { - likes_count: -1 + // Delete like + await Like.update({ + _id: exist._id + }, { + $set: { + deleted_at: new Date() } }); - // Decrement user likes count - User.update({ _id: user._id }, { - $inc: { - likes_count: -1 - } - }); + // Send response + res(); - // Decrement user liked count - User.update({ _id: post.user_id }, { - $inc: { - liked_count: -1 - } - }); + // Decrement likes count + Post.update({ _id: post._id }, { + $inc: { + likes_count: -1 + } + }); + + // Decrement user likes count + User.update({ _id: user._id }, { + $inc: { + likes_count: -1 + } + }); + + // Decrement user liked count + User.update({ _id: post.user_id }, { + $inc: { + liked_count: -1 + } }); +}); |