diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-03-05 12:00:39 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-03-05 12:00:39 +0900 |
| commit | 17a23c3eb508bd15bc68999f448224eb7cc64354 (patch) | |
| tree | ef7ece8bf80ea957981856746b30be9beac544af /src/api/endpoints/users | |
| parent | Clean up :sparkles: (diff) | |
| download | sharkey-17a23c3eb508bd15bc68999f448224eb7cc64354.tar.gz sharkey-17a23c3eb508bd15bc68999f448224eb7cc64354.tar.bz2 sharkey-17a23c3eb508bd15bc68999f448224eb7cc64354.zip | |
Use cafy
Diffstat (limited to 'src/api/endpoints/users')
| -rw-r--r-- | src/api/endpoints/users/followers.ts | 8 | ||||
| -rw-r--r-- | src/api/endpoints/users/following.ts | 8 | ||||
| -rw-r--r-- | src/api/endpoints/users/posts.ts | 12 | ||||
| -rw-r--r-- | src/api/endpoints/users/recommendation.ts | 6 | ||||
| -rw-r--r-- | src/api/endpoints/users/search.ts | 8 | ||||
| -rw-r--r-- | src/api/endpoints/users/search_by_username.ts | 8 | ||||
| -rw-r--r-- | src/api/endpoints/users/show.ts | 2 |
7 files changed, 26 insertions, 26 deletions
diff --git a/src/api/endpoints/users/followers.ts b/src/api/endpoints/users/followers.ts index e593854e81..09bc5d83ef 100644 --- a/src/api/endpoints/users/followers.ts +++ b/src/api/endpoints/users/followers.ts @@ -1,7 +1,7 @@ /** * Module dependencies */ -import it from '../../it'; +import it from 'cafy'; import User from '../../models/user'; import Following from '../../models/following'; import serialize from '../../serializers/user'; @@ -20,15 +20,15 @@ module.exports = (params, me) => new Promise(async (res, rej) => { if (userIdErr) return rej('invalid user_id param'); // Get 'iknow' parameter - const [iknow, iknowErr] = it(params.iknow).expect.boolean().default(false).qed(); + const [iknow = false, iknowErr] = it(params.iknow).expect.boolean().get(); if (iknowErr) return rej('invalid iknow param'); // Get 'limit' parameter - const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed(); + const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); if (limitErr) return rej('invalid limit param'); // Get 'cursor' parameter - const [cursor, cursorErr] = it(params.cursor).expect.id().default(null).qed(); + const [cursor = null, cursorErr] = it(params.cursor).expect.id().get(); if (cursorErr) return rej('invalid cursor param'); // Lookup user diff --git a/src/api/endpoints/users/following.ts b/src/api/endpoints/users/following.ts index 00baedbf87..a6f51410d7 100644 --- a/src/api/endpoints/users/following.ts +++ b/src/api/endpoints/users/following.ts @@ -1,7 +1,7 @@ /** * Module dependencies */ -import it from '../../it'; +import it from 'cafy'; import User from '../../models/user'; import Following from '../../models/following'; import serialize from '../../serializers/user'; @@ -20,15 +20,15 @@ module.exports = (params, me) => new Promise(async (res, rej) => { if (userIdErr) return rej('invalid user_id param'); // Get 'iknow' parameter - const [iknow, iknowErr] = it(params.iknow).expect.boolean().default(false).qed(); + const [iknow = false, iknowErr] = it(params.iknow).expect.boolean(.get(); if (iknowErr) return rej('invalid iknow param'); // Get 'limit' parameter - const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed(); + const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); if (limitErr) return rej('invalid limit param'); // Get 'cursor' parameter - const [cursor, cursorErr] = it(params.cursor).expect.id().default(null).qed(); + const [cursor = null, cursorErr] = it(params.cursor).expect.id().get(); if (cursorErr) return rej('invalid cursor param'); // Lookup user diff --git a/src/api/endpoints/users/posts.ts b/src/api/endpoints/users/posts.ts index 2832c5c6c3..af7082457a 100644 --- a/src/api/endpoints/users/posts.ts +++ b/src/api/endpoints/users/posts.ts @@ -1,7 +1,7 @@ /** * Module dependencies */ -import it from '../../it'; +import it from 'cafy'; import Post from '../../models/post'; import User from '../../models/user'; import serialize from '../../serializers/post'; @@ -27,23 +27,23 @@ module.exports = (params, me) => new Promise(async (res, rej) => { } // Get 'include_replies' parameter - const [includeReplies, includeRepliesErr] = it(params.include_replies).expect.boolean().default(true).qed(); + const [includeReplies = true, includeRepliesErr] = it(params.include_replies).expect.boolean().get(); if (includeRepliesErr) return rej('invalid include_replies param'); // Get 'with_media' parameter - const [withMedia, withMediaErr] = it(params.with_media).expect.boolean().default(false).qed(); + const [withMedia = false, withMediaErr] = it(params.with_media).expect.boolean().get(); if (withMediaErr) return rej('invalid with_media param'); // Get 'limit' parameter - const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed(); + const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); if (limitErr) return rej('invalid limit param'); // Get 'since_id' parameter - const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed(); + const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get(); if (sinceIdErr) return rej('invalid since_id param'); // Get 'max_id' parameter - const [maxId, maxIdErr] = it(params.max_id).expect.id().qed(); + const [maxId, maxIdErr] = it(params.max_id).expect.id().get(); if (maxIdErr) return rej('invalid max_id param'); // Check if both of since_id and max_id is specified diff --git a/src/api/endpoints/users/recommendation.ts b/src/api/endpoints/users/recommendation.ts index f502f41269..a0fb6613c6 100644 --- a/src/api/endpoints/users/recommendation.ts +++ b/src/api/endpoints/users/recommendation.ts @@ -1,7 +1,7 @@ /** * Module dependencies */ -import it from '../../it'; +import it from 'cafy'; import User from '../../models/user'; import serialize from '../../serializers/user'; import getFriends from '../../common/get-friends'; @@ -15,11 +15,11 @@ import getFriends from '../../common/get-friends'; */ module.exports = (params, me) => new Promise(async (res, rej) => { // Get 'limit' parameter - const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed(); + const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); if (limitErr) return rej('invalid limit param'); // Get 'offset' parameter - const [offset, offsetErr] = it(params.offset).expect.number().min(0).default(0).qed(); + const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get(); if (offsetErr) return rej('invalid offset param'); // ID list of the user itself and other users who the user follows diff --git a/src/api/endpoints/users/search.ts b/src/api/endpoints/users/search.ts index b21d8a2399..8be6a4dc8c 100644 --- a/src/api/endpoints/users/search.ts +++ b/src/api/endpoints/users/search.ts @@ -2,7 +2,7 @@ * Module dependencies */ import * as mongo from 'mongodb'; -import it from '../../it'; +import it from 'cafy'; import User from '../../models/user'; import serialize from '../../serializers/user'; import config from '../../../conf'; @@ -17,15 +17,15 @@ const escapeRegexp = require('escape-regexp'); */ 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(); + const [query, queryError] = it(params.query).expect.string().required().trim().validate(x => x != '').get(); if (queryError) return rej('invalid query param'); // Get 'offset' parameter - const [offset, offsetErr] = it(params.offset).expect.number().min(0).default(0).qed(); + const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get(); if (offsetErr) return rej('invalid offset param'); // Get 'max' parameter - const [max, maxErr] = it(params.max).expect.number().range(1, 30).default(10).qed(); + const [max = 10, maxErr] = it(params.max).expect.number().range(1, 30).get(); if (maxErr) return rej('invalid max param'); // If Elasticsearch is available, search by it diff --git a/src/api/endpoints/users/search_by_username.ts b/src/api/endpoints/users/search_by_username.ts index 4071f341f2..b3193a4956 100644 --- a/src/api/endpoints/users/search_by_username.ts +++ b/src/api/endpoints/users/search_by_username.ts @@ -1,7 +1,7 @@ /** * Module dependencies */ -import it from '../../it'; +import it from 'cafy'; import User from '../../models/user'; import { validateUsername } from '../../models/user'; import serialize from '../../serializers/user'; @@ -15,15 +15,15 @@ import serialize from '../../serializers/user'; */ module.exports = (params, me) => new Promise(async (res, rej) => { // Get 'query' parameter - const [query, queryError] = it(params.query).expect.string().required().trim().validate(validateUsername).qed(); + const [query, queryError] = it(params.query).expect.string().required().trim().validate(validateUsername).get(); if (queryError) return rej('invalid query param'); // Get 'offset' parameter - const [offset, offsetErr] = it(params.offset).expect.number().min(0).default(0).qed(); + const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get(); if (offsetErr) return rej('invalid offset param'); // Get 'limit' parameter - const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed(); + const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); if (limitErr) return rej('invalid limit param'); const users = await User diff --git a/src/api/endpoints/users/show.ts b/src/api/endpoints/users/show.ts index d35bfbae20..2a8d9c7724 100644 --- a/src/api/endpoints/users/show.ts +++ b/src/api/endpoints/users/show.ts @@ -1,7 +1,7 @@ /** * Module dependencies */ -import it from '../../it'; +import it from 'cafy'; import User from '../../models/user'; import serialize from '../../serializers/user'; |