summaryrefslogtreecommitdiff
path: root/src/server/api/common/get-friends.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/api/common/get-friends.ts')
-rw-r--r--src/server/api/common/get-friends.ts29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/server/api/common/get-friends.ts b/src/server/api/common/get-friends.ts
index c1cc3957d8..50ba71ea96 100644
--- a/src/server/api/common/get-friends.ts
+++ b/src/server/api/common/get-friends.ts
@@ -1,10 +1,10 @@
import * as mongodb from 'mongodb';
import Following from '../../../models/following';
-export default async (me: mongodb.ObjectID, includeMe: boolean = true) => {
+export const getFriendIds = async (me: mongodb.ObjectID, includeMe = true) => {
// Fetch relation to other users who the I follows
// SELECT followee
- const myfollowing = await Following
+ const followings = await Following
.find({
followerId: me
}, {
@@ -14,7 +14,7 @@ export default async (me: mongodb.ObjectID, includeMe: boolean = true) => {
});
// ID list of other users who the I follows
- const myfollowingIds = myfollowing.map(follow => follow.followeeId);
+ const myfollowingIds = followings.map(following => following.followeeId);
if (includeMe) {
myfollowingIds.push(me);
@@ -22,3 +22,26 @@ export default async (me: mongodb.ObjectID, includeMe: boolean = true) => {
return myfollowingIds;
};
+
+export const getFriends = async (me: mongodb.ObjectID, includeMe = true) => {
+ // Fetch relation to other users who the I follows
+ const followings = await Following
+ .find({
+ followerId: me
+ });
+
+ // ID list of other users who the I follows
+ const myfollowings = followings.map(following => ({
+ id: following.followeeId,
+ stalk: following.stalk
+ }));
+
+ if (includeMe) {
+ myfollowings.push({
+ id: me,
+ stalk: true
+ });
+ }
+
+ return myfollowings;
+};