summaryrefslogtreecommitdiff
path: root/src/api/common/get-friends.ts
blob: db6313816d99dc48153f145e3916780d07ef2da5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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 }
		}, {
			fields: {
				followee_id: true
			}
		});

	// ID list of other users who the I follows
	const myfollowingIds = myfollowing.map(follow => follow.followee_id);

	if (includeMe) {
		myfollowingIds.push(me);
	}

	return myfollowingIds;
};