Fixed the addon & release route
This commit is contained in:
parent
c7ee872962
commit
b36318a897
@ -70,7 +70,7 @@ app.patch("/:addonId", isAuthenticatedUser, async (req, res) => {
|
||||
const addon = await getAddonById(req.params.addonId);
|
||||
if (addon === null) return res.status(404).json({message: "The provided addon does not exist"});
|
||||
|
||||
if (!req.user._id.equals(addon.user_id)) return res.status(404).json({message: "The provided addon does not exist"});
|
||||
if (!req.user._id.equals(addon.author)) return res.status(404).json({message: "The provided addon does not exist"});
|
||||
|
||||
const updatedAddon = await addon.updateOne(req.body);
|
||||
if (!updatedAddon) return res.status(500).json({message: "An internal error occurred"});
|
||||
@ -86,7 +86,7 @@ app.patch("/:addonId/links", isAuthenticatedUser, async (req, res) => {
|
||||
const addon = await getAddonById(req.params.addonId);
|
||||
if (addon === null) return res.status(404).json({message: "The provided addon does not exist"});
|
||||
|
||||
if (!req.user._id.equals(addon.user_id)) return res.status(404).json({message: "The provided addon does not exist"});
|
||||
if (!req.user._id.equals(addon.author)) return res.status(404).json({message: "The provided addon does not exist"});
|
||||
|
||||
let updatedBody = {};
|
||||
for (let link in req.body)
|
||||
@ -103,7 +103,7 @@ app.delete("/:addonId", isAuthenticatedUser, async (req, res) => {
|
||||
const addon = await getAddonById(req.params.addonId);
|
||||
if (addon === null) return res.status(404).json({message: "The provided addon does not exist"});
|
||||
|
||||
if (!req.user._id.equals(addon.user_id)) return res.status(404).json({message: "The provided addon does not exist"});
|
||||
if (!req.user._id.equals(addon.author)) return res.status(404).json({message: "The provided addon does not exist"});
|
||||
|
||||
await addon.delete();
|
||||
await removeAllReleases(req.params.addonId);
|
||||
|
@ -47,7 +47,7 @@ app.put("/:addonId", isAuthenticatedUser, async (req, res) => {
|
||||
const addon = await getAddonById(req.params.addonId);
|
||||
if (addon === null) return res.status(404).json({message: "The provided addon does not exist"});
|
||||
|
||||
if (!req.user._id.equals(addon.user_id)) return res.status(404).json({message: "The provided addon does not exist"});
|
||||
if (!req.user._id.equals(addon.author)) return res.status(404).json({message: "The provided addon does not exist"});
|
||||
|
||||
const release = await getReleaseByAddonId(req.params.addonId, req.body.version);
|
||||
if (release) return res.status(409).json({message: "The provided release already exists"});
|
||||
@ -73,7 +73,9 @@ app.post("/:id/upload", isAuthenticatedUser, releaseUpload, async (req, res) =>
|
||||
const addon = await getAddonById(release.addon_id);
|
||||
if (addon === null) return res.status(404).json({message: "The provided release does not exist"});
|
||||
|
||||
if (!req.user._id.equals(addon.user_id)) return res.status(404).json({message: "The provided release does not exist"});
|
||||
console.log(addon)
|
||||
|
||||
if (!req.user._id.equals(addon.author)) return res.status(404).json({message: "The provided release does not exist"});
|
||||
|
||||
if (!await isValidReleaseFile(addon.type, file)) return res.status(415).json({message: "The provided file format is not supported"});
|
||||
|
||||
@ -92,7 +94,7 @@ app.delete("/:id", isAuthenticatedUser, async (req, res) => {
|
||||
const addon = await getAddonById(release.addon_id);
|
||||
if (addon === null) return res.status(404).json({message: "The provided release does not exist"});
|
||||
|
||||
if (!req.user._id.equals(addon.user_id)) return res.status(404).json({message: "The provided release does not exist"});
|
||||
if (!req.user._id.equals(addon.author)) return res.status(404).json({message: "The provided release does not exist"});
|
||||
|
||||
await release.delete();
|
||||
fs.unlink(process.env.RELEASE_PATH + "/" + release._id, () => res.json({message: "Successfully deleted the release"}));
|
||||
|
Loading…
x
Reference in New Issue
Block a user