From b27b4c47f79071d3aa336b8f9a6578103df56fe9 Mon Sep 17 00:00:00 2001 From: Pitu Date: Sun, 10 May 2020 21:22:25 +0900 Subject: feat: Proper deleting of albums --- src/api/routes/albums/albumDELETE.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/api/routes') diff --git a/src/api/routes/albums/albumDELETE.js b/src/api/routes/albums/albumDELETE.js index 96698b4..4e6640e 100644 --- a/src/api/routes/albums/albumDELETE.js +++ b/src/api/routes/albums/albumDELETE.js @@ -17,10 +17,18 @@ class albumDELETE extends Route { if (!album) return res.status(400).json({ message: 'The album doesn\'t exist or doesn\'t belong to the user' }); try { - /* - Delete the album - */ + // Delete the album await db.table('albums').where({ id }).delete(); + + // Delete the relation of any files attached to this album + await db.table('albumsFiles').where({ albumId: id }).delete(); + + // Delete the relation of any links attached to this album + await db.table('albumsLinks').where({ albumId: id }).delete(); + + // Delete any album links created for this album + await db.table('links').where({ albumId: id }).delete(); + return res.json({ message: 'The album was deleted successfully' }); } catch (error) { return super.error(res, error); -- cgit v1.2.3