From 7a472760cdc966fc94c9f28ea85e3079a3cd6106 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 3 Mar 2017 19:52:36 +0900 Subject: [PATCH] done --- .../endpoints/aggregation/posts/{like.js => like.ts} | 10 ++++------ .../endpoints/aggregation/posts/{likes.js => likes.ts} | 10 ++++------ .../endpoints/aggregation/posts/{reply.js => reply.ts} | 10 ++++------ .../aggregation/posts/{repost.js => repost.ts} | 10 ++++------ .../aggregation/users/{followers.js => followers.ts} | 10 ++++------ .../aggregation/users/{following.js => following.ts} | 10 ++++------ .../endpoints/aggregation/users/{like.js => like.ts} | 10 ++++------ .../endpoints/aggregation/users/{post.js => post.ts} | 10 ++++------ 8 files changed, 32 insertions(+), 48 deletions(-) rename src/api/endpoints/aggregation/posts/{like.js => like.ts} (88%) rename src/api/endpoints/aggregation/posts/{likes.js => likes.ts} (87%) rename src/api/endpoints/aggregation/posts/{reply.js => reply.ts} (88%) rename src/api/endpoints/aggregation/posts/{repost.js => repost.ts} (88%) rename src/api/endpoints/aggregation/users/{followers.js => followers.ts} (88%) rename src/api/endpoints/aggregation/users/{following.js => following.ts} (88%) rename src/api/endpoints/aggregation/users/{like.js => like.ts} (88%) rename src/api/endpoints/aggregation/users/{post.js => post.ts} (92%) diff --git a/src/api/endpoints/aggregation/posts/like.js b/src/api/endpoints/aggregation/posts/like.ts similarity index 88% rename from src/api/endpoints/aggregation/posts/like.js rename to src/api/endpoints/aggregation/posts/like.ts index 02724aceb..38ed7e6e1 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 similarity index 87% rename from src/api/endpoints/aggregation/posts/likes.js rename to src/api/endpoints/aggregation/posts/likes.ts index 1049c7068..55fe077f6 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 similarity index 88% rename from src/api/endpoints/aggregation/posts/reply.js rename to src/api/endpoints/aggregation/posts/reply.ts index 9d051c659..1f936bbc2 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 similarity index 88% rename from src/api/endpoints/aggregation/posts/repost.js rename to src/api/endpoints/aggregation/posts/repost.ts index 01899ecea..e4a1bf7c7 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) { diff --git a/src/api/endpoints/aggregation/users/followers.js b/src/api/endpoints/aggregation/users/followers.ts similarity index 88% rename from src/api/endpoints/aggregation/users/followers.js rename to src/api/endpoints/aggregation/users/followers.ts index 3b8d1d604..9336a102f 100644 --- a/src/api/endpoints/aggregation/users/followers.js +++ b/src/api/endpoints/aggregation/users/followers.ts @@ -3,7 +3,7 @@ /** * Module dependencies */ -import * as mongo from 'mongodb'; +import it from '../../../it'; import User from '../../../models/user'; import Following from '../../../models/following'; @@ -17,14 +17,12 @@ module.exports = (params) => new Promise(async (res, rej) => { // Get 'user_id' parameter - const userId = params.user_id; - if (userId === undefined || userId === null) { - return rej('user_id is required'); - } + const [userId, userIdErr] = it(params.user_id).expect.id().required().qed(); + if (userIdErr) return rej('invalid user_id param'); // Lookup user const user = await User.findOne({ - _id: new mongo.ObjectID(userId) + _id: userId }, { fields: { _id: true diff --git a/src/api/endpoints/aggregation/users/following.js b/src/api/endpoints/aggregation/users/following.ts similarity index 88% rename from src/api/endpoints/aggregation/users/following.js rename to src/api/endpoints/aggregation/users/following.ts index 0b04ff954..d46822915 100644 --- a/src/api/endpoints/aggregation/users/following.js +++ b/src/api/endpoints/aggregation/users/following.ts @@ -3,7 +3,7 @@ /** * Module dependencies */ -import * as mongo from 'mongodb'; +import it from '../../../it'; import User from '../../../models/user'; import Following from '../../../models/following'; @@ -17,14 +17,12 @@ module.exports = (params) => new Promise(async (res, rej) => { // Get 'user_id' parameter - const userId = params.user_id; - if (userId === undefined || userId === null) { - return rej('user_id is required'); - } + const [userId, userIdErr] = it(params.user_id).expect.id().required().qed(); + if (userIdErr) return rej('invalid user_id param'); // Lookup user const user = await User.findOne({ - _id: new mongo.ObjectID(userId) + _id: userId }, { fields: { _id: true diff --git a/src/api/endpoints/aggregation/users/like.js b/src/api/endpoints/aggregation/users/like.ts similarity index 88% rename from src/api/endpoints/aggregation/users/like.js rename to src/api/endpoints/aggregation/users/like.ts index 0b20dd09a..4a932354a 100644 --- a/src/api/endpoints/aggregation/users/like.js +++ b/src/api/endpoints/aggregation/users/like.ts @@ -3,7 +3,7 @@ /** * Module dependencies */ -import * as mongo from 'mongodb'; +import it from '../../../it'; import User from '../../../models/user'; import Like from '../../../models/like'; @@ -17,14 +17,12 @@ module.exports = (params) => new Promise(async (res, rej) => { // Get 'user_id' parameter - const userId = params.user_id; - if (userId === undefined || userId === null) { - return rej('user_id is required'); - } + const [userId, userIdErr] = it(params.user_id).expect.id().required().qed(); + if (userIdErr) return rej('invalid user_id param'); // Lookup user const user = await User.findOne({ - _id: new mongo.ObjectID(userId) + _id: userId }, { fields: { _id: true diff --git a/src/api/endpoints/aggregation/users/post.js b/src/api/endpoints/aggregation/users/post.ts similarity index 92% rename from src/api/endpoints/aggregation/users/post.js rename to src/api/endpoints/aggregation/users/post.ts index 01082801e..b62dd6ec9 100644 --- a/src/api/endpoints/aggregation/users/post.js +++ b/src/api/endpoints/aggregation/users/post.ts @@ -3,7 +3,7 @@ /** * Module dependencies */ -import * as mongo from 'mongodb'; +import it from '../../../it'; import User from '../../../models/user'; import Post from '../../../models/post'; @@ -17,14 +17,12 @@ module.exports = (params) => new Promise(async (res, rej) => { // Get 'user_id' parameter - const userId = params.user_id; - if (userId === undefined || userId === null) { - return rej('user_id is required'); - } + const [userId, userIdErr] = it(params.user_id).expect.id().required().qed(); + if (userIdErr) return rej('invalid user_id param'); // Lookup user const user = await User.findOne({ - _id: new mongo.ObjectID(userId) + _id: userId }, { fields: { _id: true