diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2025-04-27 22:58:24 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2025-04-27 22:58:24 +0530 |
commit | b5f78bf3049c181b47d8692b728d7087c4fad51d (patch) | |
tree | 694e350283ac07d43b9589ca01db5c2427a107a4 /src/controller/friend.ts | |
parent | 961708462525292c28aaf2462f7c50b05536df99 (diff) |
Bug Fix: preventing an undefined friendId causing unwanted deletion of all of the user's friendships (one sidedly, too\!)
Diffstat (limited to 'src/controller/friend.ts')
-rw-r--r-- | src/controller/friend.ts | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/controller/friend.ts b/src/controller/friend.ts index 5d76350..4690f39 100644 --- a/src/controller/friend.ts +++ b/src/controller/friend.ts @@ -87,9 +87,11 @@ const addFriend = async (req: Request, res: Response) => { const removeFriend = async (req: Request, res: Response) => { try { + if (req.body.friendId === undefined || req.body.friendId === null || !Number.isInteger(req.body.friendId)) { + res.status(400).json({ message: "Invalid Friend ID" }); // @ts-ignore - if (req.userId == req.body.friendId) { - res.status(400).json({ message: "Attempted to unfriend self" }); + } else if (req.userId == req.body.friendId) { + res.status(400).json({message: "Attempted to unfriend self"}); } else { // @ts-ignore const { count } = await unfriend(req.userId, req.body.friendId) |