Skip to content
Snippets Groups Projects
Commit 67f9c158 authored by syuilo's avatar syuilo
Browse files

wip

parent 583b6433
No related branches found
No related tags found
No related merge requests found
File moved
File moved
File moved
......@@ -3,6 +3,7 @@
/**
* Module dependencies
*/
import it from '../it';
import Post from '../models/post';
import serialize from '../serializers/post';
......@@ -15,39 +16,27 @@ import serialize from '../serializers/post';
module.exports = (params) =>
new Promise(async (res, rej) => {
// Get 'include_replies' parameter
let includeReplies = params.include_replies;
if (includeReplies === true) {
includeReplies = true;
} else {
includeReplies = false;
}
const [includeReplies, includeRepliesErr] = it(params.include_replies).expect.boolean().default(true).qed();
if (includeRepliesErr) return rej('invalid include_replies param');
// Get 'include_reposts' parameter
let includeReposts = params.include_reposts;
if (includeReposts === true) {
includeReposts = true;
} else {
includeReposts = false;
}
const [includeReposts, includeRepostsErr] = it(params.include_reposts).expect.boolean().default(true).qed();
if (includeRepostsErr) return rej('invalid include_reposts param');
// Get 'limit' parameter
let limit = params.limit;
if (limit !== undefined && limit !== null) {
limit = parseInt(limit, 10);
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
if (limitErr) return rej('invalid limit param');
// From 1 to 100
if (!(1 <= limit && limit <= 100)) {
return rej('invalid limit range');
}
} else {
limit = 10;
}
// Get 'since_id' parameter
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed();
if (sinceIdErr) return rej('invalid since_id param');
const since = params.since_id || null;
const max = params.max_id || null;
// Get 'max_id' parameter
const [maxId, maxIdErr] = it(params.max_id).expect.id().qed();
if (maxIdErr) return rej('invalid max_id param');
// Check if both of since_id and max_id is specified
if (since !== null && max !== null) {
if (sinceId !== null && maxId !== null) {
return rej('cannot set since_id and max_id');
}
......@@ -55,15 +44,15 @@ module.exports = (params) =>
const sort = {
_id: -1
};
const query = {};
if (since !== null) {
const query = {} as any;
if (sinceId) {
sort._id = 1;
query._id = {
$gt: new mongo.ObjectID(since)
$gt: sinceId
};
} else if (max !== null) {
} else if (maxId) {
query._id = {
$lt: new mongo.ObjectID(max)
$lt: maxId
};
}
......
......@@ -22,7 +22,7 @@ module.exports = (params, user) =>
// Get favoritee
const post = await Post.findOne({
_id: new mongo.ObjectID(postId)
_id: postId
});
if (post === null) {
......
......@@ -22,7 +22,7 @@ module.exports = (params, user) =>
// Get favoritee
const post = await Post.findOne({
_id: new mongo.ObjectID(postId)
_id: postId
});
if (post === null) {
......
......@@ -3,6 +3,7 @@
/**
* Module dependencies
*/
import it from '../it';
import User from '../models/user';
import serialize from '../serializers/user';
......@@ -16,23 +17,19 @@ import serialize from '../serializers/user';
module.exports = (params, me) =>
new Promise(async (res, rej) => {
// Get 'limit' parameter
let limit = params.limit;
if (limit !== undefined && limit !== null) {
limit = parseInt(limit, 10);
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
if (limitErr) return rej('invalid limit param');
// From 1 to 100
if (!(1 <= limit && limit <= 100)) {
return rej('invalid limit range');
}
} else {
limit = 10;
}
// Get 'since_id' parameter
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed();
if (sinceIdErr) return rej('invalid since_id param');
const since = params.since_id || null;
const max = params.max_id || null;
// Get 'max_id' parameter
const [maxId, maxIdErr] = it(params.max_id).expect.id().qed();
if (maxIdErr) return rej('invalid max_id param');
// Check if both of since_id and max_id is specified
if (since !== null && max !== null) {
if (sinceId !== null && maxId !== null) {
return rej('cannot set since_id and max_id');
}
......@@ -40,15 +37,15 @@ module.exports = (params, me) =>
const sort = {
_id: -1
};
const query = {};
if (since !== null) {
const query = {} as any;
if (sinceId) {
sort._id = 1;
query._id = {
$gt: new mongo.ObjectID(since)
$gt: sinceId
};
} else if (max !== null) {
} else if (maxId) {
query._id = {
$lt: new mongo.ObjectID(max)
$lt: maxId
};
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment