You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
910 B

4 years ago
/**
* @file Утилиты
* @version 2022.01.26
* @author Verevkin S.A.
* @copyright Verevkin S.A.
*/
import axios from 'axios';
import _ from 'lodash';
export type ParamGet = {
name: string,
value: string,
};
4 years ago
const tool = {
apiUrl: process.env.REACT_APP_API_URL,
// region функции
// метод взаимодействия с REST-сервисом
get<TResult>(
method: string,
args: ParamGet[],
4 years ago
): Promise<TResult | undefined> {
const url = this.apiUrl + method;
const requestConfig = {
params: _.fromPairs(args.map((v) => [v.name, v.value]))
4 years ago
};
return axios
.get<TResult>(
`${url}`,
requestConfig,
)
.then((response) => {
const { data } = response;
return data;
})
.catch((err) => {
console.warn(err);
throw err;
4 years ago
});
},
//endregion
};
export default tool;