Skip to content

Commit 116fe44

Browse files
Merge branch 'development' into management-routes
2 parents 00b135d + 9a51c47 commit 116fe44

File tree

8 files changed

+40
-35
lines changed

8 files changed

+40
-35
lines changed

.scripts/deploy-docs.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ sed -i "1 s|$| ${TRAVIS_TAG}|" apidoc/introduction.md
1515
# run apidoc
1616
apidoc -i . -f js -e node_modules
1717

18-
if [[ -z "${TRAVIS_TAG}" ]]; then
19-
echo "Docs can only be built from tags"
18+
# should contain the current api tag or nothing
19+
isApiTag=$(echo "${TRAVIS_TAG}" | grep -E '^v[0-9]+$' || true)
20+
if [[ -z "$isApiTag" ]]; then
21+
echo "Docs can only be built from api version tags"
2022
exit 0
2123
fi
2224

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# openSenseMap API Changelog
22

33
## Unreleased
4+
5+
## v4
46
- Include sensorId as default column in measurements download
57
- Add format parameter to bulk download and descriptive statistics routes
68
- Support json format in bulk download route

packages/api/lib/controllers/boxesController.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,16 @@ const getBox = async function getBox (req, res, next) {
326326
const { format, boxId } = req._userParams;
327327

328328
try {
329-
res.send(await Box.findBoxById(boxId, { format }));
329+
const box = await Box.findBoxById(boxId);
330+
331+
if (format === 'geojson') {
332+
const coordinates = box.currentLocation.coordinates;
333+
box.currentLocation = undefined;
334+
box.loc = undefined;
335+
336+
return res.send(point(coordinates, box));
337+
}
338+
res.send(box);
330339
} catch (err) {
331340
handleError(err, next);
332341
}

packages/models/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# @sensebox/opensensemap-api-models Changelog
22

33
## Unreleased
4+
- Remove format argument of findBoxById
45
- Remove box.updateImage
56
- Implement deletion of box images
67
- Allow updating of box model value

packages/models/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"dependencies": {
88
"@sensebox/osem-protos": "^1.1.0",
99
"@sensebox/sketch-templater": "^1.1.1",
10-
"@turf/helpers": "^4.6.0",
1110
"bcrypt": "^1.0.2",
1211
"bunyan": "^1.8.12",
1312
"config": "^1.29.2",

packages/models/src/box/box.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const { mongoose } = require('../db'),
1616
ModelError = require('../modelError'),
1717
Sketcher = require('@sensebox/sketch-templater'),
1818
fs = require('fs'),
19-
{ point } = require('@turf/helpers'),
2019
log = require('../log');
2120

2221
const templateSketcher = new Sketcher();
@@ -250,7 +249,7 @@ boxSchema.statics.initNew = function ({
250249

251250
};
252251

253-
boxSchema.statics.findBoxById = function findBoxById (id, { lean = true, populate = true, includeSecrets = false, onlyLastMeasurements = false, onlyLocations = false, format, projection = {} } = {}) {
252+
boxSchema.statics.findBoxById = function findBoxById (id, { lean = true, populate = true, includeSecrets = false, onlyLastMeasurements = false, onlyLocations = false, projection = {} } = {}) {
254253
let fullBox = populate;
255254
if (populate) {
256255
Object.assign(projection, BOX_PROPS_FOR_POPULATION);
@@ -289,14 +288,6 @@ boxSchema.statics.findBoxById = function findBoxById (id, { lean = true, populat
289288
throw new ModelError('Box not found', { type: 'NotFoundError' });
290289
}
291290

292-
if (format === 'geojson') {
293-
const coordinates = box.currentLocation.coordinates;
294-
box.currentLocation = undefined;
295-
box.loc = undefined;
296-
297-
return point(coordinates, box);
298-
}
299-
300291
if (fullBox === true) {
301292
// fill in box.loc manually, as toJSON & virtuals are not supported in lean queries.
302293
box.loc = [{ geometry: box.currentLocation, type: 'Feature' }];

packages/models/test/tests/1-box.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -300,26 +300,6 @@ describe('Box model', function () {
300300
});
301301
});
302302

303-
it('should allow to return box as geojson', function () {
304-
const boxId = Object.keys(testBoxes)[0];
305-
306-
return Box.findBoxById(boxId, { format: 'geojson' }).then(function (
307-
geojsonBox
308-
) {
309-
expect(geojsonBox).an('object');
310-
expect(geojsonBox.type).equal('Feature');
311-
expect(geojsonBox.geometry).an('object');
312-
313-
expect(geojsonBox.geometry.coordinates).an('array');
314-
expect(geojsonBox.geometry.coordinates).lengthOf.within(2, 3);
315-
for (const coord of geojsonBox.geometry.coordinates) {
316-
expect(coord).a('number');
317-
}
318-
expect(Math.abs(geojsonBox.geometry.coordinates[0])).most(180);
319-
expect(Math.abs(geojsonBox.geometry.coordinates[1])).most(90);
320-
});
321-
});
322-
323303
it('should allow to disable population and specify own projection', function () {
324304
const boxId = Object.keys(testBoxes)[0];
325305

tests/tests/005-create-boxes-test.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,26 @@ describe('openSenseMap API Routes: /boxes', function () {
181181
});
182182
});
183183

184+
it('should return a box as geojson', function () {
185+
return chakram.get(`${BASE_URL}/boxes/${boxId}?format=geojson`)
186+
.then(function (response) {
187+
expect(response).to.have.status(200);
188+
const geojsonBox = response.body;
189+
expect(geojsonBox).an('object');
190+
expect(geojsonBox.type).equal('Feature');
191+
expect(geojsonBox.geometry).an('object');
192+
193+
expect(geojsonBox.geometry.coordinates).an('array');
194+
for (const coord of geojsonBox.geometry.coordinates) {
195+
expect(coord).a('number');
196+
}
197+
expect(Math.abs(geojsonBox.geometry.coordinates[0])).most(180);
198+
expect(Math.abs(geojsonBox.geometry.coordinates[1])).most(90);
199+
200+
return chakram.wait();
201+
});
202+
});
203+
184204
it('should let users retrieve their arduino sketch', function () {
185205
return chakram.get(`${BASE_URL}/boxes/${boxId}/script`, { headers: { 'Authorization': `Bearer ${jwt}` } })
186206
.then(function (response) {
@@ -423,7 +443,8 @@ describe('openSenseMap API Routes: /boxes', function () {
423443
expect(response).to.comprise.of.json('data.exposure', update_payload.exposure);
424444
expect(response).to.comprise.of.json('data.grouptag', update_payload.grouptag);
425445
expect(response).to.comprise.of.json('data.description', update_payload.description);
426-
expect(response).to.comprise.of.json('data.currentLocation', { type: 'Point',
446+
expect(response).to.comprise.of.json('data.currentLocation', {
447+
type: 'Point',
427448
coordinates: [update_payload.location.lng, update_payload.location.lat]
428449
});
429450

0 commit comments

Comments
 (0)