mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
added getMutuals
service
This commit is contained in:
parent
a2f77e7f05
commit
19a5f4e6dd
30
packages/server/src/services/getMutuals/index.js
Normal file
30
packages/server/src/services/getMutuals/index.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { User, UserFollow } from "@models"
|
||||||
|
|
||||||
|
// TODO: Sort follows by last activity
|
||||||
|
export default async (payload = {}) => {
|
||||||
|
const from_user_id = payload.from_user_id
|
||||||
|
|
||||||
|
if (!from_user_id) {
|
||||||
|
throw new Error("Missing from_user_id")
|
||||||
|
}
|
||||||
|
|
||||||
|
let mutuals = []
|
||||||
|
|
||||||
|
// load friends and recents users
|
||||||
|
const follows = await UserFollow.find({
|
||||||
|
user_id: from_user_id,
|
||||||
|
})
|
||||||
|
.limit(15)
|
||||||
|
|
||||||
|
mutuals = await UserFollow.find({
|
||||||
|
user_id: follows.map((follow) => follow.to.toString()),
|
||||||
|
to: from_user_id,
|
||||||
|
})
|
||||||
|
|
||||||
|
// load data user
|
||||||
|
mutuals = await User.find({
|
||||||
|
_id: mutuals.map((mutual) => mutual.user_id.toString()),
|
||||||
|
})
|
||||||
|
|
||||||
|
return mutuals
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user