Created
December 7, 2020 20:13
-
-
Save willshepp28/4500bee20120e82d6ee6ae959fd96069 to your computer and use it in GitHub Desktop.
getting leagues by radius, then filter the leagues by budget
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 router = require("express").Router(); | |
const model = require("../db/models"); | |
const {addLeagueValidator, findLeagueValidator} = require("../helpers/validation/league.validation"); | |
const { findLeagueByName, getLeaguesByRadiusRaw } = require("../services/league/league.service"); | |
const leaguesInBudget = require("../helpers/budget.helper"); | |
// GET path to find a league | |
// Given a total budget, a radius, and a location, this service should return enough leagues to spend up to the budget, sponsoring as many leagues as possible without going over it | |
router.get("/", findLeagueValidator, async(request, response) => { | |
try { | |
const getLeagues = await getLeaguesByRadiusRaw(request); | |
const leagues = await leaguesInBudget(getLeagues, parseInt(request.body.budget)); | |
return response.status(200).json(leagues); | |
} catch(error){ | |
console.log(error) | |
return response.status(400).json(error); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment