Added GET /link/:code to the links.ts router
This commit is contained in:
parent
43e2f9553f
commit
e20bf72703
@ -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});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user