@ -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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user