From e455ff5b689b5c563a3d27a0e5c8469761016178 Mon Sep 17 00:00:00 2001 From: Paul Bienkowski Date: Sun, 13 Dec 2020 20:44:41 +0100 Subject: [PATCH] feat: Sort tracks newest first, not oldest --- src/routes/api/tracks.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/api/tracks.js b/src/routes/api/tracks.js index 46b3cc8..29fe1ab 100644 --- a/src/routes/api/tracks.js +++ b/src/routes/api/tracks.js @@ -78,7 +78,7 @@ router.get( } const [tracks, tracksCount] = await Promise.all([ - Track.find(query).limit(Number(limit)).skip(Number(offset)).sort({ createdAt: 'desc' }).populate('author').exec(), + Track.find(query).sort('-createdAt').limit(Number(limit)).skip(Number(offset)).sort({ createdAt: 'desc' }).populate('author').exec(), Track.countDocuments(query).exec(), ]); @@ -106,7 +106,7 @@ router.get( const query = { author: req.user.id }; const [tracks, tracksCount] = await Promise.all([ - Track.find(query).limit(Number(limit)).skip(Number(offset)).populate('author').exec(), + Track.find(query).sort('-createdAt').limit(Number(limit)).skip(Number(offset)).populate('author').exec(), Track.countDocuments(query), ]);