aboutsummaryrefslogtreecommitdiff
path: root/src/api/routes/albums
diff options
context:
space:
mode:
authorPitu <[email protected]>2019-03-08 00:47:30 +0900
committerPitu <[email protected]>2019-03-08 00:47:30 +0900
commit71f24504317a8391209789275549a94be5c99e4e (patch)
treeac5fbb6ea56432d180c65fd98cd5122d7a69a287 /src/api/routes/albums
parentwip (diff)
downloadhost.fuwn.me-71f24504317a8391209789275549a94be5c99e4e.tar.xz
host.fuwn.me-71f24504317a8391209789275549a94be5c99e4e.zip
WIP
Diffstat (limited to 'src/api/routes/albums')
-rw-r--r--src/api/routes/albums/link/linkDELETE.js36
-rw-r--r--src/api/routes/albums/link/linkEditPOST.js3
2 files changed, 37 insertions, 2 deletions
diff --git a/src/api/routes/albums/link/linkDELETE.js b/src/api/routes/albums/link/linkDELETE.js
new file mode 100644
index 0000000..4f948ba
--- /dev/null
+++ b/src/api/routes/albums/link/linkDELETE.js
@@ -0,0 +1,36 @@
+const Route = require('../../../structures/Route');
+
+class linkDELETE extends Route {
+ constructor() {
+ super('/album/link/delete/:identifier', 'delete');
+ }
+
+ async run(req, res, db) {
+ const { identifier } = req.params;
+ if (!identifier) return res.status(400).json({ message: 'Invalid identifier supplied' });
+
+ try {
+ const link = await db.table('links')
+ .where({ identifier })
+ .first();
+
+ if (!link) return res.status(400).json({ message: 'Identifier doesn\'t exist' });
+
+ await db.table('links')
+ .where({ id: link.id })
+ .delete();
+ await db.table('albumsLinks')
+ .where({ linkId: link.id })
+ .delete();
+ } catch (error) {
+ console.log(error);
+ return super.error(res, error);
+ }
+
+ return res.json({
+ message: 'Successfully deleted link'
+ });
+ }
+}
+
+module.exports = linkDELETE;
diff --git a/src/api/routes/albums/link/linkEditPOST.js b/src/api/routes/albums/link/linkEditPOST.js
index bb3c41b..1db0a53 100644
--- a/src/api/routes/albums/link/linkEditPOST.js
+++ b/src/api/routes/albums/link/linkEditPOST.js
@@ -8,7 +8,7 @@ class linkEditPOST extends Route {
async run(req, res, db, user) {
if (!req.body) return res.status(400).json({ message: 'No body provided' });
- const { identifier, enabled, enableDownload, expiresAt } = req.body;
+ const { identifier, enableDownload, expiresAt } = req.body;
if (!identifier) return res.status(400).json({ message: 'Invalid album identifier supplied' });
/*
@@ -21,7 +21,6 @@ class linkEditPOST extends Route {
await db.table('links')
.where({ identifier })
.update({
- enabled: enabled || false,
enableDownload: enableDownload || false,
expiresAt // This one should be null if not supplied
});