Migrated the links.ts route

This commit is contained in:
Mathias Wagner 2023-11-07 09:16:42 +01:00
parent 51e7b2562d
commit 774fed90b8
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

View File

@ -27,7 +27,7 @@ app.put("/", hasRank(Rank.TEAM_MEMBER), async (req: AuthenticatedRequest, res: R
const validationError = validateSchema(shortUrl, req.body);
if (validationError) return res.status(400).json({message: validationError});
if (await getLinkById(req.body.shortenedId) != null)
if (req.body.shortenedId && await getLinkById(req.body.shortenedId) != null)
return res.status(409).json({message: "The provided id has already been taken"});
const link = await shortLink(req.body.originalUrl, req.body.shortenedId, req.user.clientId);
@ -43,7 +43,7 @@ app.delete("/:code", hasRank(Rank.TEAM_MEMBER), async (req: AuthenticatedRequest
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();
await link.destroy();
res.json({message: "The provided link got successfully deleted"});
});