From ec2bf3cb7f38c244e788927463d668eb7c2ee7e5 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Fri, 24 Nov 2017 12:41:18 +0100 Subject: [PATCH] Sort by publication_date --- routes/api/assets/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/routes/api/assets/index.js b/routes/api/assets/index.js index 165b2cd99..d7cc86438 100644 --- a/routes/api/assets/index.js +++ b/routes/api/assets/index.js @@ -38,7 +38,7 @@ router.get('/', authorization.needed('ADMIN', 'MODERATOR'), async (req, res, nex const { value = '', - field = 'created_at', + field = 'publication_date', page = 1, asc = 'false', filter = 'all', @@ -46,9 +46,10 @@ router.get('/', authorization.needed('ADMIN', 'MODERATOR'), async (req, res, nex } = req.query; try { + const order = (asc === 'true') ? 1 : -1; const queryOpts = { - sort: {[field]: (asc === 'true') ? 1 : -1}, + sort: {[field]: order, 'created_at': order}, skip: (page - 1) * limit, limit };