From e20bf72703a97dd4c01c3a0ac213ddfa583a236b Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Fri, 9 Sep 2022 01:30:17 +0200 Subject: [PATCH] Added GET /link/:code to the links.ts router --- api/routes/links.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/api/routes/links.ts b/api/routes/links.ts index 8683074..625ed47 100644 --- a/api/routes/links.ts +++ b/api/routes/links.ts @@ -7,6 +7,15 @@ import {ShortenedLink} from "../../models/ShortenedLink"; const app = Router(); +app.get("/:code", hasRank(Rank.TEAM_MEMBER), async (req: AuthenticatedRequest, res: Response) => { + if (!req.params.code) return res.status(400).json({message: "You need to provide the shorten id"}); + + const link = await ShortenedLink.findOne({shortenedId: req.params.code}, {_id: 0, __v: 0}); + if (link == null) return res.status(404).json({message: "The provided link does not exist"}); + + res.json(link); +}); + app.put("/", hasRank(Rank.TEAM_MEMBER), async (req: AuthenticatedRequest, res: Response) => { const validationError = validateSchema(shortUrl, req.body); if (validationError) return res.status(400).json({message: validationError});