Created
December 7, 2020 19:51
-
-
Save willshepp28/8c4c23c73199262b8e7b385449ab199b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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