paricafe/src/server/api/common/get-friends.ts
2018-04-02 22:00:40 +09:00

24 lines
546 B
TypeScript

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({
followerId: me
}, {
fields: {
followeeId: true
}
});
// ID list of other users who the I follows
const myfollowingIds = myfollowing.map(follow => follow.followeeId);
if (includeMe) {
myfollowingIds.push(me);
}
return myfollowingIds;
};