summaryrefslogtreecommitdiff
path: root/src/api/endpoints
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-01-17 11:11:22 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-01-17 11:11:22 +0900
commit9f81288fccdbaf9184d49e61680747945b34f23d (patch)
treedce25db34136ffd9c05852ed4c2c493c23c96c07 /src/api/endpoints
parentFix bug (diff)
downloadsharkey-9f81288fccdbaf9184d49e61680747945b34f23d.tar.gz
sharkey-9f81288fccdbaf9184d49e61680747945b34f23d.tar.bz2
sharkey-9f81288fccdbaf9184d49e61680747945b34f23d.zip
Fix bug
Diffstat (limited to 'src/api/endpoints')
-rw-r--r--src/api/endpoints/aggregation/posts/like.js3
-rw-r--r--src/api/endpoints/aggregation/posts/likes.js3
-rw-r--r--src/api/endpoints/aggregation/posts/reply.js3
-rw-r--r--src/api/endpoints/aggregation/posts/repost.js3
-rw-r--r--src/api/endpoints/aggregation/users/followers.js3
-rw-r--r--src/api/endpoints/aggregation/users/following.js3
-rw-r--r--src/api/endpoints/aggregation/users/like.js3
-rw-r--r--src/api/endpoints/aggregation/users/post.js3
-rw-r--r--src/api/endpoints/auth/accept.js8
-rw-r--r--src/api/endpoints/drive.js11
-rw-r--r--src/api/endpoints/drive/files.js3
-rw-r--r--src/api/endpoints/drive/files/find.js3
-rw-r--r--src/api/endpoints/drive/files/update.js4
-rw-r--r--src/api/endpoints/drive/folders.js3
-rw-r--r--src/api/endpoints/drive/folders/find.js3
-rw-r--r--src/api/endpoints/drive/folders/update.js4
-rw-r--r--src/api/endpoints/drive/stream.js3
-rw-r--r--src/api/endpoints/following/create.js4
-rw-r--r--src/api/endpoints/following/delete.js6
-rw-r--r--src/api/endpoints/i/appdata/set.js4
-rw-r--r--src/api/endpoints/i/favorites.js5
-rw-r--r--src/api/endpoints/i/notifications.js5
-rw-r--r--src/api/endpoints/i/signin_history.js5
-rw-r--r--src/api/endpoints/i/update.js5
-rw-r--r--src/api/endpoints/messaging/history.js5
-rw-r--r--src/api/endpoints/messaging/messages.js5
-rw-r--r--src/api/endpoints/messaging/messages/create.js4
-rw-r--r--src/api/endpoints/my/apps.js5
-rw-r--r--src/api/endpoints/notifications/mark_as_read.js2
-rw-r--r--src/api/endpoints/posts.js5
-rw-r--r--src/api/endpoints/posts/create.js18
-rw-r--r--src/api/endpoints/posts/likes.js5
-rw-r--r--src/api/endpoints/posts/likes/create.js6
-rw-r--r--src/api/endpoints/posts/likes/delete.js8
-rw-r--r--src/api/endpoints/posts/mentions.js5
-rw-r--r--src/api/endpoints/posts/replies.js5
-rw-r--r--src/api/endpoints/posts/reposts.js5
-rw-r--r--src/api/endpoints/posts/search.js8
-rw-r--r--src/api/endpoints/posts/timeline.js5
-rw-r--r--src/api/endpoints/users.js5
-rw-r--r--src/api/endpoints/users/followers.js5
-rw-r--r--src/api/endpoints/users/following.js5
-rw-r--r--src/api/endpoints/users/posts.js5
-rw-r--r--src/api/endpoints/users/recommendation.js5
-rw-r--r--src/api/endpoints/users/search.js6
-rw-r--r--src/api/endpoints/users/search_by_username.js3
46 files changed, 89 insertions, 136 deletions
diff --git a/src/api/endpoints/aggregation/posts/like.js b/src/api/endpoints/aggregation/posts/like.js
index b82c494ff1..b5aa0a21af 100644
--- a/src/api/endpoints/aggregation/posts/like.js
+++ b/src/api/endpoints/aggregation/posts/like.js
@@ -48,8 +48,7 @@ module.exports = (params) =>
_id: '$date',
count: { $sum: 1 }
}}
- ])
- .toArray();
+ ]);
datas.forEach(data => {
data.date = data._id;
diff --git a/src/api/endpoints/aggregation/posts/likes.js b/src/api/endpoints/aggregation/posts/likes.js
index 0317245159..2ea22516f5 100644
--- a/src/api/endpoints/aggregation/posts/likes.js
+++ b/src/api/endpoints/aggregation/posts/likes.js
@@ -45,8 +45,7 @@ module.exports = (params) =>
post_id: false
}, {
sort: { created_at: -1 }
- })
- .toArray();
+ });
const graph = [];
diff --git a/src/api/endpoints/aggregation/posts/reply.js b/src/api/endpoints/aggregation/posts/reply.js
index e578bc6d7d..d79ccafb1c 100644
--- a/src/api/endpoints/aggregation/posts/reply.js
+++ b/src/api/endpoints/aggregation/posts/reply.js
@@ -47,8 +47,7 @@ module.exports = (params) =>
_id: '$date',
count: { $sum: 1 }
}}
- ])
- .toArray();
+ ]);
datas.forEach(data => {
data.date = data._id;
diff --git a/src/api/endpoints/aggregation/posts/repost.js b/src/api/endpoints/aggregation/posts/repost.js
index 38d63442a8..3e4840510d 100644
--- a/src/api/endpoints/aggregation/posts/repost.js
+++ b/src/api/endpoints/aggregation/posts/repost.js
@@ -47,8 +47,7 @@ module.exports = (params) =>
_id: '$date',
count: { $sum: 1 }
}}
- ])
- .toArray();
+ ]);
datas.forEach(data => {
data.date = data._id;
diff --git a/src/api/endpoints/aggregation/users/followers.js b/src/api/endpoints/aggregation/users/followers.js
index 16dda09675..f49c2a2fcd 100644
--- a/src/api/endpoints/aggregation/users/followers.js
+++ b/src/api/endpoints/aggregation/users/followers.js
@@ -46,8 +46,7 @@ module.exports = (params) =>
followee_id: false
}, {
sort: { created_at: -1 }
- })
- .toArray();
+ });
const graph = [];
diff --git a/src/api/endpoints/aggregation/users/following.js b/src/api/endpoints/aggregation/users/following.js
index 7b7448d715..785e5a15c3 100644
--- a/src/api/endpoints/aggregation/users/following.js
+++ b/src/api/endpoints/aggregation/users/following.js
@@ -46,8 +46,7 @@ module.exports = (params) =>
followee_id: false
}, {
sort: { created_at: -1 }
- })
- .toArray();
+ });
const graph = [];
diff --git a/src/api/endpoints/aggregation/users/like.js b/src/api/endpoints/aggregation/users/like.js
index 830f1f1bba..f5344f6ba3 100644
--- a/src/api/endpoints/aggregation/users/like.js
+++ b/src/api/endpoints/aggregation/users/like.js
@@ -48,8 +48,7 @@ module.exports = (params) =>
_id: '$date',
count: { $sum: 1 }
}}
- ])
- .toArray();
+ ]);
datas.forEach(data => {
data.date = data._id;
diff --git a/src/api/endpoints/aggregation/users/post.js b/src/api/endpoints/aggregation/users/post.js
index d75df30f5d..f968ff4158 100644
--- a/src/api/endpoints/aggregation/users/post.js
+++ b/src/api/endpoints/aggregation/users/post.js
@@ -70,8 +70,7 @@ module.exports = (params) =>
count: '$count'
}}
} }
- ])
- .toArray();
+ ]);
datas.forEach(data => {
data.date = data._id;
diff --git a/src/api/endpoints/auth/accept.js b/src/api/endpoints/auth/accept.js
index 131a0e5611..fce4fdc9cd 100644
--- a/src/api/endpoints/auth/accept.js
+++ b/src/api/endpoints/auth/accept.js
@@ -87,12 +87,8 @@ module.exports = (params, user) =>
}
// Update session
- await AuthSess.updateOne({
- _id: session._id
- }, {
- $set: {
- user_id: user._id
- }
+ await AuthSess.update(session._id, {
+ user_id: user._id
});
// Response
diff --git a/src/api/endpoints/drive.js b/src/api/endpoints/drive.js
index 4df4ac33fa..f39019e6ea 100644
--- a/src/api/endpoints/drive.js
+++ b/src/api/endpoints/drive.js
@@ -16,12 +16,11 @@ module.exports = (params, user) =>
new Promise(async (res, rej) =>
{
// Fetch all files to calculate drive usage
- const files = await DriveFile
- .find({ user_id: user._id }, {
- datasize: true,
- _id: false
- })
- .toArray();
+ const files = await DriveFile
+ .find({ user_id: user._id }, {
+ datasize: true,
+ _id: false
+ });
// Calculate drive usage (in byte)
const usage = files.map(file => file.datasize).reduce((x, y) => x + y, 0);
diff --git a/src/api/endpoints/drive/files.js b/src/api/endpoints/drive/files.js
index 7e8ff59f2a..512d17db6a 100644
--- a/src/api/endpoints/drive/files.js
+++ b/src/api/endpoints/drive/files.js
@@ -73,8 +73,7 @@ module.exports = (params, user, app) =>
}, {
limit: limit,
sort: sort
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(files.map(async file =>
diff --git a/src/api/endpoints/drive/files/find.js b/src/api/endpoints/drive/files/find.js
index e4e4c230d2..74f2e4026f 100644
--- a/src/api/endpoints/drive/files/find.js
+++ b/src/api/endpoints/drive/files/find.js
@@ -39,8 +39,7 @@ module.exports = (params, user) =>
folder_id: folder
}, {
data: false
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(files.map(async file =>
diff --git a/src/api/endpoints/drive/files/update.js b/src/api/endpoints/drive/files/update.js
index bbcb10b42d..13ec30b4fb 100644
--- a/src/api/endpoints/drive/files/update.js
+++ b/src/api/endpoints/drive/files/update.js
@@ -74,9 +74,7 @@ module.exports = (params, user) =>
}
}
- DriveFile.updateOne({ _id: file._id }, {
- $set: file
- });
+ DriveFile.update(file._id, file);
// Serialize
const fileObj = await serialize(file);
diff --git a/src/api/endpoints/drive/folders.js b/src/api/endpoints/drive/folders.js
index f95a60036f..d2a9da2808 100644
--- a/src/api/endpoints/drive/folders.js
+++ b/src/api/endpoints/drive/folders.js
@@ -73,8 +73,7 @@ module.exports = (params, user, app) =>
}, {
limit: limit,
sort: sort
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(folders.map(async folder =>
diff --git a/src/api/endpoints/drive/folders/find.js b/src/api/endpoints/drive/folders/find.js
index 01805dc910..9a2faf6d82 100644
--- a/src/api/endpoints/drive/folders/find.js
+++ b/src/api/endpoints/drive/folders/find.js
@@ -37,8 +37,7 @@ module.exports = (params, user) =>
name: name,
user_id: user._id,
parent_id: parentId
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(folders.map(async folder =>
diff --git a/src/api/endpoints/drive/folders/update.js b/src/api/endpoints/drive/folders/update.js
index ff26a09aae..f9aa2998a5 100644
--- a/src/api/endpoints/drive/folders/update.js
+++ b/src/api/endpoints/drive/folders/update.js
@@ -99,9 +99,7 @@ module.exports = (params, user) =>
}
// Update
- DriveFolder.updateOne({ _id: folder._id }, {
- $set: folder
- });
+ DriveFolder.update(folder._id, folder);
// Serialize
const folderObj = await serialize(folder);
diff --git a/src/api/endpoints/drive/stream.js b/src/api/endpoints/drive/stream.js
index 0f407f5591..1d0cbaca2b 100644
--- a/src/api/endpoints/drive/stream.js
+++ b/src/api/endpoints/drive/stream.js
@@ -76,8 +76,7 @@ module.exports = (params, user) =>
}, {
limit: limit,
sort: sort
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(files.map(async file =>
diff --git a/src/api/endpoints/following/create.js b/src/api/endpoints/following/create.js
index da714cb180..90a6da9838 100644
--- a/src/api/endpoints/following/create.js
+++ b/src/api/endpoints/following/create.js
@@ -64,14 +64,14 @@ module.exports = (params, user) =>
res();
// Increment following count
- User.updateOne({ _id: follower._id }, {
+ User.update(follower._id, {
$inc: {
following_count: 1
}
});
// Increment followers count
- User.updateOne({ _id: followee._id }, {
+ User.update({ _id: followee._id }, {
$inc: {
followers_count: 1
}
diff --git a/src/api/endpoints/following/delete.js b/src/api/endpoints/following/delete.js
index f1096801b6..9bb1b082e9 100644
--- a/src/api/endpoints/following/delete.js
+++ b/src/api/endpoints/following/delete.js
@@ -53,7 +53,7 @@ module.exports = (params, user) =>
}
// Delete following
- await Following.updateOne({
+ await Following.update({
_id: exist._id
}, {
$set: {
@@ -65,14 +65,14 @@ module.exports = (params, user) =>
res();
// Decrement following count
- User.updateOne({ _id: follower._id }, {
+ User.update({ _id: follower._id }, {
$inc: {
following_count: -1
}
});
// Decrement followers count
- User.updateOne({ _id: followee._id }, {
+ User.update({ _id: followee._id }, {
$inc: {
followers_count: -1
}
diff --git a/src/api/endpoints/i/appdata/set.js b/src/api/endpoints/i/appdata/set.js
index e161a803d0..d6506a44fa 100644
--- a/src/api/endpoints/i/appdata/set.js
+++ b/src/api/endpoints/i/appdata/set.js
@@ -29,7 +29,7 @@ module.exports = (params, user, app, isSecure) =>
data: Object.assign(user.data || {}, JSON.parse(data))
}
};
- await User.updateOne({ _id: user._id }, set);
+ await User.update({ _id: user._id }, set);
res(204);
} else {
const appdata = await Appdata.findOne({
@@ -41,7 +41,7 @@ module.exports = (params, user, app, isSecure) =>
data: Object.assign((appdata || {}).data || {}, JSON.parse(data))
}
};
- await Appdata.updateOne({
+ await Appdata.update({
app_id: app._id,
user_id: user._id
}, Object.assign({
diff --git a/src/api/endpoints/i/favorites.js b/src/api/endpoints/i/favorites.js
index e30ea2867b..d943bec32a 100644
--- a/src/api/endpoints/i/favorites.js
+++ b/src/api/endpoints/i/favorites.js
@@ -44,14 +44,13 @@ module.exports = (params) =>
const favorites = await Favorites
.find({
user_id: user._id
- }, {}, {
+ }, {
limit: limit,
skip: offset,
sort: {
_id: sort == 'asc' ? 1 : -1
}
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(favorites.map(async favorite =>
diff --git a/src/api/endpoints/i/notifications.js b/src/api/endpoints/i/notifications.js
index a28ceb76a0..02a2fb1798 100644
--- a/src/api/endpoints/i/notifications.js
+++ b/src/api/endpoints/i/notifications.js
@@ -92,11 +92,10 @@ module.exports = (params, user) =>
// Issue query
const notifications = await Notification
- .find(query, {}, {
+ .find(query, {
limit: limit,
sort: sort
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(notifications.map(async notification =>
diff --git a/src/api/endpoints/i/signin_history.js b/src/api/endpoints/i/signin_history.js
index 7def8a41e5..c373e7b7a4 100644
--- a/src/api/endpoints/i/signin_history.js
+++ b/src/api/endpoints/i/signin_history.js
@@ -59,11 +59,10 @@ module.exports = (params, user) =>
// Issue query
const history = await Signin
- .find(query, {}, {
+ .find(query, {
limit: limit,
sort: sort
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(history.map(async record =>
diff --git a/src/api/endpoints/i/update.js b/src/api/endpoints/i/update.js
index 3a6b9da905..0306a106e0 100644
--- a/src/api/endpoints/i/update.js
+++ b/src/api/endpoints/i/update.js
@@ -8,6 +8,7 @@ import User from '../../models/user';
import { isValidBirthday } from '../../models/user';
import serialize from '../../serializers/user';
import event from '../../event';
+import config from '../../../conf';
/**
* Update myself
@@ -73,9 +74,7 @@ module.exports = async (params, user, _, isSecure) =>
user.banner_id = new mongo.ObjectID(banner);
}
- await User.updateOne({ _id: user._id }, {
- $set: user
- });
+ await User.update(user._id, user);
// Serialize
const iObj = await serialize(user, user, {
diff --git a/src/api/endpoints/messaging/history.js b/src/api/endpoints/messaging/history.js
index dafb38fd1a..e6e6ac87b1 100644
--- a/src/api/endpoints/messaging/history.js
+++ b/src/api/endpoints/messaging/history.js
@@ -34,13 +34,12 @@ module.exports = (params, user) =>
const history = await History
.find({
user_id: user._id
- }, {}, {
+ }, {
limit: limit,
sort: {
updated_at: -1
}
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(history.map(async h =>
diff --git a/src/api/endpoints/messaging/messages.js b/src/api/endpoints/messaging/messages.js
index 12bd13597a..9440e2b3aa 100644
--- a/src/api/endpoints/messaging/messages.js
+++ b/src/api/endpoints/messaging/messages.js
@@ -90,11 +90,10 @@ module.exports = (params, user) =>
// Issue query
const messages = await Message
- .find(query, {}, {
+ .find(query, {
limit: limit,
sort: sort
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(messages.map(async message =>
diff --git a/src/api/endpoints/messaging/messages/create.js b/src/api/endpoints/messaging/messages/create.js
index 33634a6140..1cd02cfc58 100644
--- a/src/api/endpoints/messaging/messages/create.js
+++ b/src/api/endpoints/messaging/messages/create.js
@@ -125,7 +125,7 @@ module.exports = (params, user) =>
}
// 履歴作成(自分)
- History.updateOne({
+ History.update({
user_id: user._id,
partner: recipient._id
}, {
@@ -138,7 +138,7 @@ module.exports = (params, user) =>
});
// 履歴作成(相手)
- History.updateOne({
+ History.update({
user_id: recipient._id,
partner: user._id
}, {
diff --git a/src/api/endpoints/my/apps.js b/src/api/endpoints/my/apps.js
index d23bc38b1c..3745a92e0f 100644
--- a/src/api/endpoints/my/apps.js
+++ b/src/api/endpoints/my/apps.js
@@ -44,14 +44,13 @@ module.exports = (params, user) =>
// Execute query
const apps = await App
- .find(query, {}, {
+ .find(query, {
limit: limit,
skip: offset,
sort: {
created_at: -1
}
- })
- .toArray();
+ });
// Reply
res(await Promise.all(apps.map(async app =>
diff --git a/src/api/endpoints/notifications/mark_as_read.js b/src/api/endpoints/notifications/mark_as_read.js
index 16eb2009ac..855596a865 100644
--- a/src/api/endpoints/notifications/mark_as_read.js
+++ b/src/api/endpoints/notifications/mark_as_read.js
@@ -37,7 +37,7 @@ module.exports = (params, user) =>
// Update
notification.is_read = true;
- Notification.updateOne({ _id: notification._id }, {
+ Notification.update({ _id: notification._id }, {
$set: {
is_read: true
}
diff --git a/src/api/endpoints/posts.js b/src/api/endpoints/posts.js
index 05fc871ec1..0428b400bc 100644
--- a/src/api/endpoints/posts.js
+++ b/src/api/endpoints/posts.js
@@ -54,11 +54,10 @@ module.exports = (params) =>
// Issue query
const posts = await Post
- .find(query, {}, {
+ .find(query, {
limit: limit,
sort: sort
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(posts.map(async post => await serialize(post))));
diff --git a/src/api/endpoints/posts/create.js b/src/api/endpoints/posts/create.js
index 694e6fc824..c3291bc725 100644
--- a/src/api/endpoints/posts/create.js
+++ b/src/api/endpoints/posts/create.js
@@ -13,6 +13,7 @@ import serialize from '../../serializers/post';
import createFile from '../../common/add-file-to-drive';
import notify from '../../common/notify';
import event from '../../event';
+import config from '../../../conf';
/**
* 最大文字数
@@ -103,7 +104,7 @@ module.exports = (params, user, app) =>
// Fetch recently post
const latestPost = await Post.findOne({
user_id: user._id
- }, {}, {
+ }, {
sort: {
_id: -1
}
@@ -152,7 +153,7 @@ module.exports = (params, user, app) =>
}
// 投稿を作成
- const inserted = await Post.insert({
+ const post = await Post.insert({
created_at: new Date(),
media_ids: media ? files.map(file => file._id) : undefined,
reply_to_id: replyTo ? replyTo._id : undefined,
@@ -162,8 +163,6 @@ module.exports = (params, user, app) =>
app_id: app ? app._id : null
});
- const post = inserted.ops[0];
-
// Serialize
const postObj = await serialize(post);
@@ -200,15 +199,14 @@ module.exports = (params, user, app) =>
}, {
follower_id: true,
_id: false
- })
- .toArray();
+ });
// Publish event to followers stream
followers.forEach(following =>
event(following.follower_id, 'post', postObj));
// Increment my posts count
- User.updateOne({ _id: user._id }, {
+ User.update({ _id: user._id }, {
$inc: {
posts_count: 1
}
@@ -217,7 +215,7 @@ module.exports = (params, user, app) =>
// If has in reply to post
if (replyTo) {
// Increment replies count
- Post.updateOne({ _id: replyTo._id }, {
+ Post.update({ _id: replyTo._id }, {
$inc: {
replies_count: 1
}
@@ -262,7 +260,7 @@ module.exports = (params, user, app) =>
if (!existRepost) {
// Update repostee status
- Post.updateOne({ _id: repost._id }, {
+ Post.update({ _id: repost._id }, {
$inc: {
repost_count: 1
}
@@ -336,7 +334,7 @@ module.exports = (params, user, app) =>
// Append mentions data
if (mentions.length > 0) {
- Post.updateOne({ _id: post._id }, {
+ Post.update({ _id: post._id }, {
$set: {
mentions: mentions
}
diff --git a/src/api/endpoints/posts/likes.js b/src/api/endpoints/posts/likes.js
index 4778189fc6..6d3ab866be 100644
--- a/src/api/endpoints/posts/likes.js
+++ b/src/api/endpoints/posts/likes.js
@@ -62,14 +62,13 @@ module.exports = (params, user) =>
.find({
post_id: post._id,
deleted_at: { $exists: false }
- }, {}, {
+ }, {
limit: limit,
skip: offset,
sort: {
_id: sort == 'asc' ? 1 : -1
}
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(likes.map(async like =>
diff --git a/src/api/endpoints/posts/likes/create.js b/src/api/endpoints/posts/likes/create.js
index eb35c1e4b0..73054be875 100644
--- a/src/api/endpoints/posts/likes/create.js
+++ b/src/api/endpoints/posts/likes/create.js
@@ -66,21 +66,21 @@ module.exports = (params, user) =>
res();
// Increment likes count
- Post.updateOne({ _id: post._id }, {
+ Post.update({ _id: post._id }, {
$inc: {
likes_count: 1
}
});
// Increment user likes count
- User.updateOne({ _id: user._id }, {
+ User.update({ _id: user._id }, {
$inc: {
likes_count: 1
}
});
// Increment user liked count
- User.updateOne({ _id: post.user_id }, {
+ User.update({ _id: post.user_id }, {
$inc: {
liked_count: 1
}
diff --git a/src/api/endpoints/posts/likes/delete.js b/src/api/endpoints/posts/likes/delete.js
index b60df63af5..b5b7e5177c 100644
--- a/src/api/endpoints/posts/likes/delete.js
+++ b/src/api/endpoints/posts/likes/delete.js
@@ -46,7 +46,7 @@ module.exports = (params, user) =>
}
// Delete like
- await Like.updateOne({
+ await Like.update({
_id: exist._id
}, {
$set: {
@@ -58,21 +58,21 @@ module.exports = (params, user) =>
res();
// Decrement likes count
- Post.updateOne({ _id: post._id }, {
+ Post.update({ _id: post._id }, {
$inc: {
likes_count: -1
}
});
// Decrement user likes count
- User.updateOne({ _id: user._id }, {
+ User.update({ _id: user._id }, {
$inc: {
likes_count: -1
}
});
// Decrement user liked count
- User.updateOne({ _id: post.user_id }, {
+ User.update({ _id: post.user_id }, {
$inc: {
liked_count: -1
}
diff --git a/src/api/endpoints/posts/mentions.js b/src/api/endpoints/posts/mentions.js
index 6358e1f4a9..dbb69bd5ac 100644
--- a/src/api/endpoints/posts/mentions.js
+++ b/src/api/endpoints/posts/mentions.js
@@ -72,11 +72,10 @@ module.exports = (params, user) =>
// Issue query
const mentions = await Post
- .find(query, {}, {
+ .find(query, {
limit: limit,
sort: sort
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(mentions.map(async mention =>
diff --git a/src/api/endpoints/posts/replies.js b/src/api/endpoints/posts/replies.js
index 5eab6f896f..5ce1133e00 100644
--- a/src/api/endpoints/posts/replies.js
+++ b/src/api/endpoints/posts/replies.js
@@ -58,14 +58,13 @@ module.exports = (params, user) =>
// Issue query
const replies = await Post
- .find({ reply_to_id: post._id }, {}, {
+ .find({ reply_to_id: post._id }, {
limit: limit,
skip: offset,
sort: {
_id: sort == 'asc' ? 1 : -1
}
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(replies.map(async post =>
diff --git a/src/api/endpoints/posts/reposts.js b/src/api/endpoints/posts/reposts.js
index 8b418a682f..a118ca6fba 100644
--- a/src/api/endpoints/posts/reposts.js
+++ b/src/api/endpoints/posts/reposts.js
@@ -73,11 +73,10 @@ module.exports = (params, user) =>
// Issue query
const reposts = await Post
- .find(query, {}, {
+ .find(query, {
limit: limit,
sort: sort
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(reposts.map(async post =>
diff --git a/src/api/endpoints/posts/search.js b/src/api/endpoints/posts/search.js
index 0f214ef7ae..239517b993 100644
--- a/src/api/endpoints/posts/search.js
+++ b/src/api/endpoints/posts/search.js
@@ -65,8 +65,7 @@ async function byNative(res, rej, me, query, offset, max) {
},
limit: max,
skip: offset
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(posts.map(async post =>
@@ -120,12 +119,11 @@ async function byElasticsearch(res, rej, me, query, offset, max) {
_id: {
$in: hits
}
- }, {}, {
+ }, {
sort: {
_id: -1
}
- })
- .toArray();
+ });
posts.map(post => {
post._highlight = response.hits.hits.filter(hit => post._id.equals(hit._id))[0].highlight.text[0];
diff --git a/src/api/endpoints/posts/timeline.js b/src/api/endpoints/posts/timeline.js
index 489542da71..626f828ef8 100644
--- a/src/api/endpoints/posts/timeline.js
+++ b/src/api/endpoints/posts/timeline.js
@@ -65,11 +65,10 @@ module.exports = (params, user, app) =>
// Issue query
const timeline = await Post
- .find(query, {}, {
+ .find(query, {
limit: limit,
sort: sort
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(timeline.map(async post =>
diff --git a/src/api/endpoints/users.js b/src/api/endpoints/users.js
index cd40cdf4e1..1c6024e3ee 100644
--- a/src/api/endpoints/users.js
+++ b/src/api/endpoints/users.js
@@ -55,11 +55,10 @@ module.exports = (params, me) =>
// Issue query
const users = await User
- .find(query, {}, {
+ .find(query, {
limit: limit,
sort: sort
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(users.map(async user =>
diff --git a/src/api/endpoints/users/followers.js b/src/api/endpoints/users/followers.js
index 303f55e450..ac61361232 100644
--- a/src/api/endpoints/users/followers.js
+++ b/src/api/endpoints/users/followers.js
@@ -78,11 +78,10 @@ module.exports = (params, me) =>
// Get followers
const following = await Following
- .find(query, {}, {
+ .find(query, {
limit: limit + 1,
sort: { _id: -1 }
- })
- .toArray();
+ });
// 「次のページ」があるかどうか
const inStock = following.length === limit + 1;
diff --git a/src/api/endpoints/users/following.js b/src/api/endpoints/users/following.js
index ec3954563a..c1266b1d19 100644
--- a/src/api/endpoints/users/following.js
+++ b/src/api/endpoints/users/following.js
@@ -78,11 +78,10 @@ module.exports = (params, me) =>
// Get followers
const following = await Following
- .find(query, {}, {
+ .find(query, {
limit: limit + 1,
sort: { _id: -1 }
- })
- .toArray();
+ });
// 「次のページ」があるかどうか
const inStock = following.length === limit + 1;
diff --git a/src/api/endpoints/users/posts.js b/src/api/endpoints/users/posts.js
index 1b8dfe031b..8902cc314c 100644
--- a/src/api/endpoints/users/posts.js
+++ b/src/api/endpoints/users/posts.js
@@ -111,11 +111,10 @@ module.exports = (params, me) =>
// Issue query
const posts = await Post
- .find(query, {}, {
+ .find(query, {
limit: limit,
sort: sort
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(posts.map(async (post) =>
diff --git a/src/api/endpoints/users/recommendation.js b/src/api/endpoints/users/recommendation.js
index 9daab0ec57..d4c33c37a4 100644
--- a/src/api/endpoints/users/recommendation.js
+++ b/src/api/endpoints/users/recommendation.js
@@ -46,14 +46,13 @@ module.exports = (params, me) =>
_id: {
$nin: followingIds
}
- }, {}, {
+ }, {
limit: limit,
skip: offset,
sort: {
followers_count: -1
}
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(users.map(async user =>
diff --git a/src/api/endpoints/users/search.js b/src/api/endpoints/users/search.js
index 3a3fe677db..f8b2eccec6 100644
--- a/src/api/endpoints/users/search.js
+++ b/src/api/endpoints/users/search.js
@@ -63,8 +63,7 @@ async function byNative(res, rej, me, query, offset, max) {
}, {
name: new RegExp(escapedQuery)
}]
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(users.map(async user =>
@@ -106,8 +105,7 @@ async function byElasticsearch(res, rej, me, query, offset, max) {
_id: {
$in: hits
}
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(users.map(async user =>
diff --git a/src/api/endpoints/users/search_by_username.js b/src/api/endpoints/users/search_by_username.js
index 9e3efbd85c..2f19df3c8a 100644
--- a/src/api/endpoints/users/search_by_username.js
+++ b/src/api/endpoints/users/search_by_username.js
@@ -56,8 +56,7 @@ module.exports = (params, me) =>
}, {
limit: limit,
skip: offset
- })
- .toArray();
+ });
// Serialize
res(await Promise.all(users.map(async user =>