2017-12-11 15:16:57 -08:00
|
|
|
import { IPlatformsResponse, IDataPlatform } from 'wherehows-web/typings/api/list/platforms';
|
|
|
|
import { ApiStatus } from 'wherehows-web/utils/api';
|
|
|
|
import { getJSON } from 'wherehows-web/utils/api/fetcher';
|
2018-01-24 15:41:46 -08:00
|
|
|
import { getListUrlRoot } from 'wherehows-web/utils/api/list/shared';
|
2017-12-11 15:16:57 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines the url endpoint for the list of data platforms
|
|
|
|
*/
|
2018-01-24 15:41:46 -08:00
|
|
|
const platformsUrl = `${getListUrlRoot('v2')}/platforms`;
|
2017-12-11 15:16:57 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Requests the list of data platforms and associated properties
|
2018-01-24 15:41:46 -08:00
|
|
|
* @returns {Promise<Array<IDataPlatform>>}
|
2017-12-11 15:16:57 -08:00
|
|
|
*/
|
|
|
|
const readPlatforms = async (): Promise<Array<IDataPlatform>> => {
|
|
|
|
const { status, platforms = [], msg } = await getJSON<IPlatformsResponse>({ url: platformsUrl });
|
|
|
|
|
|
|
|
if (status === ApiStatus.OK) {
|
|
|
|
if (!platforms.length) {
|
|
|
|
throw new Error('No platforms found');
|
|
|
|
}
|
|
|
|
|
|
|
|
return platforms;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error(msg);
|
|
|
|
};
|
|
|
|
|
|
|
|
export { readPlatforms };
|