From 4d86953dd0a506cc9cc223a82a617e552e2ef4be Mon Sep 17 00:00:00 2001 From: WJXHenry Date: Mon, 25 Mar 2019 16:59:30 -0600 Subject: [PATCH] Datasets field for applet trigger --- src/controllers/open-data-datasets.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/controllers/open-data-datasets.js b/src/controllers/open-data-datasets.js index 6b29015..cefd861 100644 --- a/src/controllers/open-data-datasets.js +++ b/src/controllers/open-data-datasets.js @@ -1,13 +1,18 @@ const request = require('request-promise-native') +function sortOrder(a, b) { + return a.label < b.label ? -1 : (a.label > b.label ? 1 : 0) +} + module.exports = async function(req, res) { let datasets try { let rawJsonData = await request(process.env.OPEN_DATA_URL) const rawData = JSON.parse(rawJsonData) datasets = rawData.dataset.map(function(entry){ - return entry.title - }).sort() + return { label: entry.title, value: entry.identifier } + }).sort(sortOrder) + console.log(datasets) } catch (e) { e.code = 500 throw e