diff --git a/app/config/dataSource.js b/app/config/dataSource.js index adc1786..2cedceb 100644 --- a/app/config/dataSource.js +++ b/app/config/dataSource.js @@ -1,27 +1,77 @@ exports.internal = { - supplies: 'supplies', - staff: 'staff', - food: 'food', - water: 'water', - energyFuel: 'energy or fuel', - medical: 'medical', - openSpace: 'open space', - shelter: 'shelter', + supplies: 'supplies', + staff: 'staff', + food: 'food', + water: 'water', + energyFuel: 'energy or fuel', + medical: 'medical', + openSpace: 'open space', + shelter: 'shelter', }; exports.external = { /* --- SF Open Data --- */ - communityResiliencyIndicators: 'https://data.sfgov.org/resource/wsj2-27m9.json', + communityResiliencyIndicators: { + url: "https://data.sfgov.org/resource/wsj2-27m9.json", + modifyDataset: dataset => { + // do something here as needed + return dataset; + } + }, /* --- SF Open Data Markers --- */ - privatelyOwnedPublicOpenSpaces: 'https://data.sfgov.org/resource/3ub7-d4yy.geojson?$where=the_geom IS NOT NULL', - parksAndOpenSpaces: 'https://data.sfgov.org/resource/94uf-amnx.geojson?$where=location_1 IS NOT NULL', - schools: 'https://data.sfgov.org/resource/mmsr-vumy.geojson?$where=location_1 IS NOT NULL', + privatelyOwnedPublicOpenSpaces: { + url: "https://data.sfgov.org/resource/3ub7-d4yy.geojson", + query: + "$query=SELECT name AS title, descriptio AS description, the_geom WHERE the_geom IS NOT NULL", + author: "DataSF" + }, + parksAndOpenSpaces: { + url: "https://data.sfgov.org/resource/94uf-amnx.geojson", + query: + "$query=SELECT parkid AS _id, parktype AS description, parkname AS name, location_1 WHERE location_1 IS NOT NULL", + author: "DataSF" + }, + schools: { + url: "https://data.sfgov.org/resource/mmsr-vumy.geojson", + query: + "$query=SELECT location_1, campus_name AS name, campus_address AS description, county_fips AS _id WHERE location_1 IS NOT NULL", + author: "DataSF" + }, // very large, nation-wide data set, need to limit what's returned - businesses: 'https://data.sfgov.org/resource/vbiu-2p9h.geojson?$where=location IS NOT NULL', - cityFacilities: 'https://data.sfgov.org/resource/i5wr-crji.geojson?$where=geom IS NOT NULL', - healthCareFacilities: 'https://data.sfgov.org/resource/sci7-7q9i.geojson?$where=location IS NOT NULL', - pitStops: 'https://data.sfgov.org/resource/snkr-6jdf.geojson?$where=geom IS NOT NULL', + businesses: { + url: "https://data.sfgov.org/resource/vbiu-2p9h.geojson", + query: + "$query=SELECT * WHERE location IS NOT NULL AND city = 'San Francisco'", + author: "DataSF" + }, + cityFacilities: { + url: "https://data.sfgov.org/resource/i5wr-crji.geojson", + query: + "$query=SELECT facility_id AS _id, common_name AS name, address AS description, geom WHERE geom IS NOT NULL", + author: "DataSF" + }, + healthCareFacilities: { + url: "https://data.sfgov.org/resource/sci7-7q9i.geojson", + query: + "$query=SELECT uid AS _id, facility_name AS name, facility_type, location AS description WHERE location IS NOT NULL", + author: "DataSF" + }, + pitStops: { + url: "https://data.sfgov.org/resource/snkr-6jdf.geojson", + query: + "$query=SELECT id AS _id, location AS name, facilitytype AS description, geom WHERE geom IS NOT NULL", + author: "DataSF" + }, /* --- SF Open Data Regions --- */ - seismicHazardZones: 'https://data.sfgov.org/resource/t2cc-dy6b.geojson?$where=the_geom IS NOT NULL', - neighborhoods: 'https://data.sfgov.org/resource/6ia5-2f8k.geojson?$where=the_geom IS NOT NULL', + seismicHazardZones: { + url: "https://data.sfgov.org/resource/t2cc-dy6b.geojson", + query: "$query=SELECT id AS _id, the_geom WHERE the_geom IS NOT NULL", + author: "DataSF" + }, + neighborhoods: { + url: "https://data.sfgov.org/resource/6ia5-2f8k.geojson", + query: + "$query=SELECT the_geom, name, link AS description WHERE the_geom IS NOT NULL", + author: "DataSF" + } }; diff --git a/app/repositories/index.js b/app/repositories/index.js index b27331b..00c0f2a 100644 --- a/app/repositories/index.js +++ b/app/repositories/index.js @@ -3,6 +3,7 @@ const geojson = require('geojson'); const Marker = require('../models/marker.js'); const mapDatasets = require('../config/mapDatasets'); const { internal, external } = require('../config/dataSource'); +const addAuthor = require("../utilities/addAuthor"); async function getAll() { const datasets = await mapDatasets; // simulated db call @@ -25,10 +26,12 @@ async function getById(mapDataset) { async function fetchById(mapDataset) { try { - const response = await fetch(external[mapDataset]); + const response = await fetch(`${external[mapDataset].url}?${external[mapDataset].query}`); const dataset = await response.json(); - return dataset; + const modifiedDataset = addAuthor(dataset, external[mapDataset].author); + + return modifiedDataset; } catch (error) { throw new Error(error); } diff --git a/app/utilities/addAuthor.js b/app/utilities/addAuthor.js new file mode 100644 index 0000000..1dcc24a --- /dev/null +++ b/app/utilities/addAuthor.js @@ -0,0 +1,8 @@ +function addAuthor(dataset, author) { + dataset.features.map(feature => { + feature.properties.author = author; + }); + return dataset; +} + +module.exports = addAuthor;