Added GET /link/:code to the links.ts router

This commit is contained in:
Mathias Wagner 2022-09-09 01:30:17 +02:00
parent 43e2f9553f
commit e20bf72703
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

View File

@ -7,6 +7,15 @@ import {ShortenedLink} from "../../models/ShortenedLink";
const app = Router(); 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) => { app.put("/", hasRank(Rank.TEAM_MEMBER), async (req: AuthenticatedRequest, res: Response) => {
const validationError = validateSchema(shortUrl, req.body); const validationError = validateSchema(shortUrl, req.body);
if (validationError) return res.status(400).json({message: validationError}); if (validationError) return res.status(400).json({message: validationError});