mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
implement connected_users_following
endpoint
This commit is contained in:
parent
cfe31ba5b5
commit
4b21c898f6
@ -5,11 +5,12 @@ import bcrypt from "bcrypt"
|
||||
|
||||
import SessionController from "../SessionController"
|
||||
|
||||
import { User, UserFollow } from "../../models"
|
||||
import { User } from "../../models"
|
||||
import { Token, Schematized } from "../../lib"
|
||||
|
||||
import createUser from "./methods/createUser"
|
||||
import updatePassword from "./methods/updatePassword"
|
||||
import getConnectedUsersFollowing from "./methods/getConnectedUsersFollowing"
|
||||
|
||||
const AllowedPublicUpdateFields = [
|
||||
"fullName",
|
||||
@ -110,6 +111,16 @@ export default class UserController extends Controller {
|
||||
return res.json(req.user)
|
||||
},
|
||||
},
|
||||
"/connected_users_following": {
|
||||
middlewares: ["withAuthentication"],
|
||||
fn: async (req, res) => {
|
||||
const users = await getConnectedUsersFollowing({
|
||||
from_user_id: req.user._id.toString(),
|
||||
})
|
||||
|
||||
return res.json(users)
|
||||
}
|
||||
},
|
||||
"/user/username-available": async (req, res) => {
|
||||
const user = await User.findOne({
|
||||
username: req.query.username,
|
||||
|
@ -0,0 +1,25 @@
|
||||
import { UserFollow } from "../../../models"
|
||||
|
||||
export default async (payload = {}) => {
|
||||
const { from_user_id } = payload
|
||||
|
||||
// get all the users that are following
|
||||
const following = await UserFollow.find({
|
||||
user_id: from_user_id,
|
||||
})
|
||||
|
||||
// check if following users are connected
|
||||
const connectedUsers = []
|
||||
|
||||
following.forEach((follow) => {
|
||||
const connectedClient = global.wsInterface.clients.find((client) => {
|
||||
return client.user_id === follow.to
|
||||
})
|
||||
|
||||
if (connectedClient) {
|
||||
connectedUsers.push(connectedClient.user_id)
|
||||
}
|
||||
})
|
||||
|
||||
return connectedUsers
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user