From cd37a7618e7312e73b0d85d86e4ed271f69a181f Mon Sep 17 00:00:00 2001 From: Paul Nettleton Date: Tue, 29 Nov 2022 11:30:25 -0600 Subject: [PATCH] Update LibraryController.js to respond with objects Changes: - `findAll` (GET /api/libraries) - `getLibraryUserPersonalizedOptimal` (GET /api/libraries//personalized) - `getAuthors` (GET /api/libraries//authors) - `reorder` (POST /api/libraries/order) --- server/controllers/LibraryController.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/server/controllers/LibraryController.js b/server/controllers/LibraryController.js index f23b6f9d..7bd673b5 100644 --- a/server/controllers/LibraryController.js +++ b/server/controllers/LibraryController.js @@ -58,7 +58,9 @@ class LibraryController { return res.json(this.db.libraries.filter(lib => librariesAccessible.includes(lib.id)).map(lib => lib.toJSON())) } - res.json(this.db.libraries.map(lib => lib.toJSON())) + res.json({ + libraries: this.db.libraries.map(lib => lib.toJSON()) + }) } async findOne(req, res) { @@ -456,7 +458,9 @@ class LibraryController { const limitPerShelf = req.query.limit && !isNaN(req.query.limit) ? Number(req.query.limit) : 10 const categories = libraryHelpers.buildPersonalizedShelves(req.user, libraryItems, mediaType, this.db.series, this.db.authors, limitPerShelf) - res.json(categories) + res.json({ + shelves: categories + }) } // PATCH: Change the order of libraries @@ -487,8 +491,9 @@ class LibraryController { Logger.debug(`[LibraryController] Library orders were up to date`) } - var libraries = this.db.libraries.map(lib => lib.toJSON()) - res.json(libraries) + res.json({ + libraries: this.db.libraries.map(lib => lib.toJSON()) + }) } // GET: Global library search @@ -594,7 +599,9 @@ class LibraryController { } }) - res.json(naturalSort(Object.values(authors)).asc(au => au.name)) + res.json({ + authors: naturalSort(Object.values(authors)).asc(au => au.name) + }) } async matchAll(req, res) {