From a30d1d84a5df97b5a77b6fafc3993aaa00f7fb52 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 16 Apr 2019 17:47:12 +0200 Subject: [PATCH] Now we added the sort params. Read prev commit --- src/controllers/adventure.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/controllers/adventure.js b/src/controllers/adventure.js index e45a971..77cea6b 100644 --- a/src/controllers/adventure.js +++ b/src/controllers/adventure.js @@ -19,11 +19,17 @@ function location(req, res) { } function list(req, res) { + let sortOption = SORT_OPTIONS[0]; + + if (req.query.sort && SORT_OPTIONS.includes(req.query.sort)) { + sortOption = req.query.sort; + } + return Adventure .findAll({ attributes: ['id', 'title', 'subtext', 'dateStart', 'dateEnd', 'locationName'], order: [ - ['dateStart', 'ASC'], + ['dateStart', sortOption], ] }) .then(adventure => res.status(200).send(adventure))