add follow function and make small style changes

This commit is contained in:
luisa.bellitto 2025-06-29 15:15:48 +02:00 committed by Rudi Regentonne
parent 79e1f4ebe0
commit 9a9724d024
8 changed files with 57 additions and 19 deletions

View file

@ -202,6 +202,7 @@ export const updateBio = async (req: Request, res: Response) => {
// Endpoint to get user data
export const getProfile = async (req: Request, res: Response) => {
const username: string = req.params.username as string;
const requestingUser: JwtPayload | undefined = req.user;
if (!username) {
res.status(StatusCodes.BAD_REQUEST).json({
error: "no username",
@ -227,9 +228,22 @@ export const getProfile = async (req: Request, res: Response) => {
const publicUser: PublicUser | undefined = await getUser(user.id);
let isFollowing : boolean = false;
if(requestingUser) {
const followingData = await prisma.follow.findFirst({
where: {
followedUserId: user.id,
followingUserId: requestingUser.id,
}
})
if(followingData) {
isFollowing = true;
}
}
res.status(StatusCodes.OK).json({
message: "User found",
data: publicUser,
data: {...publicUser, isFollowing},
});
} catch (err) {
console.error(err);