Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix chat: add associations of user profiles and private chat fix #92

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/config/socketCofing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ let users = new Map<string, string>();
users.set(userId, socket.id)

}

})
socket.on('disconnect', () => {
io.emit('removed');
Expand Down Expand Up @@ -48,8 +47,9 @@ let users = new Map<string, string>();
});

}
export const getSocketIdOfUser =( userId:string ) =>{
return users.get(userId)

export const getSocketIdOfUser =( userId: string ) =>{
return users.get(JSON.stringify(userId))
}

export default socket;
20 changes: 20 additions & 0 deletions src/controllers/userControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ export const fetchAllUsers = async (req: Request, res: Response) => {
});
}
};
export const fetchUserById = async (req: Request, res: Response) => {
try {
// @ts-ignore
const userId = req.user?.id;
const user = await userService.getUserById(Number(userId));
if (!user) {
return res.status(404).json({
message: "user not found",
});
} else {
res.status(200).json(user);
}
} catch (error: any) {
console.log(error)
res.status(500).json({
message: "Internal server error",
error: error.message,
});
}
};

export const userLogin = async (req: Request, res: Response) => {
const { email, password } = req.body;
Expand Down
3 changes: 2 additions & 1 deletion src/docs/swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
updateForgotPassword,
verifyUserAccessToken,
verifyUserEmail,
getUser
} from "./users";
import {
getProducts,
Expand Down Expand Up @@ -117,7 +118,7 @@ const options = {
},

"/api/v1/users/me": {
get: verifyUserAccessToken,
get: getUser,
},
"/api/v1/roles": {
get: getRoles,
Expand Down
Loading
Loading