39 lines
958 B
JavaScript

let Locations = require('../data/locations.json');
/**
* locationController.js
*
* @description :: Server-side logic for managing locations.
*/
module.exports = {
/**
* locationController.list()
*/
list: function (req, res) {
return res.json(Locations);
},
csv: function (req, res) {
let csvData = "";
for (let i = 0; i < Locations.length; i++) {
csvData += Locations[i].location_id + "," + Locations[i].name + "," + Locations[i].cord_N + "," + Locations[i].cord_E + "," + Locations[i].img_urls[0] + "\n";
}
res.setHeader('Content-disposition', 'attachment; filename=locations.csv');
res.set('Content-Type', 'text/csv');
res.status(200).send(csvData);
},
/**
* locationController.show()
*/
show: function (req, res) {
const id = req.params.id;
const find = Locations.find(value => value.location_id == id)
return res.json(find);
},
};