- Registration screens stubbing and partial buildouts

This commit is contained in:
Mike Fitzpatrick
2019-08-05 16:59:38 -04:00
parent a9f4324f29
commit c123ec385c
17 changed files with 505 additions and 23 deletions

View File

@@ -1,4 +1,15 @@
const apiUrl = 'http://localhost:3001';
import {
constructUrl,
formatPostData,
parseQueryParams,
request,
unwrapJson,
validateResponse,
} from './helpers.js';
import { API_URL } from '../constants/constants.js';
const DefaultRequestOptions = {};
const endpoints = {
// Events and Items
@@ -35,5 +46,47 @@ export const getEndpointUrl = (endpoint) => {
throw new Error('Invalid API endpoint specified');
}
return `${apiUrl}${endpoints[endpoint]}`; //`${cacheBuster()}`;
return `${API_URL}${endpoints[endpoint]}`; //`${cacheBuster()}`;
};
export const requestGet = (path, queryParams = [], requestOptions = {}) => {
const params = parseQueryParams(queryParams);
if (params === null) {
throw new Error('Invalid queryParams');
}
return request(constructUrl(path, params), {
...DefaultRequestOptions,
...requestOptions
})
.then(validateResponse)
.then(unwrapJson);
};
export const requestPost = (options) => {
const {
path,
body = {},
queryParams = [],
requestOptions = {},
isFormattedPostData = false
} = options;
const params = parseQueryParams(queryParams || []);
if (params === null) {
throw new Error('invalid queryParams');
}
// Additional formatting happens in `formatPostData()`
// like handling what jQuery calls `traditional` form data
return request(constructUrl(path, params), {
...DefaultRequestOptions,
...requestOptions,
method: 'POST',
body: isFormattedPostData ? body : formatPostData(body)
})
.then(validateResponse)
.then(unwrapJson);
};