2016-12-28 16:49:51 -06:00
|
|
|
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 }
|
|
|
|
}, {
|
2017-01-17 15:10:56 -06:00
|
|
|
fields: {
|
|
|
|
followee_id: true
|
|
|
|
}
|
2017-01-16 20:11:22 -06:00
|
|
|
});
|
2016-12-28 16:49:51 -06:00
|
|
|
|
|
|
|
// ID list of other users who the I follows
|
|
|
|
const myfollowingIds = myfollowing.map(follow => follow.followee_id);
|
|
|
|
|
|
|
|
if (includeMe) {
|
|
|
|
myfollowingIds.push(me);
|
|
|
|
}
|
|
|
|
|
|
|
|
return myfollowingIds;
|
|
|
|
};
|