From 4f71d05aa456b8a7c384ff4b4db4eae9bb455635 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sun, 27 Apr 2025 20:06:39 +0530 Subject: Added route to get full profile of a friend --- src/controller/friend.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/controller/friend.ts') diff --git a/src/controller/friend.ts b/src/controller/friend.ts index f528858..5d76350 100644 --- a/src/controller/friend.ts +++ b/src/controller/friend.ts @@ -17,7 +17,7 @@ import { Request, Response } from "express"; import { getFriendToken } from "../util/auth"; -import { friend, unfriend, list } from "../service/friend"; +import { friend, unfriend, list, get } from "../service/friend"; import jwt from "jsonwebtoken"; import {readById} from "../service/user"; @@ -117,9 +117,27 @@ const listFriends = async (req: Request, res: Response) => { } } +const getFriend = async (req: Request, res: Response) => { + try { + // @ts-ignore + const friend = await get(req.userId, parseInt(req.params.friendId)) // TODO: handle non int value passed (bad req) + // @ts-ignore + res.status(200).json({ friend: friend }); + } catch(error) { + // @ts-ignore + if (error.message == "forbidden") { + res.status(403).json({ error: "You are not allowed to view this profile." }); + } else { + res.status(500).json({ error: "Internal Server Error" }); + console.error(error); + } + } +} + export { friendRequest, addFriend, removeFriend, - listFriends + listFriends, + getFriend } -- cgit v1.2.3