Skip to content

Instantly share code, notes, and snippets.

@willshepp28
Created December 7, 2020 19:51
Show Gist options
  • Save willshepp28/8c4c23c73199262b8e7b385449ab199b to your computer and use it in GitHub Desktop.
Save willshepp28/8c4c23c73199262b8e7b385449ab199b to your computer and use it in GitHub Desktop.
const model = require("../../db/models");
const Sequelize = require("sequelize")
const getLeaguesByRadiusRaw = async(request) => {
return await model.sequelize.query(
`SELECT name, location, price
FROM "Leagues"
WHERE ST_DWithin(location, ST_MakePoint(${request.body.longitude},${request.body.latitude})::geography, ${request.body.radius * 1609.344})
AND price BETWEEN 0 AND ${request.body.budget}
ORDER BY price ASC`, {
type: model.sequelize.QueryTypes.SELECT
}
)
};
module.exports = {
getLeaguesByRadiusRaw
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment