@hapl/api-queries 0.1.119 → 0.1.122

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.
@@ -0,0 +1,21 @@
1
+ import { AxiosResponse, AxiosError } from 'axios';
2
+ declare type ResultData = number;
3
+ declare type ResultError = string;
4
+ export declare type CountBuyersHeaders = {
5
+ 'x-auth-hc': string;
6
+ };
7
+ export declare type CountBuyersParams = {
8
+ filter?: {
9
+ 'serviceRequest.id'?: number;
10
+ everHadStatus?: 'show_complete';
11
+ };
12
+ };
13
+ export declare type CountBuyersData = AxiosResponse<ResultData>;
14
+ export declare type CountBuyersError = AxiosError<ResultError>;
15
+ export declare type CountBuyersConfig = {
16
+ baseURL?: string;
17
+ headers: CountBuyersHeaders;
18
+ params: CountBuyersParams;
19
+ };
20
+ export declare function countBuyersRequest({ baseURL, headers, params }: CountBuyersConfig): Promise<CountBuyersData>;
21
+ export {};
@@ -5,6 +5,7 @@ export * from './availableFunds/createAvailableFunds';
5
5
  export * from './availableFunds/findAvailableFunds';
6
6
  export * from './availableFunds/updateAvailableFunds';
7
7
  export * from './availableFunds/deleteAvailableFunds';
8
+ export * from './buyer/countBuyers';
8
9
  export * from './call/findCalls';
9
10
  export * from './call/findFirstSuccessOutgoingCalls';
10
11
  export * from './call/markupCall';
@@ -9,6 +9,7 @@ export declare class Api {
9
9
  findAvailableFunds: (params: api.FindAvailableFundsParams, headers: api.FindAvailableFundsHeaders) => Promise<api.FindAvailableFundsData>;
10
10
  updateAvailableFunds: (urlParams: api.UpdateAvailableFundsUrlParams, body: api.UpdateAvailableFundsBody, headers: api.UpdateAvailableFundsHeaders) => Promise<api.UpdateAvailableFundsData>;
11
11
  deleteAvailableFunds: (urlParams: api.DeleteAvailableFundsUrlParams, headers: api.DeleteAvailableFundsHeaders) => Promise<api.DeleteAvailableFundsData>;
12
+ countBuyers: (params: api.CountBuyersParams, headers: api.CountBuyersHeaders) => Promise<api.CountBuyersData>;
12
13
  findCalls: (params: api.FindCallsParams, headers: api.FindCallsHeaders) => Promise<api.FindCallsData>;
13
14
  findFirstSuccessOutgoingCalls: (params: api.FindFirstSuccessOutgoingCallsParams, headers: api.FindFirstSuccessOutgoingCallsHeaders) => Promise<api.FindFirstSuccessOutgoingCallsData>;
14
15
  markupCall: (body: api.MarkupCallBody, headers: api.MarkupCallHeaders) => Promise<api.MarkupCallData>;
@@ -1,32 +1,37 @@
1
+ import { AxiosResponse, AxiosError } from 'axios';
1
2
  import { ActualEventsRow } from '../../types';
3
+ declare type ResultData = {
4
+ ids: string[];
5
+ byId: Record<string, ActualEventsRow & {
6
+ _id: string;
7
+ }>;
8
+ meta: {
9
+ total: number;
10
+ };
11
+ };
12
+ declare type ResultError = string;
2
13
  export declare type FindActualEventsRowHeaders = {
3
14
  'x-auth-hc': string;
4
15
  };
5
16
  export declare type FindActualEventsRowParams = {
6
17
  filter?: {
7
- 'apartment.id'?: number;
18
+ 'realty.id'?: number;
19
+ createdAt?: {
20
+ from?: string;
21
+ to?: string;
22
+ };
8
23
  };
9
24
  limits?: {
10
25
  page: number;
11
- count: number;
12
- };
13
- };
14
- export declare type FindActualEventsRowData = {
15
- data: {
16
- ids: number[];
17
- byId: Record<string, ActualEventsRow>;
26
+ count: number | 'all';
18
27
  };
19
- meta: {
20
- total: number;
21
- };
22
- };
23
- export declare type FindActualEventsRowError = {
24
- status: number;
25
- data: string;
26
28
  };
29
+ export declare type FindActualEventsRowData = AxiosResponse<ResultData>;
30
+ export declare type FindActualEventsRowError = AxiosError<ResultError>;
27
31
  export declare type FindActualEventsRowConfig = {
28
32
  baseURL?: string;
29
33
  headers: FindActualEventsRowHeaders;
30
34
  params: FindActualEventsRowParams;
31
35
  };
32
36
  export declare function findActualEventsRowRequest({ baseURL, headers, params, }: FindActualEventsRowConfig): Promise<FindActualEventsRowData>;
37
+ export {};
@@ -1,32 +1,36 @@
1
+ import { AxiosResponse, AxiosError } from 'axios';
1
2
  import { PlannedEventsRow } from '../../types';
3
+ declare type ResultData = {
4
+ ids: number[];
5
+ byId: Record<string, PlannedEventsRow>;
6
+ meta: {
7
+ total: number;
8
+ };
9
+ };
10
+ declare type ResultError = string;
2
11
  export declare type FindPlannedEventsRowHeaders = {
3
12
  'x-auth-hc': string;
4
13
  };
5
14
  export declare type FindPlannedEventsRowParams = {
6
15
  filter?: {
7
16
  id?: number;
17
+ 'realty.id'?: number;
18
+ createdAt?: {
19
+ from?: string;
20
+ to?: string;
21
+ };
8
22
  };
9
23
  limits?: {
10
24
  page: number;
11
25
  count: number;
12
26
  };
13
27
  };
14
- export declare type FindPlannedEventsRowData = {
15
- data: {
16
- ids: number[];
17
- byId: Record<string, PlannedEventsRow>;
18
- };
19
- meta: {
20
- total: number;
21
- };
22
- };
23
- export declare type FindPlannedEventsRowError = {
24
- status: number;
25
- data: string;
26
- };
28
+ export declare type FindPlannedEventsRowData = AxiosResponse<ResultData>;
29
+ export declare type FindPlannedEventsRowError = AxiosError<ResultError>;
27
30
  export declare type FindPlannedEventsRowConfig = {
28
31
  baseURL?: string;
29
32
  headers: FindPlannedEventsRowHeaders;
30
33
  params: FindPlannedEventsRowParams;
31
34
  };
32
35
  export declare function findPlannedEventsRowRequest({ baseURL, headers, params, }: FindPlannedEventsRowConfig): Promise<FindPlannedEventsRowData>;
36
+ export {};
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.1.119",
2
+ "version": "0.1.122",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -68,6 +68,7 @@
68
68
  "axios": "^0.21.1",
69
69
  "lodash": "^4.17.21",
70
70
  "lodash-es": "^4.17.21",
71
+ "nanoid": "^3.2.0",
71
72
  "qs": "^6.10.1"
72
73
  }
73
74
  }
@@ -0,0 +1,47 @@
1
+ import axios, { AxiosResponse, AxiosError, AxiosTransformer } from 'axios';
2
+ import qs from 'qs';
3
+
4
+ type SuccessData = { success: true; data: number };
5
+ type ErrorData = { success: false; data: { error: string } };
6
+
7
+ type ResultData = number;
8
+ type ResultError = string;
9
+
10
+ export type CountBuyersHeaders = { 'x-auth-hc': string };
11
+ export type CountBuyersParams = {
12
+ filter?: {
13
+ 'serviceRequest.id'?: number;
14
+ everHadStatus?: 'show_complete';
15
+ };
16
+ };
17
+ export type CountBuyersData = AxiosResponse<ResultData>;
18
+ export type CountBuyersError = AxiosError<ResultError>;
19
+ export type CountBuyersConfig = {
20
+ baseURL?: string;
21
+ headers: CountBuyersHeaders;
22
+ params: CountBuyersParams;
23
+ };
24
+
25
+ export function countBuyersRequest({ baseURL = 'https://clients.homeapp.ru', headers, params }: CountBuyersConfig) {
26
+ return axios
27
+ .get('/api/buyer/count', {
28
+ baseURL,
29
+ params,
30
+ paramsSerializer: params => qs.stringify(params, { arrayFormat: 'brackets' }),
31
+ headers: { Accept: 'application/json', ...headers },
32
+ transformResponse: [
33
+ ...(axios.defaults.transformResponse as AxiosTransformer[]),
34
+ (data: SuccessData | ErrorData): ResultData | ResultError => {
35
+ if (data.success) {
36
+ return data.data;
37
+ }
38
+
39
+ return data.data.error;
40
+ },
41
+ ],
42
+ })
43
+ .then((res: CountBuyersData) => res)
44
+ .catch((err: CountBuyersError) => {
45
+ throw err;
46
+ });
47
+ }
@@ -7,6 +7,8 @@ export * from './availableFunds/findAvailableFunds';
7
7
  export * from './availableFunds/updateAvailableFunds';
8
8
  export * from './availableFunds/deleteAvailableFunds';
9
9
 
10
+ export * from './buyer/countBuyers';
11
+
10
12
  export * from './call/findCalls';
11
13
  export * from './call/findFirstSuccessOutgoingCalls';
12
14
  export * from './call/markupCall';
@@ -39,6 +39,12 @@ export class Api {
39
39
  return api.deleteAvailableFundsRequest({ urlParams, headers, baseURL: this.baseURL });
40
40
  };
41
41
 
42
+ // buyer
43
+
44
+ countBuyers = (params: api.CountBuyersParams, headers: api.CountBuyersHeaders) => {
45
+ return api.countBuyersRequest({ params, headers, baseURL: this.baseURL });
46
+ };
47
+
42
48
  // call
43
49
 
44
50
  findCalls = (params: api.FindCallsParams, headers: api.FindCallsHeaders) => {
@@ -1,24 +1,24 @@
1
- import axios, { AxiosResponse, AxiosError } from 'axios';
1
+ import axios, { AxiosResponse, AxiosError, AxiosTransformer } from 'axios';
2
+ import { nanoid } from 'nanoid';
2
3
  import qs from 'qs';
3
4
  import { ActualEventsRow } from '../../types';
4
5
 
5
6
  type SuccessData = { success: true; data: ActualEventsRow[]; pageParams: { page: number; length: number } };
6
-
7
7
  type ErrorData = { success?: false; data?: { error: string }; message?: string };
8
8
 
9
- export type FindActualEventsRowHeaders = { 'x-auth-hc': string };
9
+ type ResultData = { ids: string[]; byId: Record<string, ActualEventsRow & { _id: string }>; meta: { total: number } };
10
+ type ResultError = string;
10
11
 
12
+ export type FindActualEventsRowHeaders = { 'x-auth-hc': string };
11
13
  export type FindActualEventsRowParams = {
12
- filter?: { 'apartment.id'?: number };
13
- limits?: { page: number; count: number };
14
- };
15
-
16
- export type FindActualEventsRowData = {
17
- data: { ids: number[]; byId: Record<string, ActualEventsRow> };
18
- meta: { total: number };
14
+ filter?: {
15
+ 'realty.id'?: number;
16
+ createdAt?: { from?: string; to?: string };
17
+ };
18
+ limits?: { page: number; count: number | 'all' };
19
19
  };
20
-
21
- export type FindActualEventsRowError = { status: number; data: string };
20
+ export type FindActualEventsRowData = AxiosResponse<ResultData>;
21
+ export type FindActualEventsRowError = AxiosError<ResultError>;
22
22
 
23
23
  export type FindActualEventsRowConfig = {
24
24
  baseURL?: string;
@@ -37,27 +37,28 @@ export function findActualEventsRowRequest({
37
37
  params,
38
38
  paramsSerializer: params => qs.stringify(params, { arrayFormat: 'brackets' }),
39
39
  headers: { Accept: 'application/json', ...headers },
40
+ transformResponse: [
41
+ ...(axios.defaults.transformResponse as AxiosTransformer[]),
42
+ (data: SuccessData | ErrorData): ResultData | ResultError => {
43
+ if (data.success) {
44
+ const ids: ResultData['ids'] = [];
45
+ const byId: ResultData['byId'] = {};
46
+
47
+ data.data.forEach(entity => {
48
+ const _id = nanoid();
49
+ byId[_id] = { ...entity, _id };
50
+ ids.push(_id);
51
+ });
52
+
53
+ return { ids, byId, meta: { total: data.pageParams.length } };
54
+ }
55
+
56
+ return data.data?.error ?? data.message ?? 'Unknown Error';
57
+ },
58
+ ],
40
59
  })
41
- .then(
42
- (res: AxiosResponse<SuccessData>): FindActualEventsRowData => {
43
- const data: FindActualEventsRowData = {
44
- data: { byId: {}, ids: [] },
45
- meta: { total: res.data.pageParams.length },
46
- };
47
-
48
- res.data.data.forEach(entity => {
49
- data.data.byId[entity.apartmentId] = entity;
50
- data.data.ids.push(entity.apartmentId);
51
- });
52
-
53
- return data;
54
- }
55
- )
56
- .catch((err: AxiosError<ErrorData>) => {
57
- const error: Error & Partial<FindActualEventsRowError> = new Error(err.message);
58
- error.status = err.response?.status ?? 520;
59
- error.data = err.response?.data.message ?? err.response?.data.data?.error ?? 'Unknown Error';
60
-
61
- throw error;
60
+ .then((res: FindActualEventsRowData) => res)
61
+ .catch((err: FindActualEventsRowError) => {
62
+ throw err;
62
63
  });
63
64
  }
@@ -1,24 +1,20 @@
1
- import axios, { AxiosResponse, AxiosError } from 'axios';
1
+ import axios, { AxiosResponse, AxiosError, AxiosTransformer } from 'axios';
2
2
  import qs from 'qs';
3
3
  import { PlannedEventsRow } from '../../types';
4
4
 
5
5
  type SuccessData = { success: true; data: PlannedEventsRow[]; pageParams: { page: number; length: number } };
6
-
7
6
  type ErrorData = { success?: false; data?: { error: string }; message?: string };
8
7
 
9
- export type FindPlannedEventsRowHeaders = { 'x-auth-hc': string };
8
+ type ResultData = { ids: number[]; byId: Record<string, PlannedEventsRow>; meta: { total: number } };
9
+ type ResultError = string;
10
10
 
11
+ export type FindPlannedEventsRowHeaders = { 'x-auth-hc': string };
11
12
  export type FindPlannedEventsRowParams = {
12
- filter?: { id?: number };
13
+ filter?: { id?: number; 'realty.id'?: number; createdAt?: { from?: string; to?: string } };
13
14
  limits?: { page: number; count: number };
14
15
  };
15
-
16
- export type FindPlannedEventsRowData = {
17
- data: { ids: number[]; byId: Record<string, PlannedEventsRow> };
18
- meta: { total: number };
19
- };
20
-
21
- export type FindPlannedEventsRowError = { status: number; data: string };
16
+ export type FindPlannedEventsRowData = AxiosResponse<ResultData>;
17
+ export type FindPlannedEventsRowError = AxiosError<ResultError>;
22
18
 
23
19
  export type FindPlannedEventsRowConfig = {
24
20
  baseURL?: string;
@@ -37,27 +33,27 @@ export function findPlannedEventsRowRequest({
37
33
  params,
38
34
  paramsSerializer: params => qs.stringify(params, { arrayFormat: 'brackets' }),
39
35
  headers: { Accept: 'application/json', ...headers },
36
+ transformResponse: [
37
+ ...(axios.defaults.transformResponse as AxiosTransformer[]),
38
+ (data: SuccessData | ErrorData): ResultData | ResultError => {
39
+ if (data.success) {
40
+ const ids: ResultData['ids'] = [];
41
+ const byId: ResultData['byId'] = {};
42
+
43
+ data.data.forEach(entity => {
44
+ byId[entity.id] = entity;
45
+ ids.push(entity.id);
46
+ });
47
+
48
+ return { ids, byId, meta: { total: data.pageParams.length } };
49
+ }
50
+
51
+ return data.data?.error ?? data.message ?? 'Unknown Error';
52
+ },
53
+ ],
40
54
  })
41
- .then(
42
- (res: AxiosResponse<SuccessData>): FindPlannedEventsRowData => {
43
- const data: FindPlannedEventsRowData = {
44
- data: { byId: {}, ids: [] },
45
- meta: { total: res.data.pageParams.length },
46
- };
47
-
48
- res.data.data.forEach(entity => {
49
- data.data.byId[entity.id] = entity;
50
- data.data.ids.push(entity.id);
51
- });
52
-
53
- return data;
54
- }
55
- )
56
- .catch((err: AxiosError<ErrorData>) => {
57
- const error: Error & Partial<FindPlannedEventsRowError> = new Error(err.message);
58
- error.status = err.response?.status ?? 520;
59
- error.data = err.response?.data.message ?? err.response?.data.data?.error ?? 'Unknown Error';
60
-
61
- throw error;
55
+ .then((res: FindPlannedEventsRowData) => res)
56
+ .catch((err: FindPlannedEventsRowError) => {
57
+ throw err;
62
58
  });
63
59
  }