From f18b452fc181e1beb5793b289ed141417704ca2c Mon Sep 17 00:00:00 2001 From: "mirlan.maksitaliev" Date: Tue, 16 Jun 2020 17:55:25 +0600 Subject: [PATCH] feat(ott-91): added countries list request --- src/config/index.tsx | 1 + src/config/procedures.tsx | 3 +++ src/config/routes.tsx | 2 +- src/helpers/callApi/getResponseData.tsx | 2 +- src/helpers/index.tsx | 1 + src/requests/getCountries.tsx | 28 +++++++++++++++++++++++++ src/requests/index.tsx | 1 + 7 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/config/procedures.tsx create mode 100644 src/requests/getCountries.tsx diff --git a/src/config/index.tsx b/src/config/index.tsx index bf81f61f..e5851bad 100644 --- a/src/config/index.tsx +++ b/src/config/index.tsx @@ -1,3 +1,4 @@ export * from './routes' export * from './pages' export * from './authKeys' +export * from './procedures' diff --git a/src/config/procedures.tsx b/src/config/procedures.tsx new file mode 100644 index 00000000..6138575d --- /dev/null +++ b/src/config/procedures.tsx @@ -0,0 +1,3 @@ +export const PROCEDURES = { + lst_c_country: 'lst_c_country', +} diff --git a/src/config/routes.tsx b/src/config/routes.tsx index 7cc14d50..708156ee 100644 --- a/src/config/routes.tsx +++ b/src/config/routes.tsx @@ -1,2 +1,2 @@ -export const API_ROOT = '' +export const API_ROOT = 'http://85.10.224.24:8080' export const DATA_URL = `${API_ROOT}/data` diff --git a/src/helpers/callApi/getResponseData.tsx b/src/helpers/callApi/getResponseData.tsx index 149ace17..2aa97ed1 100644 --- a/src/helpers/callApi/getResponseData.tsx +++ b/src/helpers/callApi/getResponseData.tsx @@ -1,3 +1,3 @@ export const getResponseData = (proc: string) => (response: any) => ( - response?.data?.[0]?.[proc] + response?.[proc] ) diff --git a/src/helpers/index.tsx b/src/helpers/index.tsx index 8842e651..1ba6128d 100644 --- a/src/helpers/index.tsx +++ b/src/helpers/index.tsx @@ -1 +1,2 @@ export * from './callApi' +export * from './callApi/getResponseData' diff --git a/src/requests/getCountries.tsx b/src/requests/getCountries.tsx new file mode 100644 index 00000000..30944b42 --- /dev/null +++ b/src/requests/getCountries.tsx @@ -0,0 +1,28 @@ +import { DATA_URL, PROCEDURES } from 'config' +import { callApi, getResponseData } from 'helpers' + +const proc = PROCEDURES.lst_c_country + +export type Country = { + id: number, + iso_3166_1_alpha_2: string, + iso_3166_1_alpha_3: string, + name_eng: string, + name_rus: string, +} + +export type Countries = Array + +export const getCountries = (): Promise => { + const config = { + body: { + params: null, + proc, + }, + } + + return callApi({ + config, + url: DATA_URL, + }).then(getResponseData(proc)) +} diff --git a/src/requests/index.tsx b/src/requests/index.tsx index d4389750..a803e3e4 100644 --- a/src/requests/index.tsx +++ b/src/requests/index.tsx @@ -1 +1,2 @@ export * from './login' +export * from './getCountries'