summaryrefslogtreecommitdiff
path: root/src/api/common/get-friends.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/common/get-friends.ts')
-rw-r--r--src/api/common/get-friends.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/api/common/get-friends.ts b/src/api/common/get-friends.ts
new file mode 100644
index 0000000000..5d50bcdb13
--- /dev/null
+++ b/src/api/common/get-friends.ts
@@ -0,0 +1,25 @@
+import * as mongodb from 'mongodb';
+import Following from '../models/following';
+
+export default async (me: mongodb.ObjectID, includeMe: boolean = true) => {
+ // Fetch relation to other users who the I follows
+ // SELECT followee
+ const myfollowing = await Following
+ .find({
+ follower_id: me,
+ // 削除されたドキュメントは除く
+ deleted_at: { $exists: false }
+ }, {
+ followee_id: true
+ })
+ .toArray();
+
+ // ID list of other users who the I follows
+ const myfollowingIds = myfollowing.map(follow => follow.followee_id);
+
+ if (includeMe) {
+ myfollowingIds.push(me);
+ }
+
+ return myfollowingIds;
+};