financial-assistant

Форк
0
116 строк · 2.9 Кб
1
import axios from "../../../node_modules/axios/index";
2
import { Categories, ResponseType, TableData } from "../contracts/interfaces";
3

4
class Api {
5
  private serverUrl: string;
6

7
  constructor() {
8
    this.serverUrl = "http://127.0.0.1:8000/";
9
  }
10

11
  public async fetchBanks(): Promise<ResponseType[] | []> {
12
    try {
13
      const response = await axios.get(`${this.serverUrl}banks/`);
14
      return response.data as ResponseType[];
15
    } catch (error) {
16
      console.error("Error fetching banks:", error);
17
      return [];
18
    }
19
  }
20

21
  public async fetchProducts(): Promise<ResponseType[] | []> {
22
    try {
23
      const response = await axios.get(`${this.serverUrl}financial-products/`);
24
      return response.data as ResponseType[];
25
    } catch (error) {
26
      console.error("Error fetching financial products:", error);
27
      return [];
28
    }
29
  }
30

31
  public async fetchProductsCategories(
32
    bankId: number,
33
    productId: number
34
  ): Promise<Categories[] | []> {
35
    try {
36
      const response = await axios.get(
37
        `${this.serverUrl}products-categories/`,
38
        {
39
          params: {
40
            bank_id: bankId,
41
            product_id: productId,
42
          },
43
        }
44
      );
45
      return response.data;
46
    } catch (error) {
47
      console.error("Error fetching credit categories:", error);
48
      return [];
49
    }
50
  }
51

52
  public async fetchCategorySubsections(
53
    categoryId: number
54
  ): Promise<ResponseType[] | []> {
55
    try {
56
      const response = await axios.get(`${this.serverUrl}loan-subsections/`, {
57
        params: {
58
          category_id: categoryId,
59
        },
60
      });
61
      return response.data;
62
    } catch (error) {
63
      console.error("Error fetching category's subsections:", error);
64
      return [];
65
    }
66
  }
67

68
  public async fetchSubsectionDetails(
69
    subsectionId: number
70
  ): Promise<ResponseType[] | []> {
71
    try {
72
      const response = await axios.get(`${this.serverUrl}subsection-details/`, {
73
        params: {
74
          subsection_id: subsectionId,
75
        },
76
      });
77
      return response.data;
78
    } catch (error) {
79
      console.error("Error fetching subsection details:", error);
80
      return [];
81
    }
82
  }
83

84
  public async fetchDetailedData(
85
    loanDetailId: number
86
  ): Promise<TableData[] | []> {
87
    try {
88
      const response = await axios.get(
89
        `${this.serverUrl}detailed-description/`,
90
        {
91
          params: {
92
            loanDetail_id: loanDetailId,
93
          },
94
        }
95
      );
96
      return response.data;
97
    } catch (error) {
98
      console.error("Error fetching detailed information:", error);
99
      return [];
100
    }
101
  }
102

103
  public async assistant(query: string): Promise<ResponseType | null> {
104
    try {
105
      const response = await axios.get(
106
        `${this.serverUrl}assistant/?q=${encodeURIComponent(query)}`
107
      );
108
      return response.data;
109
    } catch (error) {
110
      console.error("Error getting loan rate:", error);
111
      return null;
112
    }
113
  }
114
}
115

116
export default Api;
117

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.