@hapl/api-queries 0.1.70 → 0.1.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/dist/api-queries.cjs.development.js +80 -101
  3. package/dist/api-queries.cjs.development.js.map +1 -1
  4. package/dist/api-queries.cjs.production.min.js +1 -1
  5. package/dist/api-queries.cjs.production.min.js.map +1 -1
  6. package/dist/api-queries.esm.js +80 -101
  7. package/dist/api-queries.esm.js.map +1 -1
  8. package/dist/clients/v1/api/auth/checkPassword/index.d.ts +2 -6
  9. package/dist/clients/v1/api/auth/checkToken/index.d.ts +9 -7
  10. package/dist/clients/v1/api/auth/getPassword/index.d.ts +11 -7
  11. package/dist/clients/v1/api/availableFunds/createAvailableFunds/index.d.ts +16 -7
  12. package/dist/clients/v1/api/availableFunds/deleteAvailableFunds/index.d.ts +16 -7
  13. package/dist/clients/v1/api/availableFunds/findAvailableFunds/index.d.ts +12 -13
  14. package/dist/clients/v1/api/availableFunds/updateAvailableFunds/index.d.ts +16 -7
  15. package/dist/clients/v1/api/experts/findPublishedExperts/index.d.ts +14 -15
  16. package/package.json +1 -1
  17. package/src/clients/v1/api/auth/checkPassword/index.ts +4 -6
  18. package/src/clients/v1/api/auth/checkToken/index.ts +17 -15
  19. package/src/clients/v1/api/auth/getPassword/index.ts +22 -15
  20. package/src/clients/v1/api/availableFunds/createAvailableFunds/index.ts +17 -15
  21. package/src/clients/v1/api/availableFunds/deleteAvailableFunds/index.ts +21 -16
  22. package/src/clients/v1/api/availableFunds/findAvailableFunds/index.ts +27 -32
  23. package/src/clients/v1/api/availableFunds/updateAvailableFunds/index.ts +17 -16
  24. package/src/clients/v1/api/experts/findPublishedExperts/index.ts +27 -31
@@ -1,4 +1,4 @@
1
- import axios, { AxiosResponse, AxiosError } from 'axios';
1
+ import axios, { AxiosResponse, AxiosError, AxiosTransformer } from 'axios';
2
2
  import qs from 'qs';
3
3
  import { User, UserDirection, UserOffice } from '../../../types';
4
4
 
@@ -7,9 +7,11 @@ type SuccessData = {
7
7
  data: Partial<User> & { id: number }[];
8
8
  pageParams: { page: number; length: number };
9
9
  };
10
-
11
10
  type ErrorData = { success: false; data: { error: string } };
12
11
 
12
+ type ResultData = { ids: number[]; byId: Record<string, Partial<User> & { id: number }>; meta: { total: number } };
13
+ type ResultError = string;
14
+
13
15
  export type FindPublishedExpertsParams = {
14
16
  filter?: {
15
17
  id?: number | number[];
@@ -20,14 +22,8 @@ export type FindPublishedExpertsParams = {
20
22
  limits?: { page: number; count: number };
21
23
  sorting?: { direction: 'asc' | 'desc'; type: 'id' | 'expert.scoring' };
22
24
  };
23
-
24
- export type FindPublishedExpertsData = {
25
- data: { ids: number[]; byId: Record<string, Partial<User> & { id: number }> };
26
- meta: { total: number };
27
- };
28
-
29
- export type FindPublishedExpertsError = { status: number; data: string };
30
-
25
+ export type FindPublishedExpertsData = AxiosResponse<ResultData>;
26
+ export type FindPublishedExpertsError = AxiosError<ResultError>;
31
27
  export type FindPublishedExpertsConfig = { baseURL?: string; params: FindPublishedExpertsParams };
32
28
 
33
29
  export function findPublishedExpertsRequest({
@@ -40,27 +36,27 @@ export function findPublishedExpertsRequest({
40
36
  params,
41
37
  paramsSerializer: params => qs.stringify(params, { arrayFormat: 'brackets' }),
42
38
  headers: { Accept: 'application/json' },
39
+ transformResponse: [
40
+ ...(axios.defaults.transformResponse as AxiosTransformer[]),
41
+ (data: SuccessData | ErrorData): ResultData | ResultError => {
42
+ if (data.success) {
43
+ const ids: ResultData['ids'] = [];
44
+ const byId: ResultData['byId'] = {};
45
+
46
+ data.data.forEach(entity => {
47
+ byId[entity.id] = entity;
48
+ ids.push(entity.id);
49
+ });
50
+
51
+ return { ids, byId, meta: { total: data.pageParams.length } };
52
+ }
53
+
54
+ return data.data.error;
55
+ },
56
+ ],
43
57
  })
44
- .then(
45
- (res: AxiosResponse<SuccessData>): FindPublishedExpertsData => {
46
- const data: FindPublishedExpertsData = {
47
- data: { byId: {}, ids: [] },
48
- meta: { total: res.data.pageParams.length },
49
- };
50
-
51
- res.data.data.forEach(entity => {
52
- data.data.byId[entity.id] = entity;
53
- data.data.ids.push(entity.id);
54
- });
55
-
56
- return data;
57
- }
58
- )
59
- .catch((err: AxiosError<ErrorData>) => {
60
- const error: Error & Partial<FindPublishedExpertsError> = new Error(err.message);
61
- error.status = err.response?.status ?? 520;
62
- error.data = err.response?.data.data.error ?? 'Unknown Error';
63
-
64
- throw error;
58
+ .then((res: FindPublishedExpertsData) => res)
59
+ .catch((err: FindPublishedExpertsError) => {
60
+ throw err;
65
61
  });
66
62
  }