Skip to content

Commit 7a3cdd7

Browse files
committed
fix: gis/feature route was broken due to incorrect layout / aggregation setup
1 parent 7f9870c commit 7a3cdd7

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

src/routes/gis/index.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import mongoose from 'mongoose';
77
import get from 'lodash/get';
88
import { logger } from '@services/logger.service';
99
import axios from 'axios';
10+
import { isEqual } from 'lodash';
1011

1112
/**
1213
* Endpoint for custom feature layers
@@ -47,7 +48,10 @@ const getFeatureFromItem = (
4748
if (latitude && longitude) {
4849
const feature = {
4950
type: 'Feature',
50-
geometry: [latitude, longitude],
51+
geometry: {
52+
type: 'Point',
53+
coordinates: [latitude, longitude],
54+
},
5155
properties: { ...item },
5256
};
5357
features.push(feature);
@@ -98,6 +102,7 @@ router.get('/feature', async (req, res) => {
98102
return res.status(404).send(i18next.t('common.errors.dataNotFound'));
99103
}
100104

105+
// todo(gis): improve how we find resource
101106
const resourceData = await Resource.findOne({
102107
$or: [
103108
{
@@ -117,29 +122,30 @@ router.get('/feature', async (req, res) => {
117122
],
118123
});
119124

125+
if (!resourceData) {
126+
return res.status(404).send(i18next.t('common.errors.dataNotFound'));
127+
}
128+
120129
let query: any;
121130
let variables: any;
122131

123-
if (
124-
resourceData &&
125-
resourceData.aggregations &&
126-
resourceData.aggregations.length > 0
127-
) {
132+
const aggregations = resourceData.aggregations || [];
133+
const aggregation = aggregations.find((x) => isEqual(x._id, id));
134+
const layouts = resourceData.layouts || [];
135+
const layout = layouts.find((x) => isEqual(x._id, id));
136+
137+
if (aggregation) {
128138
query = `query recordsAggregation($resource: ID!, $aggregation: ID!) {
129139
recordsAggregation(resource: $resource, aggregation: $aggregation)
130140
}`;
131141
variables = {
132142
resource: resourceData._id,
133-
aggregation: resourceData.aggregations[0]._id,
143+
aggregation: aggregation._id,
134144
};
135-
} else if (
136-
resourceData &&
137-
resourceData.layouts &&
138-
resourceData.layouts.length > 0
139-
) {
140-
query = buildQuery(resourceData.layouts[0].query);
145+
} else if (layout) {
146+
query = buildQuery(layout.query);
141147
variables = {
142-
filter: resourceData.layouts[0].query.filter,
148+
filter: layout.query.filter,
143149
};
144150
} else {
145151
return res.status(404).send(i18next.t('common.errors.dataNotFound'));

src/utils/aggregation/buildCalculatedFieldPipeline.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ const resolveMultipleOperators = (
278278
},
279279
};
280280
} else {
281-
return { $toString: value };
281+
return {
282+
$convert: { input: value, to: 'string', onError: null },
283+
};
282284
}
283285
}
284286
default: {

0 commit comments

Comments
 (0)