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 | |
| parent | Merge pull request #233 from syuilo/greenkeeper/inquirer-3.0.6 (diff) | |
| download | sharkey-3c1b92baa1ac15c23fe63e2f50739105252ca516.tar.gz sharkey-3c1b92baa1ac15c23fe63e2f50739105252ca516.tar.bz2 sharkey-3c1b92baa1ac15c23fe63e2f50739105252ca516.zip | |
Follow linter
Diffstat (limited to 'src/api/endpoints/posts')
| -rw-r--r-- | src/api/endpoints/posts/context.ts | 6 | ||||
| -rw-r--r-- | src/api/endpoints/posts/create.ts | 6 | ||||
| -rw-r--r-- | src/api/endpoints/posts/favorites/create.ts | 59 | ||||
| -rw-r--r-- | src/api/endpoints/posts/favorites/delete.ts | 55 | ||||
| -rw-r--r-- | src/api/endpoints/posts/likes.ts | 6 | ||||
| -rw-r--r-- | src/api/endpoints/posts/likes/create.ts | 111 | ||||
| -rw-r--r-- | src/api/endpoints/posts/likes/delete.ts | 99 | ||||
| -rw-r--r-- | src/api/endpoints/posts/mentions.ts | 6 | ||||
| -rw-r--r-- | src/api/endpoints/posts/polls/vote.ts | 101 | ||||
| -rw-r--r-- | src/api/endpoints/posts/replies.ts | 6 | ||||
| -rw-r--r-- | src/api/endpoints/posts/reposts.ts | 6 | ||||
| -rw-r--r-- | src/api/endpoints/posts/search.ts | 6 | ||||
| -rw-r--r-- | src/api/endpoints/posts/show.ts | 6 | ||||
| -rw-r--r-- | src/api/endpoints/posts/timeline.ts | 6 |
14 files changed, 214 insertions, 265 deletions
diff --git a/src/api/endpoints/posts/context.ts b/src/api/endpoints/posts/context.ts index 5b0a56f356..7bccecfb98 100644 --- a/src/api/endpoints/posts/context.ts +++ b/src/api/endpoints/posts/context.ts @@ -1,5 +1,3 @@ -'use strict'; - /** * Module dependencies */ @@ -14,9 +12,7 @@ import serialize from '../../serializers/post'; * @param {any} user * @return {Promise<any>} */ -module.exports = (params, user) => - new Promise(async (res, rej) => -{ +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'); diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts index d558cd3018..dfc9866515 100644 --- a/src/api/endpoints/posts/create.ts +++ b/src/api/endpoints/posts/create.ts @@ -1,5 +1,3 @@ -'use strict'; - /** * Module dependencies */ @@ -23,9 +21,7 @@ import config from '../../../conf'; * @param {any} app * @return {Promise<any>} */ -module.exports = (params, user, app) => - new Promise(async (res, rej) => -{ +module.exports = (params, user, app) => new Promise(async (res, rej) => { // Get 'text' parameter const [text, textErr] = it(params.text).must.be.a.string().validate(isValidText).qed(); if (textErr) return rej('invalid text'); diff --git a/src/api/endpoints/posts/favorites/create.ts b/src/api/endpoints/posts/favorites/create.ts index 45a347ebb3..7ae77778e3 100644 --- a/src/api/endpoints/posts/favorites/create.ts +++ b/src/api/endpoints/posts/favorites/create.ts @@ -1,5 +1,3 @@ -'use strict'; - /** * Module dependencies */ @@ -14,38 +12,37 @@ import Post from '../../../models/post'; * @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 favoritee - const post = await Post.findOne({ - _id: postId - }); +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 (post === null) { - return rej('post not found'); - } + // Get favoritee + const post = await Post.findOne({ + _id: postId + }); - // if already favorited - const exist = await Favorite.findOne({ - post_id: post._id, - user_id: user._id - }); + if (post === null) { + return rej('post not found'); + } - if (exist !== null) { - return rej('already favorited'); - } + // if already favorited + const exist = await Favorite.findOne({ + post_id: post._id, + user_id: user._id + }); - // Create favorite - await Favorite.insert({ - created_at: new Date(), - post_id: post._id, - user_id: user._id - }); + if (exist !== null) { + return rej('already favorited'); + } - // Send response - res(); + // Create favorite + await Favorite.insert({ + created_at: new Date(), + post_id: post._id, + user_id: user._id }); + + // Send response + res(); +}); diff --git a/src/api/endpoints/posts/favorites/delete.ts b/src/api/endpoints/posts/favorites/delete.ts index df11215903..437863d06c 100644 --- a/src/api/endpoints/posts/favorites/delete.ts +++ b/src/api/endpoints/posts/favorites/delete.ts @@ -1,5 +1,3 @@ -'use strict'; - /** * Module dependencies */ @@ -14,36 +12,35 @@ import Post from '../../../models/post'; * @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 favoritee - const post = await Post.findOne({ - _id: postId - }); +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 (post === null) { - return rej('post not found'); - } + // Get favoritee + const post = await Post.findOne({ + _id: postId + }); - // if already favorited - const exist = await Favorite.findOne({ - post_id: post._id, - user_id: user._id - }); + if (post === null) { + return rej('post not found'); + } - if (exist === null) { - return rej('already not favorited'); - } + // if already favorited + const exist = await Favorite.findOne({ + post_id: post._id, + user_id: user._id + }); - // Delete favorite - await Favorite.deleteOne({ - _id: exist._id - }); + if (exist === null) { + return rej('already not favorited'); + } - // Send response - res(); + // Delete favorite + await Favorite.deleteOne({ + _id: exist._id }); + + // Send response + res(); +}); diff --git a/src/api/endpoints/posts/likes.ts b/src/api/endpoints/posts/likes.ts index f299de7492..88d3a6e1de 100644 --- a/src/api/endpoints/posts/likes.ts +++ b/src/api/endpoints/posts/likes.ts @@ -1,5 +1,3 @@ -'use strict'; - /** * Module dependencies */ @@ -15,9 +13,7 @@ import serialize from '../../serializers/user'; * @param {any} user * @return {Promise<any>} */ -module.exports = (params, user) => - new Promise(async (res, rej) => -{ +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'); 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 + } }); +}); diff --git a/src/api/endpoints/posts/mentions.ts b/src/api/endpoints/posts/mentions.ts index a190b55f1b..3f54674955 100644 --- a/src/api/endpoints/posts/mentions.ts +++ b/src/api/endpoints/posts/mentions.ts @@ -1,5 +1,3 @@ -'use strict'; - /** * Module dependencies */ @@ -15,9 +13,7 @@ import serialize from '../../serializers/post'; * @param {any} user * @return {Promise<any>} */ -module.exports = (params, user) => - new Promise(async (res, rej) => -{ +module.exports = (params, user) => new Promise(async (res, rej) => { // Get 'following' parameter const [following, followingError] = it(params.following).expect.boolean().default(false).qed(); diff --git a/src/api/endpoints/posts/polls/vote.ts b/src/api/endpoints/posts/polls/vote.ts index d0caf7da95..36d0de975b 100644 --- a/src/api/endpoints/posts/polls/vote.ts +++ b/src/api/endpoints/posts/polls/vote.ts @@ -1,5 +1,3 @@ -'use strict'; - /** * Module dependencies */ @@ -15,68 +13,67 @@ 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 votee - const post = await Post.findOne({ - _id: postId - }); + // Get votee + const post = await Post.findOne({ + _id: postId + }); - if (post === null) { - return rej('post not found'); - } + if (post === null) { + return rej('post not found'); + } - if (post.poll == null) { - return rej('poll not found'); - } + if (post.poll == null) { + return rej('poll not found'); + } - // Get 'choice' parameter - const [choice, choiceError] = - it(params.choice).expect.string() - .required() - .validate(c => post.poll.choices.some(x => x.id == c)) - .qed(); - if (choiceError) return rej('invalid choice param'); + // Get 'choice' parameter + const [choice, choiceError] = + it(params.choice).expect.string() + .required() + .validate(c => post.poll.choices.some(x => x.id == c)) + .qed(); + if (choiceError) return rej('invalid choice param'); - // if already voted - const exist = await Vote.findOne({ - post_id: post._id, - user_id: user._id - }); + // if already voted + const exist = await Vote.findOne({ + post_id: post._id, + user_id: user._id + }); - if (exist !== null) { - return rej('already voted'); - } + if (exist !== null) { + return rej('already voted'); + } - // Create vote - await Vote.insert({ - created_at: new Date(), - post_id: post._id, - user_id: user._id, - choice: choice - }); + // Create vote + await Vote.insert({ + created_at: new Date(), + post_id: post._id, + user_id: user._id, + choice: choice + }); - // Send response - res(); + // Send response + res(); - const inc = {}; - inc[`poll.choices.${findWithAttr(post.poll.choices, 'id', choice)}.votes`] = 1; + const inc = {}; + inc[`poll.choices.${findWithAttr(post.poll.choices, 'id', choice)}.votes`] = 1; - // Increment likes count - Post.update({ _id: post._id }, { - $inc: inc - }); + // Increment likes count + Post.update({ _id: post._id }, { + $inc: inc + }); - // Notify - notify(post.user_id, user._id, 'poll_vote', { - post_id: post._id, - choice: choice - }); + // Notify + notify(post.user_id, user._id, 'poll_vote', { + post_id: post._id, + choice: choice }); +}); function findWithAttr(array, attr, value) { for (let i = 0; i < array.length; i += 1) { diff --git a/src/api/endpoints/posts/replies.ts b/src/api/endpoints/posts/replies.ts index 3f448d1632..378ba7ec2b 100644 --- a/src/api/endpoints/posts/replies.ts +++ b/src/api/endpoints/posts/replies.ts @@ -1,5 +1,3 @@ -'use strict'; - /** * Module dependencies */ @@ -14,9 +12,7 @@ import serialize from '../../serializers/post'; * @param {any} user * @return {Promise<any>} */ -module.exports = (params, user) => - new Promise(async (res, rej) => -{ +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'); diff --git a/src/api/endpoints/posts/reposts.ts b/src/api/endpoints/posts/reposts.ts index 0c1fa9bbd1..fc9b56cfc4 100644 --- a/src/api/endpoints/posts/reposts.ts +++ b/src/api/endpoints/posts/reposts.ts @@ -1,5 +1,3 @@ -'use strict'; - /** * Module dependencies */ @@ -14,9 +12,7 @@ import serialize from '../../serializers/post'; * @param {any} user * @return {Promise<any>} */ -module.exports = (params, user) => - new Promise(async (res, rej) => -{ +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'); diff --git a/src/api/endpoints/posts/search.ts b/src/api/endpoints/posts/search.ts index 1d02f6775d..e869701a30 100644 --- a/src/api/endpoints/posts/search.ts +++ b/src/api/endpoints/posts/search.ts @@ -1,5 +1,3 @@ -'use strict'; - /** * Module dependencies */ @@ -17,9 +15,7 @@ import config from '../../../conf'; * @param {any} me * @return {Promise<any>} */ -module.exports = (params, me) => - new Promise(async (res, rej) => -{ +module.exports = (params, me) => new Promise(async (res, rej) => { // Get 'query' parameter const [query, queryError] = it(params.query).expect.string().required().trim().validate(x => x != '').qed(); if (queryError) return rej('invalid query param'); diff --git a/src/api/endpoints/posts/show.ts b/src/api/endpoints/posts/show.ts index 712ef1e160..0ff1947e98 100644 --- a/src/api/endpoints/posts/show.ts +++ b/src/api/endpoints/posts/show.ts @@ -1,5 +1,3 @@ -'use strict'; - /** * Module dependencies */ @@ -14,9 +12,7 @@ import serialize from '../../serializers/post'; * @param {any} user * @return {Promise<any>} */ -module.exports = (params, user) => - new Promise(async (res, rej) => -{ +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'); diff --git a/src/api/endpoints/posts/timeline.ts b/src/api/endpoints/posts/timeline.ts index c599c4ded7..83a96e6c65 100644 --- a/src/api/endpoints/posts/timeline.ts +++ b/src/api/endpoints/posts/timeline.ts @@ -1,5 +1,3 @@ -'use strict'; - /** * Module dependencies */ @@ -16,9 +14,7 @@ import serialize from '../../serializers/post'; * @param {any} app * @return {Promise<any>} */ -module.exports = (params, user, app) => - new Promise(async (res, rej) => -{ +module.exports = (params, user, app) => new Promise(async (res, rej) => { // Get 'limit' parameter const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed(); if (limitErr) return rej('invalid limit param'); |