jormungandr-bite/src/server/api/common/get-friends.ts

25 lines
546 B
TypeScript
Raw Normal View History

2016-12-28 15:49:51 -07:00
import * as mongodb from 'mongodb';
2018-03-29 05:32:18 -06:00
import Following from '../../../models/following';
2016-12-28 15:49:51 -07:00
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({
followerId: me
2016-12-28 15:49:51 -07:00
}, {
2017-01-17 14:10:56 -07:00
fields: {
2018-03-28 23:48:47 -06:00
followeeId: true
2017-01-17 14:10:56 -07:00
}
2017-01-16 19:11:22 -07:00
});
2016-12-28 15:49:51 -07:00
// ID list of other users who the I follows
2018-03-28 23:48:47 -06:00
const myfollowingIds = myfollowing.map(follow => follow.followeeId);
2016-12-28 15:49:51 -07:00
if (includeMe) {
myfollowingIds.push(me);
}
return myfollowingIds;
};