Use cafy
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import Post from '../../models/post';
|
||||
import serialize from '../../serializers/post';
|
||||
|
||||
@@ -18,11 +18,11 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
if (postIdErr) return rej('invalid post_id 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 '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');
|
||||
|
||||
// Lookup post
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import parse from '../../../common/text';
|
||||
import Post from '../../models/post';
|
||||
import { isValidText } from '../../models/post';
|
||||
@@ -23,11 +23,11 @@ import config from '../../../conf';
|
||||
*/
|
||||
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();
|
||||
const [text, textErr] = it(params.text).must.be.a.string().validate(isValidText).get();
|
||||
if (textErr) return rej('invalid text');
|
||||
|
||||
// Get 'media_ids' parameter
|
||||
const [mediaIds, mediaIdsErr] = it(params.media_ids).must.be.an.array().unique().range(1, 4).qed();
|
||||
const [mediaIds, mediaIdsErr] = it(params.media_ids).must.be.an.array().unique().range(1, 4).get();
|
||||
if (mediaIdsErr) return rej('invalid media_ids');
|
||||
|
||||
let files = [];
|
||||
@@ -36,7 +36,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||
// forEach だと途中でエラーなどがあっても return できないので
|
||||
// 敢えて for を使っています。
|
||||
for (let i = 0; i < mediaIds.length; i++) {
|
||||
const [mediaId, mediaIdErr] = it(mediaIds[i]).must.be.an.id().required().qed();
|
||||
const [mediaId, mediaIdErr] = it(mediaIds[i]).must.be.an.id().required().get();
|
||||
if (mediaIdErr) return rej('invalid media id');
|
||||
|
||||
// Fetch file
|
||||
@@ -59,7 +59,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'repost_id' parameter
|
||||
const [repostId, repostIdErr] = it(params.repost_id).must.be.an.id().qed();
|
||||
const [repostId, repostIdErr] = it(params.repost_id).must.be.an.id().get();
|
||||
if (repostIdErr) return rej('invalid repost_id');
|
||||
|
||||
let repost = null;
|
||||
@@ -138,7 +138,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||
if (choice.trim().length > 50) return true;
|
||||
return false;
|
||||
}))
|
||||
.qed();
|
||||
.get();
|
||||
if (pollChoicesErr) return rej('invalid poll choices');
|
||||
|
||||
_poll.choices = pollChoices.map((choice, i) => ({
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import Favorite from '../../../models/favorite';
|
||||
import Post from '../../../models/post';
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import Favorite from '../../../models/favorite';
|
||||
import Post from '../../../models/post';
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import Post from '../../models/post';
|
||||
import Like from '../../models/like';
|
||||
import serialize from '../../serializers/user';
|
||||
@@ -19,15 +19,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
if (postIdErr) return rej('invalid post_id 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 '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 'sort' parameter
|
||||
const [sort, sortError] = it(params.sort).expect.string().or('desc asc').default('desc').qed();
|
||||
const [sort = 'desc', sortError] = it(params.sort).expect.string().or('desc asc').get();
|
||||
if (sortError) return rej('invalid sort param');
|
||||
|
||||
// Lookup post
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import Like from '../../../models/like';
|
||||
import Post from '../../../models/post';
|
||||
import User from '../../../models/user';
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import Like from '../../../models/like';
|
||||
import Post from '../../../models/post';
|
||||
import User from '../../../models/user';
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import Post from '../../models/post';
|
||||
import getFriends from '../../common/get-friends';
|
||||
import serialize from '../../serializers/post';
|
||||
@@ -15,20 +15,20 @@ import serialize from '../../serializers/post';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'following' parameter
|
||||
const [following, followingError] =
|
||||
it(params.following).expect.boolean().default(false).qed();
|
||||
const [following = false, followingError] =
|
||||
it(params.following).expect.boolean().get();
|
||||
if (followingError) return rej('invalid following 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 Vote from '../../../models/poll-vote';
|
||||
import Post from '../../../models/post';
|
||||
import notify from '../../../common/notify';
|
||||
@@ -36,7 +36,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
it(params.choice).expect.string()
|
||||
.required()
|
||||
.validate(c => post.poll.choices.some(x => x.id == c))
|
||||
.qed();
|
||||
.get();
|
||||
if (choiceError) return rej('invalid choice param');
|
||||
|
||||
// if already voted
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import Post from '../../models/post';
|
||||
import serialize from '../../serializers/post';
|
||||
|
||||
@@ -18,15 +18,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
if (postIdErr) return rej('invalid post_id 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 '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 'sort' parameter
|
||||
const [sort, sortError] = it(params.sort).expect.string().or('desc asc').default('desc').qed();
|
||||
const [sort = 'desc', sortError] = it(params.sort).expect.string().or('desc asc').get();
|
||||
if (sortError) return rej('invalid sort param');
|
||||
|
||||
// Lookup post
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import Post from '../../models/post';
|
||||
import serialize from '../../serializers/post';
|
||||
|
||||
@@ -18,15 +18,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
if (postIdErr) return rej('invalid post_id 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
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* Module dependencies
|
||||
*/
|
||||
import * as mongo from 'mongodb';
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
const escapeRegexp = require('escape-regexp');
|
||||
import Post from '../../models/post';
|
||||
import serialize from '../../serializers/post';
|
||||
@@ -17,15 +17,15 @@ import config from '../../../conf';
|
||||
*/
|
||||
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 Post from '../../models/post';
|
||||
import serialize from '../../serializers/post';
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import Post from '../../models/post';
|
||||
import getFriends from '../../common/get-friends';
|
||||
import serialize from '../../serializers/post';
|
||||
@@ -16,15 +16,15 @@ import serialize from '../../serializers/post';
|
||||
*/
|
||||
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();
|
||||
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
|
||||
|
Reference in New Issue
Block a user