summaryrefslogtreecommitdiff
path: root/src/api/endpoints/posts/likes
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-03-04 04:28:38 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-03-04 04:28:38 +0900
commit3c1b92baa1ac15c23fe63e2f50739105252ca516 (patch)
tree35a0ae58802891f05209c83e780440775075e088 /src/api/endpoints/posts/likes
parentMerge pull request #233 from syuilo/greenkeeper/inquirer-3.0.6 (diff)
downloadmisskey-3c1b92baa1ac15c23fe63e2f50739105252ca516.tar.gz
misskey-3c1b92baa1ac15c23fe63e2f50739105252ca516.tar.bz2
misskey-3c1b92baa1ac15c23fe63e2f50739105252ca516.zip
Follow linter
Diffstat (limited to 'src/api/endpoints/posts/likes')
-rw-r--r--src/api/endpoints/posts/likes/create.ts111
-rw-r--r--src/api/endpoints/posts/likes/delete.ts99
2 files changed, 102 insertions, 108 deletions
diff --git a/src/api/endpoints/posts/likes/create.ts b/src/api/endpoints/posts/likes/create.ts
index 0ae417e239..43e76d1a58 100644
--- a/src/api/endpoints/posts/likes/create.ts
+++ b/src/api/endpoints/posts/likes/create.ts
@@ -1,5 +1,3 @@
-'use strict';
-
/**
* Module dependencies
*/
@@ -16,70 +14,69 @@ import notify from '../../../common/notify';
* @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');
+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
- });
+ // Get likee
+ const post = await Post.findOne({
+ _id: postId
+ });
- if (post === null) {
- return rej('post not found');
- }
+ if (post === null) {
+ return rej('post not found');
+ }
- // Myself
- if (post.user_id.equals(user._id)) {
- return rej('-need-translate-');
- }
+ // Myself
+ if (post.user_id.equals(user._id)) {
+ return rej('-need-translate-');
+ }
- // if already liked
- const exist = await Like.findOne({
- post_id: post._id,
- user_id: user._id,
- deleted_at: { $exists: false }
- });
+ // if already liked
+ const exist = await Like.findOne({
+ post_id: post._id,
+ user_id: user._id,
+ deleted_at: { $exists: false }
+ });
- if (exist !== null) {
- return rej('already liked');
- }
+ if (exist !== null) {
+ return rej('already liked');
+ }
- // Create like
- await Like.insert({
- created_at: new Date(),
- post_id: post._id,
- user_id: user._id
- });
+ // Create like
+ await Like.insert({
+ created_at: new Date(),
+ post_id: post._id,
+ user_id: user._id
+ });
- // Send response
- res();
+ // Send response
+ res();
- // Increment likes count
- Post.update({ _id: post._id }, {
- $inc: {
- likes_count: 1
- }
- });
+ // Increment likes count
+ Post.update({ _id: post._id }, {
+ $inc: {
+ likes_count: 1
+ }
+ });
- // Increment user likes count
- User.update({ _id: user._id }, {
- $inc: {
- likes_count: 1
- }
- });
+ // Increment user likes count
+ User.update({ _id: user._id }, {
+ $inc: {
+ likes_count: 1
+ }
+ });
- // Increment user liked count
- User.update({ _id: post.user_id }, {
- $inc: {
- liked_count: 1
- }
- });
+ // Increment user liked count
+ User.update({ _id: post.user_id }, {
+ $inc: {
+ liked_count: 1
+ }
+ });
- // Notify
- notify(post.user_id, user._id, 'like', {
- post_id: post._id
- });
+ // Notify
+ notify(post.user_id, user._id, 'like', {
+ post_id: post._id
});
+});
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
+ }
});
+});