Matched getRegions to API Specification
Matched getRegionsByID to API Specification
This commit is contained in:
parent
ea2c87a557
commit
8b0064a5b9
@ -2,8 +2,7 @@ module.exports = async (dbConn) => {
|
||||
const countries = await dbConn.query(
|
||||
`SELECT countries.id AS country_id,
|
||||
countries.country AS name,
|
||||
countries.description,
|
||||
countries.preview_img
|
||||
countries.description
|
||||
FROM countries`
|
||||
);
|
||||
return countries;
|
||||
|
||||
@ -2,8 +2,7 @@ module.exports = async (dbConn, id) => {
|
||||
const country = await dbConn.query(
|
||||
`SELECT countries.id AS country_id,
|
||||
countries.country AS name,
|
||||
countries.description,
|
||||
countries.preview_img
|
||||
countries.description
|
||||
FROM countries
|
||||
WHERE countries.id = ?`,
|
||||
[id]
|
||||
|
||||
@ -2,17 +2,94 @@ module.exports = async (dbConn, id) => {
|
||||
const region = await dbConn.query(
|
||||
`SELECT regions.id AS region_id,
|
||||
regions.region AS name,
|
||||
regions.description,
|
||||
regions.preview_img,
|
||||
regions.country_id AS country_id,
|
||||
countries.country AS country,
|
||||
regions.meteostat_id AS meteostat_id
|
||||
regions.description AS description,
|
||||
rcma.temperature_mean,
|
||||
rcma.temperature_mean_min,
|
||||
rcma.temperature_mean_max,
|
||||
rcma.percipitation,
|
||||
rcma.raindays,
|
||||
rcma.sunshine,
|
||||
rcma.humidity,
|
||||
regions_byt.average_per_day,
|
||||
regions_byt.accomodation,
|
||||
regions_byt.food,
|
||||
regions_byt.water,
|
||||
regions_byt.local_transportation,
|
||||
regions_byt.entertainment,
|
||||
regions_byt.tips_and_handouts,
|
||||
regions_byt.scams_robberies_and_mishaps,
|
||||
regions_byt.alcohol
|
||||
FROM regions
|
||||
JOIN countries
|
||||
ON regions.country_id = countries.id
|
||||
WHERE regions.id = ?`,
|
||||
JOIN countries ON regions.country_id = countries.id
|
||||
JOIN (SELECT rcma.region_id,
|
||||
GROUP_CONCAT(IFNULL(rcma.temperature_mean,"") ORDER BY rcma.month SEPARATOR ', ') AS temperature_mean,
|
||||
GROUP_CONCAT(IFNULL(rcma.temperature_mean_min, "") ORDER BY rcma.month SEPARATOR ', ') AS temperature_mean_min,
|
||||
GROUP_CONCAT(IFNULL(rcma.temperature_mean_max, "") ORDER BY rcma.month SEPARATOR ', ') AS temperature_mean_max,
|
||||
GROUP_CONCAT(IFNULL(rcma.percipitation, "") ORDER BY rcma.month SEPARATOR ', ') AS percipitation,
|
||||
GROUP_CONCAT(IFNULL(rcma.raindays, "") ORDER BY rcma.month SEPARATOR ', ') AS raindays,
|
||||
GROUP_CONCAT(IFNULL(rcma.sunshine, "") ORDER BY rcma.month SEPARATOR ', ') AS sunshine,
|
||||
GROUP_CONCAT(IFNULL(rcma.humidity, "") ORDER BY rcma.month SEPARATOR ', ') AS humidity
|
||||
FROM region_climate_monthly_avg AS rcma
|
||||
GROUP BY rcma.region_id) rcma ON rcma.region_id = regions.id
|
||||
JOIN regions_byt ON regions.id = regions_byt.region_id
|
||||
WHERE regions_byt.travelstyle = 1
|
||||
AND regions.id = ?`,
|
||||
[id]
|
||||
);
|
||||
|
||||
for (k = 0; k < region.length; k++) {
|
||||
if (region[k].temperature_mean !== null) {
|
||||
const temperature_mean = region[k].temperature_mean
|
||||
region[k].temperature_mean = temperature_mean.split(",");
|
||||
for (i = 0; i < region[k].temperature_mean.length; i++) {
|
||||
region[k].temperature_mean[i] = parseFloat(region[k].temperature_mean[i])
|
||||
}
|
||||
}
|
||||
if (region[k].temperature_mean_min !== null) {
|
||||
const temperature_mean_min = region[k].temperature_mean_min
|
||||
region[k].temperature_mean_min = temperature_mean_min.split(",");
|
||||
for (i = 0; i < region[k].temperature_mean_min.length; i++) {
|
||||
region[k].temperature_mean_min[i] = parseFloat(region[k].temperature_mean_min[i])
|
||||
}
|
||||
}
|
||||
if (region[k].temperature_mean_max !== null) {
|
||||
const temperature_mean_max = region[k].temperature_mean_max
|
||||
region[k].temperature_mean_max = temperature_mean_max.split(",");
|
||||
for (i = 0; i < region[k].temperature_mean_max.length; i++) {
|
||||
region[k].temperature_mean_max[i] = parseFloat(region[k].temperature_mean_max[i])
|
||||
}
|
||||
|
||||
}
|
||||
if (region[k].percipitation !== null) {
|
||||
const percipitation = region[k].percipitation
|
||||
region[k].percipitation = percipitation.split(",");
|
||||
for (i = 0; i < region[k].percipitation.length; i++) {
|
||||
region[k].percipitation[i] = parseFloat(region[k].percipitation[i])
|
||||
}
|
||||
}
|
||||
if (region[k].raindays !== null) {
|
||||
const raindays = region[k].raindays
|
||||
region[k].raindays = raindays.split(",");
|
||||
for (i = 0; i < region[k].raindays.length; i++) {
|
||||
region[k].raindays[i] = parseFloat(region[k].raindays[i])
|
||||
}
|
||||
}
|
||||
if (region[k].sunshine !== null) {
|
||||
const sunshine = region[k].sunshine
|
||||
region[k].sunshine = sunshine.split(",");
|
||||
for (i = 0; i < region[k].sunshine.length; i++) {
|
||||
region[k].sunshine[i] = parseFloat(region[k].sunshine[i])
|
||||
}
|
||||
}
|
||||
if (region[k].humidity !== null) {
|
||||
const humidity = region[k].humidity
|
||||
region[k].humidity = humidity.split(",");
|
||||
for (i = 0; i < region[k].humidity.length; i++) {
|
||||
region[k].humidity[i] = parseFloat(region[k].humidity[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
return region;
|
||||
};
|
||||
|
||||
|
||||
@ -3,11 +3,91 @@ module.exports = async (dbConn) => {
|
||||
`SELECT regions.id AS region_id,
|
||||
regions.region AS name,
|
||||
countries.country AS country,
|
||||
regions.meteostat_id AS meteostat_id
|
||||
regions.description AS description,
|
||||
rcma.temperature_mean,
|
||||
rcma.temperature_mean_min,
|
||||
rcma.temperature_mean_max,
|
||||
rcma.percipitation,
|
||||
rcma.raindays,
|
||||
rcma.sunshine,
|
||||
rcma.humidity,
|
||||
regions_byt.average_per_day,
|
||||
regions_byt.accomodation,
|
||||
regions_byt.food,
|
||||
regions_byt.water,
|
||||
regions_byt.local_transportation,
|
||||
regions_byt.entertainment,
|
||||
regions_byt.tips_and_handouts,
|
||||
regions_byt.scams_robberies_and_mishaps,
|
||||
regions_byt.alcohol
|
||||
FROM regions
|
||||
JOIN countries
|
||||
ON regions.country_id = countries.id`
|
||||
JOIN countries ON regions.country_id = countries.id
|
||||
JOIN (SELECT rcma.region_id,
|
||||
GROUP_CONCAT(IFNULL(rcma.temperature_mean,"") ORDER BY rcma.month SEPARATOR ', ') AS temperature_mean,
|
||||
GROUP_CONCAT(IFNULL(rcma.temperature_mean_min, "") ORDER BY rcma.month SEPARATOR ', ') AS temperature_mean_min,
|
||||
GROUP_CONCAT(IFNULL(rcma.temperature_mean_max, "") ORDER BY rcma.month SEPARATOR ', ') AS temperature_mean_max,
|
||||
GROUP_CONCAT(IFNULL(rcma.percipitation, "") ORDER BY rcma.month SEPARATOR ', ') AS percipitation,
|
||||
GROUP_CONCAT(IFNULL(rcma.raindays, "") ORDER BY rcma.month SEPARATOR ', ') AS raindays,
|
||||
GROUP_CONCAT(IFNULL(rcma.sunshine, "") ORDER BY rcma.month SEPARATOR ', ') AS sunshine,
|
||||
GROUP_CONCAT(IFNULL(rcma.humidity, "") ORDER BY rcma.month SEPARATOR ', ') AS humidity
|
||||
FROM region_climate_monthly_avg AS rcma
|
||||
GROUP BY rcma.region_id) rcma ON rcma.region_id = regions.id
|
||||
JOIN regions_byt ON regions.id = regions_byt.region_id
|
||||
WHERE regions_byt.travelstyle = 1`
|
||||
);
|
||||
|
||||
for (k = 0; k < regions.length; k++) {
|
||||
if (regions[k].temperature_mean !== null) {
|
||||
const temperature_mean = regions[k].temperature_mean
|
||||
regions[k].temperature_mean = temperature_mean.split(",");
|
||||
for (i = 0; i < regions[k].temperature_mean.length; i++) {
|
||||
regions[k].temperature_mean[i] = parseFloat(regions[k].temperature_mean[i])
|
||||
}
|
||||
}
|
||||
if (regions[k].temperature_mean_min !== null) {
|
||||
const temperature_mean_min = regions[k].temperature_mean_min
|
||||
regions[k].temperature_mean_min = temperature_mean_min.split(",");
|
||||
for (i = 0; i < regions[k].temperature_mean_min.length; i++) {
|
||||
regions[k].temperature_mean_min[i] = parseFloat(regions[k].temperature_mean_min[i])
|
||||
}
|
||||
}
|
||||
if (regions[k].temperature_mean_max !== null) {
|
||||
const temperature_mean_max = regions[k].temperature_mean_max
|
||||
regions[k].temperature_mean_max = temperature_mean_max.split(",");
|
||||
for (i = 0; i < regions[k].temperature_mean_max.length; i++) {
|
||||
regions[k].temperature_mean_max[i] = parseFloat(regions[k].temperature_mean_max[i])
|
||||
}
|
||||
|
||||
}
|
||||
if (regions[k].percipitation !== null) {
|
||||
const percipitation = regions[k].percipitation
|
||||
regions[k].percipitation = percipitation.split(",");
|
||||
for (i = 0; i < regions[k].percipitation.length; i++) {
|
||||
regions[k].percipitation[i] = parseFloat(regions[k].percipitation[i])
|
||||
}
|
||||
}
|
||||
if (regions[k].raindays !== null) {
|
||||
const raindays = regions[k].raindays
|
||||
regions[k].raindays = raindays.split(",");
|
||||
for (i = 0; i < regions[k].raindays.length; i++) {
|
||||
regions[k].raindays[i] = parseFloat(regions[k].raindays[i])
|
||||
}
|
||||
}
|
||||
if (regions[k].sunshine !== null) {
|
||||
const sunshine = regions[k].sunshine
|
||||
regions[k].sunshine = sunshine.split(",");
|
||||
for (i = 0; i < regions[k].sunshine.length; i++) {
|
||||
regions[k].sunshine[i] = parseFloat(regions[k].sunshine[i])
|
||||
}
|
||||
}
|
||||
if (regions[k].humidity !== null) {
|
||||
const humidity = regions[k].humidity
|
||||
regions[k].humidity = humidity.split(",");
|
||||
for (i = 0; i < regions[k].humidity.length; i++) {
|
||||
regions[k].humidity[i] = parseFloat(regions[k].humidity[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
return regions;
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user