- Registration screens stubbing and partial buildouts
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user