Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/api/lib/controllers/measurementsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,17 @@ const getData = function getData (req, res, next) {
let stringifier;

// IDEA: add geojson point featurecollection format
if (format === 'csv' || (download === 'true')) {
if (format === 'csv') {
res.header('Content-Type', 'text/csv');
res.header('Content-Disposition', `attachment; filename=${sensorId}.${format}`);
stringifier = csvStringifier(['createdAt', 'value'], delimiter);
} else if (format === 'json') {
res.header('Content-Type', 'application/json; charset=utf-8');
// IDEA: add geojson point featurecollection format
stringifier = jsonstringify({ open: '[', close: ']' }, jsonLocationReplacer);
}
if (download === 'true') {
res.header('Content-Disposition', `attachment; filename=${sensorId}.${format}`);
}

let measurementsStream = Measurement.getMeasurementsStream(req._userParams)
.on('error', function (err) {
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/007-download-data-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ describe('downloading data', function () {
});

it('should allow download data through /boxes/:boxid/data/:sensorid as csv', function () {
return chakram.get(`${BASE_URL}/boxes/${boxIds[0]}/data/${boxes[0].sensors[1]._id}?format=csv`)
return chakram.get(`${BASE_URL}/boxes/${boxIds[0]}/data/${boxes[0].sensors[1]._id}?format=csv&download=true`)
.then(function (response) {
expect(response).to.have.status(200);
expect(response.body).not.to.be.empty;
Expand Down