Added DELETE /link/:code to the links.ts router
This commit is contained in:
parent
ed75a8ed49
commit
43e2f9553f
@ -18,4 +18,17 @@ app.put("/", hasRank(Rank.TEAM_MEMBER), async (req: AuthenticatedRequest, res: R
|
||||
res.json({message: "Link successfully shortened", "shorten_url": link.shortenedId});
|
||||
});
|
||||
|
||||
app.delete("/: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});
|
||||
if (link == null) return res.status(404).json({message: "The provided link does not exist"});
|
||||
|
||||
if (!(req.user.rank === Rank.TEAM_MEMBER && link.clientId === req.user.clientId || req.user.rank === Rank.ADMIN))
|
||||
return res.status(401).json({message: "You don't have the permission to delete this link"});
|
||||
|
||||
await link.delete();
|
||||
res.json({message: "The provided link got successfully deleted"});
|
||||
});
|
||||
|
||||
module.exports = app;
|
Loading…
x
Reference in New Issue
Block a user