mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
implement getUserFollowers
This commit is contained in:
parent
5e67a1f578
commit
18a5f7d229
@ -146,6 +146,44 @@ export default class User {
|
||||
return data
|
||||
}
|
||||
|
||||
static async getUserFollowers({
|
||||
user_id,
|
||||
username,
|
||||
limit = 20,
|
||||
offset = 0,
|
||||
}) {
|
||||
if (!User.bridge) {
|
||||
return false
|
||||
}
|
||||
|
||||
// if user_id or username is not provided, set with current user
|
||||
if (!user_id && !username) {
|
||||
const token = await Session.decodedToken()
|
||||
|
||||
if (token) {
|
||||
username = token.username
|
||||
} else {
|
||||
throw new Error("username or user_id is required")
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: if user_id is not provided, get it from username
|
||||
if (!user_id) {
|
||||
|
||||
}
|
||||
|
||||
const { data } = await app.api.customRequest("main", {
|
||||
method: "GET",
|
||||
url: `/user/${user_id}/followers`,
|
||||
params: {
|
||||
limit,
|
||||
offset,
|
||||
}
|
||||
})
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
static async getConnectedUsersFollowing() {
|
||||
if (!User.bridge) {
|
||||
return false
|
||||
|
@ -149,6 +149,29 @@ export default class FollowerController extends Controller {
|
||||
}
|
||||
|
||||
get = {
|
||||
"/user/:user_id/followers": async (req, res) => {
|
||||
const { limit = 30, offset } = req.query
|
||||
|
||||
let followers = []
|
||||
|
||||
const follows = await UserFollow.find({
|
||||
to: req.params.user_id,
|
||||
})
|
||||
.limit(limit)
|
||||
.skip(offset)
|
||||
|
||||
for await (const follow of follows) {
|
||||
const user = await User.findById(follow.user_id)
|
||||
|
||||
if (!user) {
|
||||
continue
|
||||
}
|
||||
|
||||
followers.push(user.toObject())
|
||||
}
|
||||
|
||||
return res.json(followers)
|
||||
},
|
||||
"/followers": Schematized({
|
||||
required: ["user_id"],
|
||||
select: ["user_id"],
|
||||
|
Loading…
x
Reference in New Issue
Block a user