aboutsummaryrefslogtreecommitdiff
path: root/src/controller
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2025-04-27 20:06:39 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2025-04-27 20:06:39 +0530
commit4f71d05aa456b8a7c384ff4b4db4eae9bb455635 (patch)
treee1efa3180113020ca72a206b53105b3f701359d7 /src/controller
parentd0a94e8b4982ed8937defaea1939b71805214ffe (diff)
Added route to get full profile of a friend
Diffstat (limited to 'src/controller')
-rw-r--r--src/controller/friend.ts22
1 files changed, 20 insertions, 2 deletions
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
}