Skip to content

Instantly share code, notes, and snippets.

@willshepp28
Created December 7, 2020 20:13
Show Gist options
  • Save willshepp28/4500bee20120e82d6ee6ae959fd96069 to your computer and use it in GitHub Desktop.
Save willshepp28/4500bee20120e82d6ee6ae959fd96069 to your computer and use it in GitHub Desktop.
getting leagues by radius, then filter the leagues by budget
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