summaryrefslogtreecommitdiff
path: root/src/api/endpoints
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-02-04 14:52:33 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-02-04 14:52:33 +0900
commitbcd65d290d25219631bb47570478378a698d0fa0 (patch)
treede3630065fcddeb1916668ef3b0b43a219340e2e /src/api/endpoints
parentwip (diff)
downloadsharkey-bcd65d290d25219631bb47570478378a698d0fa0.tar.gz
sharkey-bcd65d290d25219631bb47570478378a698d0fa0.tar.bz2
sharkey-bcd65d290d25219631bb47570478378a698d0fa0.zip
wip
Diffstat (limited to 'src/api/endpoints')
-rw-r--r--src/api/endpoints/aggregation/posts/reactions.ts11
-rw-r--r--src/api/endpoints/aggregation/users.ts13
-rw-r--r--src/api/endpoints/app/create.ts3
-rw-r--r--src/api/endpoints/channels/show.ts2
-rw-r--r--src/api/endpoints/drive/files/create.ts2
-rw-r--r--src/api/endpoints/drive/files/update.ts3
-rw-r--r--src/api/endpoints/drive/files/upload_from_url.ts2
-rw-r--r--src/api/endpoints/drive/folders/create.ts3
-rw-r--r--src/api/endpoints/drive/folders/update.ts3
-rw-r--r--src/api/endpoints/following/create.ts7
-rw-r--r--src/api/endpoints/following/delete.ts5
-rw-r--r--src/api/endpoints/i/update.ts3
-rw-r--r--src/api/endpoints/posts/reactions/create.ts9
-rw-r--r--src/api/endpoints/users/posts.ts4
-rw-r--r--src/api/endpoints/users/search.ts2
15 files changed, 35 insertions, 37 deletions
diff --git a/src/api/endpoints/aggregation/posts/reactions.ts b/src/api/endpoints/aggregation/posts/reactions.ts
index 2cd4588ae1..790b523be9 100644
--- a/src/api/endpoints/aggregation/posts/reactions.ts
+++ b/src/api/endpoints/aggregation/posts/reactions.ts
@@ -35,10 +35,13 @@ module.exports = (params) => new Promise(async (res, rej) => {
{ deleted_at: { $gt: startTime } }
]
}, {
- _id: false,
- post_id: false
- }, {
- sort: { created_at: -1 }
+ sort: {
+ _id: -1
+ },
+ fields: {
+ _id: false,
+ post_id: false
+ }
});
const graph = [];
diff --git a/src/api/endpoints/aggregation/users.ts b/src/api/endpoints/aggregation/users.ts
index 9eb2d035ec..e38ce92ff9 100644
--- a/src/api/endpoints/aggregation/users.ts
+++ b/src/api/endpoints/aggregation/users.ts
@@ -17,11 +17,14 @@ module.exports = params => new Promise(async (res, rej) => {
const users = await User
.find({}, {
- _id: false,
- created_at: true,
- deleted_at: true
- }, {
- sort: { created_at: -1 }
+ sort: {
+ _id: -1
+ },
+ fields: {
+ _id: false,
+ created_at: true,
+ deleted_at: true
+ }
});
const graph = [];
diff --git a/src/api/endpoints/app/create.ts b/src/api/endpoints/app/create.ts
index 71633f7def..0f688792a7 100644
--- a/src/api/endpoints/app/create.ts
+++ b/src/api/endpoints/app/create.ts
@@ -3,8 +3,7 @@
*/
import rndstr from 'rndstr';
import $ from 'cafy';
-import App from '../../models/app';
-import { isValidNameId }, { pack } from '../../models/app';
+import App, { isValidNameId, pack } from '../../models/app';
/**
* @swagger
diff --git a/src/api/endpoints/channels/show.ts b/src/api/endpoints/channels/show.ts
index 3238616fa5..332da64675 100644
--- a/src/api/endpoints/channels/show.ts
+++ b/src/api/endpoints/channels/show.ts
@@ -2,7 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import { default as Channel, IChannel }, { pack } from '../../models/channel';
+import Channel, { IChannel, pack } from '../../models/channel';
/**
* Show a channel
diff --git a/src/api/endpoints/drive/files/create.ts b/src/api/endpoints/drive/files/create.ts
index 7b424f3f5a..96bcace886 100644
--- a/src/api/endpoints/drive/files/create.ts
+++ b/src/api/endpoints/drive/files/create.ts
@@ -2,7 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import { validateFileName }, { pack } from '../../../models/drive-file';
+import { validateFileName, pack } from '../../../models/drive-file';
import create from '../../../common/add-file-to-drive';
/**
diff --git a/src/api/endpoints/drive/files/update.ts b/src/api/endpoints/drive/files/update.ts
index ff65a48f71..83da462113 100644
--- a/src/api/endpoints/drive/files/update.ts
+++ b/src/api/endpoints/drive/files/update.ts
@@ -3,8 +3,7 @@
*/
import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder';
-import DriveFile from '../../../models/drive-file';
-import { validateFileName }, { pack } from '../../../models/drive-file';
+import DriveFile, { validateFileName, pack } from '../../../models/drive-file';
import { publishDriveStream } from '../../../event';
/**
diff --git a/src/api/endpoints/drive/files/upload_from_url.ts b/src/api/endpoints/drive/files/upload_from_url.ts
index 009f06aaaf..68428747ef 100644
--- a/src/api/endpoints/drive/files/upload_from_url.ts
+++ b/src/api/endpoints/drive/files/upload_from_url.ts
@@ -3,7 +3,7 @@
*/
import * as URL from 'url';
import $ from 'cafy';
-import { validateFileName }, { pack } from '../../../models/drive-file';
+import { validateFileName, pack } from '../../../models/drive-file';
import create from '../../../common/add-file-to-drive';
import * as debug from 'debug';
import * as tmp from 'tmp';
diff --git a/src/api/endpoints/drive/folders/create.ts b/src/api/endpoints/drive/folders/create.ts
index 6543b11274..03f396ddc9 100644
--- a/src/api/endpoints/drive/folders/create.ts
+++ b/src/api/endpoints/drive/folders/create.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import DriveFolder from '../../../models/drive-folder';
-import { isValidFolderName }, { pack } from '../../../models/drive-folder';
+import DriveFolder, { isValidFolderName, pack } from '../../../models/drive-folder';
import { publishDriveStream } from '../../../event';
/**
diff --git a/src/api/endpoints/drive/folders/update.ts b/src/api/endpoints/drive/folders/update.ts
index 2adcadcb08..d3df8bdae5 100644
--- a/src/api/endpoints/drive/folders/update.ts
+++ b/src/api/endpoints/drive/folders/update.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import DriveFolder from '../../../models/drive-folder';
-import { isValidFolderName }, { pack } from '../../../models/drive-folder';
+import DriveFolder, { isValidFolderName, pack } from '../../../models/drive-folder';
import { publishDriveStream } from '../../../event';
/**
diff --git a/src/api/endpoints/following/create.ts b/src/api/endpoints/following/create.ts
index b4a2217b16..8e1aa34713 100644
--- a/src/api/endpoints/following/create.ts
+++ b/src/api/endpoints/following/create.ts
@@ -2,11 +2,10 @@
* Module dependencies
*/
import $ from 'cafy';
-import User from '../../models/user';
+import User, { pack as packUser } from '../../models/user';
import Following from '../../models/following';
import notify from '../../common/notify';
import event from '../../event';
-import serializeUser from '../../serializers/user';
/**
* Follow a user
@@ -77,8 +76,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Publish follow event
- event(follower._id, 'follow', await serializeUser(followee, follower));
- event(followee._id, 'followed', await serializeUser(follower, followee));
+ event(follower._id, 'follow', await packUser(followee, follower));
+ event(followee._id, 'followed', await packUser(follower, followee));
// Notify
notify(followee._id, follower._id, 'follow');
diff --git a/src/api/endpoints/following/delete.ts b/src/api/endpoints/following/delete.ts
index aa1639ef6c..b68cec09dd 100644
--- a/src/api/endpoints/following/delete.ts
+++ b/src/api/endpoints/following/delete.ts
@@ -2,10 +2,9 @@
* Module dependencies
*/
import $ from 'cafy';
-import User from '../../models/user';
+import User, { pack as packUser } from '../../models/user';
import Following from '../../models/following';
import event from '../../event';
-import serializeUser from '../../serializers/user';
/**
* Unfollow a user
@@ -78,5 +77,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Publish follow event
- event(follower._id, 'unfollow', await serializeUser(followee, follower));
+ event(follower._id, 'unfollow', await packUser(followee, follower));
});
diff --git a/src/api/endpoints/i/update.ts b/src/api/endpoints/i/update.ts
index cd4b1a13f5..7bbbf95900 100644
--- a/src/api/endpoints/i/update.ts
+++ b/src/api/endpoints/i/update.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import User from '../../models/user';
-import { isValidName, isValidDescription, isValidLocation, isValidBirthday }, { pack } from '../../models/user';
+import User, { isValidName, isValidDescription, isValidLocation, isValidBirthday, pack } from '../../models/user';
import event from '../../event';
import config from '../../../conf';
diff --git a/src/api/endpoints/posts/reactions/create.ts b/src/api/endpoints/posts/reactions/create.ts
index d537463dfe..0b0e0e294d 100644
--- a/src/api/endpoints/posts/reactions/create.ts
+++ b/src/api/endpoints/posts/reactions/create.ts
@@ -3,13 +3,12 @@
*/
import $ from 'cafy';
import Reaction from '../../../models/post-reaction';
-import Post from '../../../models/post';
+import Post, { pack as packPost } from '../../../models/post';
+import { pack as packUser } from '../../../models/user';
import Watching from '../../../models/post-watching';
import notify from '../../../common/notify';
import watch from '../../../common/watch-post';
import { publishPostStream, pushSw } from '../../../event';
-import serializePost from '../../../serializers/post';
-import serializeUser from '../../../serializers/user';
/**
* React to a post
@@ -90,8 +89,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
pushSw(post.user_id, 'reaction', {
- user: await serializeUser(user, post.user_id),
- post: await serializePost(post, post.user_id),
+ user: await packUser(user, post.user_id),
+ post: await packPost(post, post.user_id),
reaction: reaction
});
diff --git a/src/api/endpoints/users/posts.ts b/src/api/endpoints/users/posts.ts
index 285e5bc46c..0c8bceee3d 100644
--- a/src/api/endpoints/users/posts.ts
+++ b/src/api/endpoints/users/posts.ts
@@ -2,8 +2,8 @@
* Module dependencies
*/
import $ from 'cafy';
-import Post from '../../models/post';
-import User, { pack } from '../../models/user';
+import Post, { pack } from '../../models/post';
+import User from '../../models/user';
/**
* Get posts of a user
diff --git a/src/api/endpoints/users/search.ts b/src/api/endpoints/users/search.ts
index 1142db9e9b..39e2ff9890 100644
--- a/src/api/endpoints/users/search.ts
+++ b/src/api/endpoints/users/search.ts
@@ -51,7 +51,7 @@ async function byNative(res, rej, me, query, offset, max) {
// Serialize
res(await Promise.all(users.map(async user =>
- await serialize(user, me, { detail: true }))));
+ await pack(user, me, { detail: true }))));
}
// Search by Elasticsearch