notum-cz / strapi-plugin-location

This plugin allows users to create location inputs and store latitude and longitude values as geometry types in a PostGIS database. It also provides functionality to filter items based on their location.
MIT License
24 stars 13 forks source link

No correct data from api request #38

Closed korayrubicoda closed 1 year ago

korayrubicoda commented 1 year ago

Bug report

Describe the bug

I am using your plugin for the strap, everything was going well, but when I make api request, it pulls all the data Api Url http://localhost:1337/v1/articles?$location[coords]=49.200949303006055,16.623833585841673,5000&populate=*

Screenshots

image image

System

omikulcik commented 1 year ago

Hi @korayrubicoda, is the field in which you store the coordinates also named "coords"? In case the url is constructed wrongly it will return all entries.

korayrubicoda commented 1 year ago

yes cordinates name "coords" image image

omikulcik commented 1 year ago

Oh, you should test on real coordinates from the map because they are stored as geospatial data in the DB. Also try omitting the populate=* but that should not cause any problems. If that does not work I will try replicating this.

korayrubicoda commented 1 year ago

I tested the coordinate and it's correct and deleted populate=* image image i change url and it's not working image

omikulcik commented 1 year ago

I see now. For some reason your url starts with /v1instead of /api and our middleware determines the collection type with this code const collectionType = url.replace("/api/", "").split("/")[0].split("?")[0]; And since there is no "/api" in your request it will fail to get the correct collectionType and lets the request through.

If you need a hotfix it should be fixed by changing the line 24 of the middleware to const collectionType = url.replace(strapi.config.api.rest.prefix, "").split("/")[0].split("?")[0];

I will also include this into the source code and publish a new version but I will do it tomorrow at the earliest.

korayrubicoda commented 1 year ago

ahh sorry i changed the code to /v1 in the instructions when installing postgres I fixed it, now it works thank you :)

omikulcik commented 1 year ago

Glad it works :)

omikulcik commented 1 year ago

Closed by #39