diff --git a/api/routes/links.ts b/api/routes/links.ts index 4c1f149..e26feb8 100644 --- a/api/routes/links.ts +++ b/api/routes/links.ts @@ -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"}); });