Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return async dispatch => {
try {
let response;
if (isVet360Configured()) {
response = await apiRequest('/profile/status/');
} else {
response = { data: [] };
// Uncomment the line below to simulate transactions being processed during initialization
// response = localVet360.getUserTransactions();
}
dispatch({
type: VET360_TRANSACTIONS_FETCH_SUCCESS,
data: response.data,
});
} catch (err) {
// If we sync transactions in the background and fail, is it worth telling the user?
}
};
}
export function getSystemDetails(systemIds) {
let promise;
if (USE_MOCK_DATA) {
promise = import('./facilities.json').then(
module => (module.default ? module.default : module),
);
} else {
const idList = systemIds.map(id => `facility_codes[]=${id}`).join('&');
promise = apiRequest(`/vaos/facilities?${idList}`);
}
return promise.then(resp =>
resp.data
.map(item => ({ ...item.attributes, id: item.id }))
// Sometimes facilities that aren't in our codes list come back, because they're
// marked as parents. We don't want this, so we're filtering them out
.filter(item => item.rootStationCode === item.institutionCode),
);
}
return async dispatch => {
dispatch({ type: UPGRADING_MHV_ACCOUNT });
let mhvAccount;
let userProfile;
// If upgrade is successful, fetch user to update the list of services.
// Note that as long as the actual MHV upgrade responded with a success,
// it will count as a success even if user fetch fails for whatever reason.
try {
mhvAccount = await apiRequest(`${BASE_URL}/upgrade`, { method: 'POST' });
userProfile = await apiRequest('/user');
} catch (error) {
if (!mhvAccount) return dispatch({ type: UPGRADE_MHV_ACCOUNT_FAILURE });
}
return dispatch({
type: UPGRADE_MHV_ACCOUNT_SUCCESS,
mhvAccount,
userProfile,
});
};
}
);
dispatch({
type: SET_DISMISSED_HCA_NOTIFICATION,
data: statusEffectiveAt,
});
if (hasPreviouslyDismissedNotification) {
return apiRequest('/notifications/dismissed_statuses/form_10_10ez', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
status,
statusEffectiveAt,
}),
});
}
return apiRequest('/notifications/dismissed_statuses', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
subject: 'form_10_10ez',
status,
statusEffectiveAt,
}),
});
};
}
return (dispatch, getState) => {
dispatch({
type: SAVE_USER_PREFERENCES_STARTED,
});
const body = transformPreferencesForSaving(benefitsData);
const method = 'POST';
const headers = { 'Content-Type': 'application/json' };
return apiRequest('/user/preferences', { headers, method, body })
.then(() => {
dispatch({
type: SAVE_USER_PREFERENCES_SUCCEEDED,
});
const newBenefitSelections = getNewSelections(
getState().preferences.savedDashboard,
benefitsData,
);
const newBenefitAlerts = benefitChoices
.filter(
choice =>
!!choice.alert && newBenefitSelections.includes(choice.code),
)
.map(choice => choice.alert.name);
export function getRequestLimits(facilityId, typeOfCareId) {
let promise;
if (USE_MOCK_DATA) {
promise = Promise.resolve({
data: {
attributes: {
requestLimit: 1,
numberOfRequests: facilityId.includes('984') ? 1 : 0,
},
},
});
} else {
promise = apiRequest(
`/vaos/facilities/${facilityId}/limits?type_of_care_id=${typeOfCareId}`,
);
}
return promise.then(resp => resp.data.attributes);
}
body: JSON.stringify(payload),
method,
headers: {
'Content-Type': 'application/json',
},
};
try {
dispatch({
type: VET360_TRANSACTION_REQUESTED,
fieldName,
method,
});
const transaction = isVet360Configured()
? await apiRequest(route, options)
: await localVet360.createTransaction();
recordEvent({
event: method === 'DELETE' ? 'profile-deleted' : 'profile-transaction',
'profile-section': analyticsSectionName,
});
dispatch({
type: VET360_TRANSACTION_REQUEST_SUCCEEDED,
fieldName,
transaction,
});
} catch (error) {
dispatch({
type: VET360_TRANSACTION_REQUEST_FAILED,
error,
export function submitAppointment(appointment) {
let promise;
if (USE_MOCK_DATA || true) {
promise = Promise.resolve({
data: {
attributes: {},
},
});
} else {
promise = apiRequest('/vaos/appointments', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(appointment),
});
}
return promise.then(resp => resp.data.attributes);
}
export async function getData(apiRoute, options) {
try {
const response = await apiRequest(apiRoute, options);
return response.data.attributes;
} catch (error) {
return error;
}
}
export function getConfirmedAppointments(type, startDate, endDate) {
let promise;
if (USE_MOCK_DATA) {
if (type === 'va') {
promise = import('./confirmed_va.json').then(
module => (module.default ? module.default : module),
);
} else {
promise = import('./confirmed_cc.json').then(
module => (module.default ? module.default : module),
);
}
} else {
promise = apiRequest(
`/vaos/appointments?start_date=${startDate}&end_date=${endDate}&type=${type}`,
);
}
return promise.then(resp =>
resp.data.map(item => ({ ...item.attributes, id: item.id })),
);
}