diff options
Diffstat (limited to 'src/controller')
| -rw-r--r-- | src/controller/friend.ts | 22 | 
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  }  |