Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove calls to unnecessary endpoints. #61

Merged
merged 1 commit into from
Feb 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 4 additions & 24 deletions src/renderer/redux/modules/services/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from 'redux-modules/services/paths';
import { requestUrl } from 'redux-modules/general/request';
import { GET } from 'redux-modules/general/constants';
import { API_URL, FOOD_CAT_ID } from 'redux-modules/services/constants';
import { API_URL } from 'redux-modules/services/constants';

const LIMIT = 2000;

Expand All @@ -35,11 +35,7 @@ export function getServiceChildren(taxId) {
return Promise.resolve(currentChildren[taxId]);
}

let uri = `${API_URL}/taxonomy`;

// we have a dedicated API route for the food category
// all others we pass the ID and get the children
uri += taxId === FOOD_CAT_ID ? '/food' : `/${taxId}/children`;
const uri = `${API_URL}/taxonomy/${taxId}/children`;

return dispatch(
requestUrl(uri, GET, {
Expand All @@ -61,14 +57,12 @@ export function getServiceChildren(taxId) {
};
}

export function getSpecificLocations(taxId, agencyIds, showMarkers) {
export function getSpecificLocations(taxId, showMarkers) {
return (dispatch, getState) =>
dispatch(
requestUrl(`${API_URL}/location`, GET, {
qs: {
taxonomyId: taxId,
agencyId:
agencyIds.join !== undefined ? agencyIds.join(',') : agencyIds,
limit: LIMIT,
},
successToast: 'successfully grabbed locations',
Expand Down Expand Up @@ -97,21 +91,7 @@ export function getSpecificLocations(taxId, agencyIds, showMarkers) {

export function getServiceLocations(taxId, showMarkers) {
return dispatch =>
dispatch(
requestUrl(`${API_URL}/agency`, GET, {
qs: {
taxonomyId: taxId,
limit: LIMIT,
},
successToast: 'successfully grabbed locations',
errorToast: 'failed to fetch locations',
})
)
.then(response => {
const agencyIds = pluck('id', response);
return dispatch(getSpecificLocations(taxId, agencyIds, showMarkers));
})
.catch(console.error);
dispatch(getSpecificLocations(taxId, showMarkers)).catch(console.error);
}

export default {
Expand Down