diff --git a/backend/routes/search.js b/backend/routes/search.js index ecd55a0..50e596b 100644 --- a/backend/routes/search.js +++ b/backend/routes/search.js @@ -47,15 +47,15 @@ function searchHandler(dbConn) { if (q.food_costs) scoreQueryObj['food_costs'] = q.food_costs if (q.alcohol_costs) scoreQueryObj['alcohol_costs'] = q.alcohol_costs if (q.water_costs) scoreQueryObj['water_costs'] = q.water_costs - if (q.public_transportation_costs) scoreQueryObj['public_transportation_costs'] = q.public_transportation_costs + if (q.local_transportation_costs) scoreQueryObj['local_transportation_costs'] = q.local_transportation_costs if (q.entertainment_costs) scoreQueryObj['entertainment_costs'] = q.entertainment_costs if (q.average_per_day_costs) scoreQueryObj['average_per_day_costs'] = q.average_per_day_costs //console.log(scoreQueryObj) - if (_.isEmpty(scoreQueryObj)) { - res.status(400).send('provide at least one search parameter.'); - } + // if (_.isEmpty(scoreQueryObj)) { + // res.status(400).send('provide at least one search parameter.'); + // } scoreAndSearch(q.from, q.to, scoreQueryObj).then(searchResults => { //response.data = searchResults @@ -69,7 +69,7 @@ function searchHandler(dbConn) { }).catch(e => { // TODO error handling console.log(e) - res.json(e.message) + res.status(400).send(e.message) }) } } diff --git a/backend/util/oldToNewQuerySyntax.js b/backend/util/oldToNewQuerySyntax.js index fef514f..17d2168 100644 --- a/backend/util/oldToNewQuerySyntax.js +++ b/backend/util/oldToNewQuerySyntax.js @@ -10,7 +10,7 @@ exports.oldToNewQuerySyntax = function (queries) { if (queries.food_costs) res.food_costs = [Number(queries.food_costs.split(',')[0]), Number(queries.food_costs.split(',')[1])] if (queries.alcohol_costs) res.alcohol_costs = [Number(queries.alcohol_costs.split(',')[0]), Number(queries.alcohol_costs.split(',')[1])] if (queries.water_costs) res.water_costs = [Number(queries.water_costs.split(',')[0]), Number(queries.water_costs.split(',')[1])] - if (queries.public_transportation_costs) res.public_transportation_costs = [Number(queries.public_transportation_costs.split(',')[0]), Number(queries.public_transportation_costs.split(',')[1])] + if (queries.local_transportation_costs) res.local_transportation_costs = [Number(queries.local_transportation_costs.split(',')[0]), Number(queries.local_transportation_costs.split(',')[1])] if (queries.entertainment_costs) res.entertainment_costs = [Number(queries.entertainment_costs.split(',')[0]), Number(queries.entertainment_costs.split(',')[1])] if (queries.average_per_day_costs) res.average_per_day_costs = [Number(queries.average_per_day_costs.split(',')[0]), Number(queries.average_per_day_costs.split(',')[1])] console.log('queries successfully transformed'); diff --git a/backend/util/scoreAndSearch.js b/backend/util/scoreAndSearch.js index d9aabbf..2ee8d89 100644 --- a/backend/util/scoreAndSearch.js +++ b/backend/util/scoreAndSearch.js @@ -12,11 +12,12 @@ const MULTIPLIER = { precipitation: 3.5, rain_days: 3, sun_hours: 2.5, + accommodation_costs: 5, food_costs: 5, alcohol_costs: 5, water_costs: 5, - public_transportation_costs: 5, + local_transportation_costs: 5, entertainment_costs: 5, average_per_day_costs: 5 } @@ -24,9 +25,15 @@ const MULTIPLIER = { module.exports = function (dbConn) { return async function (from, to, queries) { console.log('search') + console.log((_.isEmpty(to) || _.isEmpty(from)) && !_.isEmpty(queries)) + if ((_.isEmpty(to) || _.isEmpty(from)) && !_.isEmpty(queries)) { + throw new Error('Invalid Parameters...') + } // PREPARE SEARCH // validate dates const dates = validateDates(from, to) + // for calculating average if traveldates are in more than one month + const travelPeriods = travelPeriodsFromDates(dates) // transform syntax and seperate climate queries from price queries queries = oldToNewQuerySyntax.oldToNewQuerySyntax(queries) @@ -34,8 +41,6 @@ module.exports = function (dbConn) { const q = prepareQueries(queries) console.log('q', q) - // for calculating average if traveldates are in more than one month - const travelPeriods = travelPeriodsFromDates(dates) // FETCH DATA FROM DB const boundaryClimate = await getClimateMinMax.getClimateMinMax(dbConn) @@ -47,7 +52,7 @@ module.exports = function (dbConn) { food_costs: 100, alcohol_costs: 100, water_costs: 100, - public_transportation_costs: 100, + local_transportation_costs: 100, entertainment_costs: 100, average_per_day_costs: 1000 @@ -57,7 +62,7 @@ module.exports = function (dbConn) { food_costs: 0, alcohol_costs: 0, water_costs: 0, - public_transportation_costs: 0, + local_transportation_costs: 0, entertainment_costs: 0, average_per_day_costs: 0 } @@ -89,7 +94,7 @@ module.exports = function (dbConn) { // CALCULATE AVERAGE SCORE reg.score = calculateAverage(reg.scores) }) - return _.orderBy(regions, ({score}) => score || 0, 'desc') //.filter(el => !_.isNaN(el.score)) + return _.orderBy(regions, ({ score }) => score || 0, 'desc') //.filter(el => !_.isNaN(el.score)) } function calculateAverage(scores) { @@ -120,7 +125,7 @@ module.exports = function (dbConn) { if (queries.food_costs) q.costs.food_costs = queries.food_costs if (queries.alcohol_costs) q.costs.alcohol_costs = queries.alcohol_costs if (queries.water_costs) q.costs.water_costs = queries.water_costs - if (queries.public_transportation_costs) q.costs.public_transportation_costs = queries.public_transportation_costs + if (queries.local_transportation_costs) q.costs.local_transportation_costs = queries.local_transportation_costs if (queries.entertainment_costs) q.costs.entertainment_costs = queries.entertainment_costs if (queries.average_per_day_costs) q.costs.average_per_day_costs = queries.average_per_day_costs