diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-03-03 19:52:36 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-03-03 19:52:36 +0900 |
| commit | 970843acd429e62c884c780601fae317a6a0fabb (patch) | |
| tree | 03a5d532d5b30758311d9069519d24f23bc209c7 /src/api/endpoints/aggregation/posts | |
| parent | wip (diff) | |
| download | sharkey-970843acd429e62c884c780601fae317a6a0fabb.tar.gz sharkey-970843acd429e62c884c780601fae317a6a0fabb.tar.bz2 sharkey-970843acd429e62c884c780601fae317a6a0fabb.zip | |
done
Diffstat (limited to 'src/api/endpoints/aggregation/posts')
| -rw-r--r-- | src/api/endpoints/aggregation/posts/like.ts (renamed from src/api/endpoints/aggregation/posts/like.js) | 10 | ||||
| -rw-r--r-- | src/api/endpoints/aggregation/posts/likes.ts (renamed from src/api/endpoints/aggregation/posts/likes.js) | 10 | ||||
| -rw-r--r-- | src/api/endpoints/aggregation/posts/reply.ts (renamed from src/api/endpoints/aggregation/posts/reply.js) | 10 | ||||
| -rw-r--r-- | src/api/endpoints/aggregation/posts/repost.ts (renamed from src/api/endpoints/aggregation/posts/repost.js) | 10 |
4 files changed, 16 insertions, 24 deletions
diff --git a/src/api/endpoints/aggregation/posts/like.js b/src/api/endpoints/aggregation/posts/like.ts index 02724aceb6..38ed7e6e16 100644 --- a/src/api/endpoints/aggregation/posts/like.js +++ b/src/api/endpoints/aggregation/posts/like.ts @@ -3,7 +3,7 @@ /** * Module dependencies */ -import * as mongo from 'mongodb'; +import it from '../../../it'; import Post from '../../../models/post'; import Like from '../../../models/like'; @@ -17,14 +17,12 @@ module.exports = (params) => new Promise(async (res, rej) => { // Get 'post_id' parameter - const postId = params.post_id; - if (postId === undefined || postId === null) { - return rej('post_id is required'); - } + const [postId, postIdErr] = it(params.post_id).expect.id().required().qed(); + if (postIdErr) return rej('invalid post_id param'); // Lookup post const post = await Post.findOne({ - _id: new mongo.ObjectID(postId) + _id: postId }); if (post === null) { diff --git a/src/api/endpoints/aggregation/posts/likes.js b/src/api/endpoints/aggregation/posts/likes.ts index 1049c70687..55fe077f64 100644 --- a/src/api/endpoints/aggregation/posts/likes.js +++ b/src/api/endpoints/aggregation/posts/likes.ts @@ -3,7 +3,7 @@ /** * Module dependencies */ -import * as mongo from 'mongodb'; +import it from '../../../it'; import Post from '../../../models/post'; import Like from '../../../models/like'; @@ -17,14 +17,12 @@ module.exports = (params) => new Promise(async (res, rej) => { // Get 'post_id' parameter - const postId = params.post_id; - if (postId === undefined || postId === null) { - return rej('post_id is required'); - } + const [postId, postIdErr] = it(params.post_id).expect.id().required().qed(); + if (postIdErr) return rej('invalid post_id param'); // Lookup post const post = await Post.findOne({ - _id: new mongo.ObjectID(postId) + _id: postId }); if (post === null) { diff --git a/src/api/endpoints/aggregation/posts/reply.js b/src/api/endpoints/aggregation/posts/reply.ts index 9d051c6593..1f936bbc2f 100644 --- a/src/api/endpoints/aggregation/posts/reply.js +++ b/src/api/endpoints/aggregation/posts/reply.ts @@ -3,7 +3,7 @@ /** * Module dependencies */ -import * as mongo from 'mongodb'; +import it from '../../../it'; import Post from '../../../models/post'; /** @@ -16,14 +16,12 @@ module.exports = (params) => new Promise(async (res, rej) => { // Get 'post_id' parameter - const postId = params.post_id; - if (postId === undefined || postId === null) { - return rej('post_id is required'); - } + const [postId, postIdErr] = it(params.post_id).expect.id().required().qed(); + if (postIdErr) return rej('invalid post_id param'); // Lookup post const post = await Post.findOne({ - _id: new mongo.ObjectID(postId) + _id: postId }); if (post === null) { diff --git a/src/api/endpoints/aggregation/posts/repost.js b/src/api/endpoints/aggregation/posts/repost.ts index 01899ecea6..e4a1bf7c7b 100644 --- a/src/api/endpoints/aggregation/posts/repost.js +++ b/src/api/endpoints/aggregation/posts/repost.ts @@ -3,7 +3,7 @@ /** * Module dependencies */ -import * as mongo from 'mongodb'; +import it from '../../../it'; import Post from '../../../models/post'; /** @@ -16,14 +16,12 @@ module.exports = (params) => new Promise(async (res, rej) => { // Get 'post_id' parameter - const postId = params.post_id; - if (postId === undefined || postId === null) { - return rej('post_id is required'); - } + const [postId, postIdErr] = it(params.post_id).expect.id().required().qed(); + if (postIdErr) return rej('invalid post_id param'); // Lookup post const post = await Post.findOne({ - _id: new mongo.ObjectID(postId) + _id: postId }); if (post === null) { |