Hi guys, I recently read this very interesting Medium post.
This guys implemented this controller in Strapi V3:
module.exports = {
async find(params, populate, { transacting } = {}) {
const latitude=params._latitude;
const longitude=params._longitude;
const distance=params.distance;
const isGeoQuery = latitude && longitude && distance;
delete params._latitude;
delete params._longitude;
delete params.distance;
const distanceInMilesSql=`
ST_distance_sphere( point(latitude, longitude), point(${latitude}, ${longitude})) as distance`;
const knex = strapi.connections.default;
const filters = convertRestQueryParams(params);
const model = strapi.models.item;
const query = buildQuery({ model, filters });
return model.query(qb => {
if(isGeoQuery){
console.log('Is geo query');
qb.column(knex.raw(distanceInMilesSql));
qb.having('distance','<',distance);
qb.orderBy('distance');
}
query(qb);
}).fetchAll({
withRelated: populate,
transacting,
publicationState: filters.publicationState,
}).then(results => results.toJSON());
}
}
Here he customized the find controller maintaining the control over the other standard query parameters passed via URL.
I tried to implement this code in Strapi V4 but I discovered that the function convertRestQueryParams is no more available under the @strapi/utils package.
Do you have any solution to implement this exact find controller in Strapi V4?
Best regards