Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
Added CSV ingredients
Browse files Browse the repository at this point in the history
  • Loading branch information
WJXHenry committed Apr 29, 2019
1 parent d7c5f69 commit f0293e7
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions src/controllers/lrt-escalator-elevator-outages.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ module.exports = async function(req, res) {
created_at: latestTimestamp,
outages_json: JSON.stringify(latestColumnRows),
fixed_json: JSON.stringify(fixed),
outages_string: stringData(latestColumnRows),
fixed_string: stringData(fixed),
outages_html: htmlData(latestColumnRows),
fixed_html: htmlData(fixed),
outages_string: formatData(latestColumnRows, '\n- '),
fixed_string: formatData(fixed, '\n- '),
outages_html: formatData(latestColumnRows, '<br>- '),
fixed_html: formatData(fixed, '<br>- '),
outages_csv: formatData(latestColumnRows, ''),
fixed_csv: formatData(fixed, ''),
meta: {
id,
timestamp: Math.round(new Date() / 1000)
Expand All @@ -81,35 +83,20 @@ module.exports = async function(req, res) {
/**
* Uses \n newline to format the data
* @param {Object} data The JSON object with outages information
* @param {String} lineBreak The linebreak to use
* @returns {String} Formatted data
*/
function stringData(data) {
function formatData(data, lineBreak) {
return data
.map(entry => {
return `\n- ${entry.lrt_station_name} ${entry.device_type}: ${
return `${lineBreak}${entry.lrt_station_name} ${entry.device_type}: ${
entry.lrt_device_location
}`
})
.sort()
.toString()
}

/**
* Uses <br> tags to format the data
* @param {Object} data The JSON object with outages information
* @returns {String} Formatted data
*/
function htmlData(data) {
return data
.map(entry => {
return `<br>- ${entry.lrt_station_name} ${entry.device_type}: ${
entry.lrt_device_location
}</br>`
})
.sort()
.toString()
}

/**
* Compares the elements of two arrays and returns TRUE arrays are same or FALSE
* if they are different
Expand Down

0 comments on commit f0293e7

Please sign in to comment.