Skip to content

Commit dfcb405

Browse files
committed
move grouptag to /data route and remove own route
1 parent e4f3c3e commit dfcb405

File tree

2 files changed

+55
-20
lines changed

2 files changed

+55
-20
lines changed

packages/api/lib/controllers/measurementsController.js

+54-19
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ const getData = async function getData (req, res) {
225225
* @apiName getDataMulti
226226
* @apiParam {String} boxId Comma separated list of senseBox IDs.
227227
* @apiParam {String} phenomenon the name of the phenomenon you want to download the data for.
228+
* @apiParam {String} grouptag the name of the phenomenon you want to download the data for.
228229
* @apiParam {RFC3339Date} [from-date] Beginning date of measurement data (default: 2 days ago from now)
229230
* @apiParam {RFC3339Date} [to-date] End date of measurement data (default: now)
230231
* @apiUse SeparatorParam
@@ -235,17 +236,22 @@ const getData = async function getData (req, res) {
235236
* @apiParam {Boolean=true,false} [download=true] Set the `content-disposition` header to force browsers to download instead of displaying.
236237
*/
237238
const getDataMulti = async function getDataMulti (req, res) {
238-
const { boxId, bbox, exposure, delimiter, columns, fromDate, toDate, phenomenon, download, format } = req._userParams;
239+
const { boxId, bbox, exposure, delimiter, columns, fromDate, toDate, phenomenon, download, format, grouptag } = req._userParams;
239240

240241
// build query
241-
const queryParams = {
242-
'sensors.title': phenomenon
243-
};
242+
// const queryParams = {
243+
// 'sensors.title': phenomenon
244+
// };
245+
const queryParams = {};
246+
247+
if (phenomenon) {
248+
queryParams['sensors.title'] = phenomenon;
249+
}
244250

245251
if (boxId && bbox) {
246-
return Promise.reject(new BadRequestError('please specify only boxId or bbox'));
252+
return Promise.reject(new BadRequestError('please specify only boxId or bbox or grouptag'));
247253
} else if (!boxId && !bbox) {
248-
return Promise.reject(new BadRequestError('please specify either boxId or bbox'));
254+
return Promise.reject(new BadRequestError('please specify either boxId or bbox or grouptag'));
249255
}
250256

251257
if (boxId) {
@@ -257,6 +263,11 @@ const getDataMulti = async function getDataMulti (req, res) {
257263
queryParams['exposure'] = { '$in': exposure };
258264
}
259265

266+
if (grouptag) {
267+
const queryTags = grouptag.split(',');
268+
queryParams['grouptag'] = { '$all': queryTags };
269+
}
270+
260271
try {
261272
let stream = await Box.findMeasurementsOfBoxesStream({
262273
query: queryParams,
@@ -512,10 +523,21 @@ module.exports = {
512523
retrieveParameters([
513524
{ predef: 'sensorId', required: true },
514525
{ name: 'format', defaultValue: 'json', allowedValues: ['json', 'csv'] },
515-
{ name: 'download', defaultValue: 'false', allowedValues: ['true', 'false'] },
526+
{
527+
name: 'download',
528+
defaultValue: 'false',
529+
allowedValues: ['true', 'false']
530+
},
516531
{ predef: 'delimiter' },
517532
{ name: 'outliers', allowedValues: ['mark', 'replace'] },
518-
{ name: 'outlierWindow', dataType: 'Integer', aliases: ['outlier-window'], defaultValue: 15, min: 1, max: 50 },
533+
{
534+
name: 'outlierWindow',
535+
dataType: 'Integer',
536+
aliases: ['outlier-window'],
537+
defaultValue: 15,
538+
min: 1,
539+
max: 50
540+
},
519541
{ predef: 'toDate' },
520542
{ predef: 'fromDate' }
521543
]),
@@ -524,27 +546,40 @@ module.exports = {
524546
],
525547
getDataMulti: [
526548
retrieveParameters([
527-
{ name: 'boxId', aliases: ['senseboxid', 'senseboxids', 'boxid', 'boxids'], dataType: ['id'] },
528-
{ name: 'phenomenon', required: true },
549+
{
550+
name: 'boxId',
551+
aliases: ['senseboxid', 'senseboxids', 'boxid', 'boxids'],
552+
dataType: ['id']
553+
},
554+
{ name: 'grouptag', required: false },
555+
{ name: 'phenomenon', required: false },
529556
{ predef: 'delimiter' },
530-
{ name: 'exposure', allowedValues: Box.BOX_VALID_EXPOSURES, dataType: ['String'] },
557+
{
558+
name: 'exposure',
559+
allowedValues: Box.BOX_VALID_EXPOSURES,
560+
dataType: ['String']
561+
},
531562
{ predef: 'columnsGetDataMulti' },
532563
{ predef: 'bbox' },
533564
{ predef: 'toDate' },
534565
{ predef: 'fromDate' },
535-
{ name: 'download', defaultValue: 'true', allowedValues: ['true', 'false'] },
566+
{
567+
name: 'download',
568+
defaultValue: 'true',
569+
allowedValues: ['true', 'false']
570+
},
536571
{ name: 'format', defaultValue: 'csv', allowedValues: ['csv', 'json'] }
537572
]),
538573
validateFromToTimeParams,
539574
getDataMulti
540575
],
541-
getDataByGroupTag: [
542-
retrieveParameters([
543-
{ name: 'grouptag', required: true },
544-
{ name: 'format', defaultValue: 'json', allowedValues: ['json'] }
545-
]),
546-
getDataByGroupTag
547-
],
576+
// getDataByGroupTag: [
577+
// retrieveParameters([
578+
// { name: 'grouptag', required: true },
579+
// { name: 'format', defaultValue: 'json', allowedValues: ['json'] }
580+
// ]),
581+
// getDataByGroupTag
582+
// ],
548583
getLatestMeasurements: [
549584
retrieveParameters([
550585
{ predef: 'boxId', required: true },

packages/api/lib/routes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const routes = {
7979
{ path: `${statisticsPath}/descriptive`, method: 'get', handler: statisticsController.descriptiveStatisticsHandler, reference: 'api-Statistics-descriptive' },
8080
{ path: `${boxesPath}`, method: 'get', handler: boxesController.getBoxes, reference: 'api-Boxes-getBoxes' },
8181
{ path: `${boxesPath}/data`, method: 'get', handler: measurementsController.getDataMulti, reference: 'api-Measurements-getDataMulti' },
82-
{ path: `${boxesPath}/data/bytag`, method: 'get', handler: measurementsController.getDataByGroupTag, reference: 'api-Measurements-getDataByGroupTag' },
82+
// { path: `${boxesPath}/data/bytag`, method: 'get', handler: measurementsController.getDataByGroupTag, reference: 'api-Measurements-getDataByGroupTag' },
8383
{ path: `${boxesPath}/:boxId`, method: 'get', handler: boxesController.getBox, reference: 'api-Boxes-getBox' },
8484
{ path: `${boxesPath}/:boxId/sensors`, method: 'get', handler: measurementsController.getLatestMeasurements, reference: 'api-Measurements-getLatestMeasurements' },
8585
{ path: `${boxesPath}/:boxId/sensors/:sensorId`, method: 'get', handler: measurementsController.getLatestMeasurements, reference: 'api-Measurements-getLatestMeasurementOfSensor' },

0 commit comments

Comments
 (0)