feat(ParseQuery): Added 'withinPolygon' support for GeoPoints (#3866)
* Added 'withinPolygon' to query * Unit test for withinPolygon * More Unit Test * withinPolygon fix for Postgres * Fix nit nit?
This commit is contained in:
committed by
Florent Vilmart
parent
a380fcf2c7
commit
c99fdea6fb
@@ -344,6 +344,25 @@ const buildWhereClause = ({ schema, query, index }) => {
|
||||
index += 2;
|
||||
}
|
||||
|
||||
if (fieldValue.$geoWithin && fieldValue.$geoWithin.$polygon) {
|
||||
const polygon = fieldValue.$geoWithin.$polygon;
|
||||
if (!(polygon instanceof Array)) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad $geoWithin value');
|
||||
}
|
||||
const points = polygon.map((point) => {
|
||||
if (typeof point !== 'object' || point.__type !== 'GeoPoint') {
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad $geoWithin value');
|
||||
} else {
|
||||
Parse.GeoPoint._validate(point.latitude, point.longitude);
|
||||
}
|
||||
return `(${point.longitude}, ${point.latitude})`;
|
||||
}).join(', ');
|
||||
|
||||
patterns.push(`$${index}:name::point <@ $${index + 1}::polygon`);
|
||||
values.push(fieldName, `(${points})`);
|
||||
index += 2;
|
||||
}
|
||||
|
||||
if (fieldValue.$regex) {
|
||||
let regex = fieldValue.$regex;
|
||||
let operator = '~';
|
||||
|
||||
Reference in New Issue
Block a user