Skip to content

Commit

Permalink
add services for schools and trends
Browse files Browse the repository at this point in the history
  • Loading branch information
rrusher committed Jul 9, 2024
1 parent f5a1a56 commit f43aa71
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
40 changes: 40 additions & 0 deletions scripts/apis/creg/creg.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,43 @@ export async function getEnvelope(listingId) {
});
});
}

/**
* Gets the school details for the specified listing.
*
* @param {string} lat latitude
* @param {string} long longitude
* @return {Promise<Object>} resolving the economic details
*/
export async function getSchools(lat, long) {
return new Promise((resolve) => {
const worker = new Worker(`${window.hlx.codeBasePath}/scripts/apis/creg/workers/schools.js`, { type: 'module' });
worker.onmessage = (e) => resolve(e.data);
worker.postMessage({
lat,
long,
});
});
}

/**
* Gets the market trends for .
*
* @param {string} listingId - The ID of the listing.
* @param {string} lat latitude
* @param {string} long longitude
* @param {string} zipcode the zip code
* @return {Promise<Object>} resolving the economic details
*/
export async function getMarketTrends(listingId, lat, long, zipcode) {
return new Promise((resolve) => {
const worker = new Worker(`${window.hlx.codeBasePath}/scripts/apis/creg/workers/markettrends.js`, { type: 'module' });
worker.onmessage = (e) => resolve(e.data);
worker.postMessage({
listingId,
lat,
long,
zipcode,
});
});
}
24 changes: 24 additions & 0 deletions scripts/apis/creg/workers/markettrends.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Handle the Worker event. Fetches school details for the provided lat/long.
*
* @param {Object} event the worker event.
* @param {string} event.data.api the URL to fetch.
* @param {string} event.data.id - The ID of the listing.
* @param {string} event.data.lat latitude
* @param {string} event.data.long longitude
* @param {string} event.data.zipcode the zip code
*/
onmessage = async (event) => {
const {
id, lat, long, zip,
} = event.data;
const promises = [];
promises.push(
fetch(`/bin/bhhs/pdp/cregSchoolServlet?PropertyId=${id}&Latitude=${lat}&Longitude=${long}&zipCode=${zip}`)
.then((resp) => (resp.ok ? resp.json() : undefined)),
);

Promise.all(promises).then((values) => {
postMessage(values.filter((v) => v));
});
};
20 changes: 20 additions & 0 deletions scripts/apis/creg/workers/schools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Handle the Worker event. Fetches school details for the provided lat/long.
*
* @param {Object} event the worker event.
* @param {string} event.data.api the URL to fetch.
* @param {string} event.data.lat latitude
* @param {string} event.data.long longitude
*/
onmessage = async (event) => {
const { lat, long } = event.data;
const promises = [];
promises.push(
fetch(`/bin/bhhs/pdp/cregSchoolServlet?latitude=${lat}&longitude=${long}`)
.then((resp) => (resp.ok ? resp.json() : undefined)),
);

Promise.all(promises).then((values) => {
postMessage(values.filter((v) => v));
});
};

0 comments on commit f43aa71

Please sign in to comment.