Use cafy
This commit is contained in:
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import User from '../../models/user';
|
||||
import serialize from '../../serializers/user';
|
||||
|
||||
|
Reference in New Issue
Block a user