diff --git a/server/routes/discover.ts b/server/routes/discover.ts index 2c3c665f16..f032fa66bf 100644 --- a/server/routes/discover.ts +++ b/server/routes/discover.ts @@ -800,12 +800,12 @@ discoverRoutes.get<{ language: string }, GenreSliderItem[]>( } ); -discoverRoutes.get<{ page?: number }, WatchlistResponse>( +discoverRoutes.get, WatchlistResponse>( '/watchlist', async (req, res) => { const userRepository = getRepository(User); const itemsPerPage = 20; - const page = req.params.page ?? 1; + const page = Number(req.query.page) ?? 1; const offset = (page - 1) * itemsPerPage; const activeUser = await userRepository.findOne({ @@ -829,8 +829,8 @@ discoverRoutes.get<{ page?: number }, WatchlistResponse>( return res.json({ page, - totalPages: Math.ceil(watchlist.size / itemsPerPage), - totalResults: watchlist.size, + totalPages: Math.ceil(watchlist.totalSize / itemsPerPage), + totalResults: watchlist.totalSize, results: watchlist.items.map((item) => ({ ratingKey: item.ratingKey, title: item.title, diff --git a/server/routes/user/index.ts b/server/routes/user/index.ts index f77b7e5155..ea709caf52 100644 --- a/server/routes/user/index.ts +++ b/server/routes/user/index.ts @@ -607,7 +607,7 @@ router.get<{ id: string }, UserWatchDataResponse>( } ); -router.get<{ id: string; page?: number }, WatchlistResponse>( +router.get<{ id: string }, WatchlistResponse>( '/:id/watchlist', async (req, res, next) => { if ( @@ -627,7 +627,7 @@ router.get<{ id: string; page?: number }, WatchlistResponse>( } const itemsPerPage = 20; - const page = req.params.page ?? 1; + const page = Number(req.query.page) ?? 1; const offset = (page - 1) * itemsPerPage; const user = await getRepository(User).findOneOrFail({ @@ -651,8 +651,8 @@ router.get<{ id: string; page?: number }, WatchlistResponse>( return res.json({ page, - totalPages: Math.ceil(watchlist.size / itemsPerPage), - totalResults: watchlist.size, + totalPages: Math.ceil(watchlist.totalSize / itemsPerPage), + totalResults: watchlist.totalSize, results: watchlist.items.map((item) => ({ ratingKey: item.ratingKey, title: item.title,