@hapl/api-queries 0.1.127 → 0.1.129

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 (28) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/api-queries.cjs.development.js +188 -21
  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 +188 -21
  7. package/dist/api-queries.esm.js.map +1 -1
  8. package/dist/clients/v1/api/callTask/findCallTasks.d.ts +37 -0
  9. package/dist/clients/v1/api/index.d.ts +3 -0
  10. package/dist/clients/v1/api/serviceRequest/depublishServiceRequest/index.d.ts +29 -0
  11. package/dist/clients/v1/api/serviceRequest/publishServiceRequest/index.d.ts +24 -0
  12. package/dist/clients/v1/index.d.ts +3 -0
  13. package/dist/publisher/v1/api/findExternalLinks/index.d.ts +41 -0
  14. package/dist/publisher/v1/api/findStatisticRow/index.d.ts +61 -0
  15. package/dist/publisher/v1/api/index.d.ts +2 -1
  16. package/dist/publisher/v1/index.d.ts +2 -1
  17. package/package.json +1 -1
  18. package/src/clients/v1/api/callTask/findCallTasks.ts +60 -0
  19. package/src/clients/v1/api/index.ts +3 -0
  20. package/src/clients/v1/api/serviceRequest/depublishServiceRequest/index.ts +40 -0
  21. package/src/clients/v1/api/serviceRequest/publishServiceRequest/index.ts +41 -0
  22. package/src/clients/v1/index.ts +19 -0
  23. package/src/publisher/v1/api/findExternalLinks/index.ts +65 -0
  24. package/src/publisher/v1/api/findStatisticRow/index.ts +71 -0
  25. package/src/publisher/v1/api/index.ts +2 -1
  26. package/src/publisher/v1/index.ts +6 -2
  27. package/dist/publisher/v1/api/getExternalLinks/index.d.ts +0 -32
  28. package/src/publisher/v1/api/getExternalLinks/index.ts +0 -55
@@ -0,0 +1,37 @@
1
+ import { AxiosResponse, AxiosError } from 'axios';
2
+ import { CallTask, CallTaskStatus } from '../../types';
3
+ declare type Data = Partial<CallTask> & Required<Pick<CallTask, 'id' | 'status' | 'createdAt'>>;
4
+ declare type ResultData = {
5
+ ids: number[];
6
+ byId: Record<string, Data>;
7
+ meta: {
8
+ total: number;
9
+ };
10
+ };
11
+ declare type ResultError = string;
12
+ export declare type FindCallTasksHeaders = {
13
+ 'x-auth-hc': string;
14
+ };
15
+ export declare type FindCallTasksParams = {
16
+ filter?: {
17
+ id?: number | number[];
18
+ status?: CallTaskStatus | CallTaskStatus[];
19
+ };
20
+ limits?: {
21
+ page?: number;
22
+ count: number | 'all';
23
+ };
24
+ sorting?: {
25
+ direction: 'asc' | 'desc';
26
+ type: 'createdAt' | 'id';
27
+ };
28
+ };
29
+ export declare type FindCallTasksData = AxiosResponse<ResultData>;
30
+ export declare type FindCallTasksError = AxiosError<ResultError>;
31
+ export declare type FindCallTasksConfig = {
32
+ baseURL?: string;
33
+ headers: FindCallTasksHeaders;
34
+ params: FindCallTasksParams;
35
+ };
36
+ export declare function findCallTasksRequest({ baseURL, headers, params }: FindCallTasksConfig): Promise<FindCallTasksData>;
37
+ export {};
@@ -16,6 +16,7 @@ export * from './callCenter/finishOperatorWork';
16
16
  export * from './callCenter/getOperatorStatus';
17
17
  export * from './callCenter/startOperatorWork';
18
18
  export * from './callTask/createCallTask';
19
+ export * from './callTask/findCallTasks';
19
20
  export * from './contract/approveContract';
20
21
  export * from './contract/declineContract';
21
22
  export * from './contract/findContracts';
@@ -58,6 +59,8 @@ export * from './serviceRequest/returnDeferredServiceRequest';
58
59
  export * from './serviceRequest/sendServiceRequestToModeration';
59
60
  export * from './serviceRequest/startServiceRequestModeration';
60
61
  export * from './serviceRequest/startServiceRequestModerationForOldRealty';
62
+ export * from './serviceRequest/publishServiceRequest';
63
+ export * from './serviceRequest/depublishServiceRequest';
61
64
  export * from './sold/findSoldStatistic';
62
65
  export * from './users/createUser';
63
66
  export * from './users/findUsers';
@@ -0,0 +1,29 @@
1
+ import { AxiosResponse, AxiosError } from 'axios';
2
+ declare type ErrorData = {
3
+ success: false;
4
+ data: {
5
+ error: string;
6
+ };
7
+ };
8
+ declare type ResultData = null;
9
+ declare type ResultError = ErrorData['data']['error'];
10
+ export declare type DepublishServiceRequestHeaders = {
11
+ 'x-auth-hc': string;
12
+ };
13
+ export declare type DepublishServiceRequestUrlParams = {
14
+ id: number;
15
+ };
16
+ export declare type DepublishServiceRequestBody = {
17
+ depublishReason: string;
18
+ isEnabled: boolean;
19
+ };
20
+ export declare type DepublishServiceRequestData = AxiosResponse<ResultData>;
21
+ export declare type DepublishServiceRequestError = AxiosError<ResultError>;
22
+ export declare type DepublishServiceRequestConfig = {
23
+ baseURL?: string;
24
+ headers: DepublishServiceRequestHeaders;
25
+ urlParams: DepublishServiceRequestUrlParams;
26
+ body: DepublishServiceRequestBody;
27
+ };
28
+ export declare function depublishServiceRequest({ baseURL, urlParams, body, headers, }: DepublishServiceRequestConfig): Promise<DepublishServiceRequestData>;
29
+ export {};
@@ -0,0 +1,24 @@
1
+ import { AxiosResponse, AxiosError } from 'axios';
2
+ declare type ErrorData = {
3
+ success: false;
4
+ data: {
5
+ error: string;
6
+ };
7
+ };
8
+ declare type ResultData = null;
9
+ declare type ResultError = ErrorData['data']['error'];
10
+ export declare type PublishServiceRequestUrlParams = {
11
+ id: number;
12
+ };
13
+ export declare type PublishServiceRequestHeaders = {
14
+ 'x-auth-hc': string;
15
+ };
16
+ export declare type PublishServiceRequestData = AxiosResponse<ResultData>;
17
+ export declare type PublishServiceRequestError = AxiosError<ResultError>;
18
+ export declare type PublishServiceRequestConfig = {
19
+ baseURL?: string;
20
+ headers: PublishServiceRequestHeaders;
21
+ urlParams: PublishServiceRequestUrlParams;
22
+ };
23
+ export declare function publishServiceRequest({ baseURL, urlParams, headers, }: PublishServiceRequestConfig): Promise<PublishServiceRequestData>;
24
+ export {};
@@ -20,6 +20,7 @@ export declare class Api {
20
20
  startOperatorWork: (headers: api.StartOperatorWorkHeaders) => Promise<api.StartOperatorWorkData>;
21
21
  getOperatorStatus: (headers: api.GetOperatorStatusHeaders) => Promise<api.GetOperatorStatusData>;
22
22
  createCallTask: (body: api.CreateCallTaskBody, headers: api.CreateCallTaskHeaders) => Promise<api.CreateCallTaskData>;
23
+ findCallTasks: (params: api.FindCallTasksParams, headers: api.FindCallTasksHeaders) => Promise<api.FindCallTasksData>;
23
24
  approveContract: (urlParams: api.ApproveContractUrlParams, body: api.ApproveContractBody, headers: api.ApproveContractHeaders) => Promise<api.ApproveContractData>;
24
25
  declineContract: (urlParams: api.DeclineContractUrlParams, body: api.DeclineContractBody, headers: api.DeclineContractHeaders) => Promise<api.DeclineContractData>;
25
26
  findContracts: (params: api.FindContractsParams, headers: api.FindContractsHeaders) => Promise<api.FindContractsData>;
@@ -58,6 +59,8 @@ export declare class Api {
58
59
  findServiceRequestCategorizedFiles: (urlParams: api.FindServiceRequestCategorizedFilesUrlParams, params: api.FindServiceRequestCategorizedFilesParams, headers: api.FindServiceRequestCategorizedFilesHeaders) => Promise<api.FindServiceRequestCategorizedFilesData>;
59
60
  findServiceRequestCategorizedFileCreatedDate: (urlParams: api.FindServiceRequestCategorizedFileCreatedDateUrlParams, headers: api.FindServiceRequestCategorizedFileCreatedDateHeaders) => Promise<api.FindServiceRequestCategorizedFileCreatedDateData>;
60
61
  sendServiceRequestToModeration: (urlParams: api.SendServiceRequestToModerationUrlParams, headers: api.SendServiceRequestToModerationHeaders) => Promise<api.SendServiceRequestToModerationData>;
62
+ publishServiceRequest: (urlParams: api.PublishServiceRequestUrlParams, headers: api.PublishServiceRequestHeaders) => Promise<api.PublishServiceRequestData>;
63
+ depublishServiceRequest: (urlParams: api.DepublishServiceRequestUrlParams, headers: api.DepublishServiceRequestHeaders, body: api.DepublishServiceRequestBody) => Promise<api.DepublishServiceRequestData>;
61
64
  returnDeferredServiceRequest: (body: api.ReturnDeferredServiceRequestBody, headers: api.ReturnDeferredServiceRequestHeaders) => Promise<api.ReturnDeferredServiceRequestData>;
62
65
  startServiceRequestModeration: (urlParams: api.StartServiceRequestModerationUrlParams, headers: api.StartServiceRequestModerationHeaders) => Promise<api.StartServiceRequestModerationData>;
63
66
  startServiceRequestModerationForOldRealty: (urlParams: api.StartServiceRequestModerationForOldRealtyUrlParams, headers: api.StartServiceRequestModerationForOldRealtyHeaders) => Promise<api.StartServiceRequestModerationForOldRealtyData>;
@@ -0,0 +1,41 @@
1
+ import { AxiosResponse, AxiosError } from 'axios';
2
+ export declare type ExternalLink = {
3
+ apartmentId: number;
4
+ url: string;
5
+ externalSite: string;
6
+ };
7
+ declare type ErrorData = {
8
+ success?: false;
9
+ data: {
10
+ error: string;
11
+ };
12
+ };
13
+ declare type ResultData = {
14
+ ids: string[];
15
+ byId: Record<string, ExternalLink>;
16
+ meta: {
17
+ total: number;
18
+ };
19
+ };
20
+ declare type ResultError = ErrorData['data']['error'];
21
+ export declare type FindExternalLinksHeaders = {
22
+ 'x-auth-hc'?: string;
23
+ };
24
+ export declare type FindExternalLinksParams = {
25
+ filter?: {
26
+ 'realty.id'?: string;
27
+ };
28
+ limits?: {
29
+ page?: number;
30
+ count?: number | 'all';
31
+ };
32
+ };
33
+ export declare type FindExternalLinksData = AxiosResponse<ResultData>;
34
+ export declare type FindExternalLinksError = AxiosError<ResultError>;
35
+ export declare type FindExternalLinksConfig = {
36
+ baseURL?: string;
37
+ headers?: FindExternalLinksHeaders;
38
+ params: FindExternalLinksParams;
39
+ };
40
+ export declare function findExternalLinksRequest({ baseURL, headers, params, }: FindExternalLinksConfig): Promise<FindExternalLinksData>;
41
+ export {};
@@ -0,0 +1,61 @@
1
+ import { AxiosResponse, AxiosError } from 'axios';
2
+ export declare type StatisticRow = {
3
+ createdAt: string;
4
+ apartmentId?: number;
5
+ likes?: {
6
+ value: number;
7
+ delta: number;
8
+ };
9
+ listingViews?: {
10
+ value: number;
11
+ delta: number;
12
+ };
13
+ phoneViews?: {
14
+ value: number;
15
+ delta: number;
16
+ };
17
+ source: string;
18
+ views: {
19
+ value: number;
20
+ delta: number;
21
+ };
22
+ };
23
+ declare type ErrorData = {
24
+ success?: false;
25
+ data: {
26
+ error: string;
27
+ };
28
+ };
29
+ declare type ResultData = {
30
+ ids: string[];
31
+ byId: Record<string, StatisticRow>;
32
+ meta: {
33
+ total: number;
34
+ };
35
+ };
36
+ declare type ResultError = ErrorData['data']['error'];
37
+ export declare type FindStatisticRowHeaders = {
38
+ 'x-auth-hc'?: string;
39
+ };
40
+ export declare type FindStatisticRowParams = {
41
+ filter?: {
42
+ 'realty.id'?: number;
43
+ createdAt?: {
44
+ from?: string;
45
+ to?: string;
46
+ };
47
+ };
48
+ limits?: {
49
+ page?: number;
50
+ count?: number | 'all';
51
+ };
52
+ };
53
+ export declare type FindStatisticRowData = AxiosResponse<ResultData>;
54
+ export declare type FindStatisticRowError = AxiosError<ResultError>;
55
+ export declare type FindStatisticRowConfig = {
56
+ baseURL?: string;
57
+ headers?: FindStatisticRowHeaders;
58
+ params: FindStatisticRowParams;
59
+ };
60
+ export declare function findStatisticRowRequest({ baseURL, headers, params, }: FindStatisticRowConfig): Promise<FindStatisticRowData>;
61
+ export {};
@@ -2,7 +2,8 @@ export * from './findActualEventsRow';
2
2
  export * from './findNewBuildings';
3
3
  export * from './findPlannedEventsRow';
4
4
  export * from './findScoring';
5
- export * from './getExternalLinks';
5
+ export * from './findExternalLinks';
6
+ export * from './findStatisticRow';
6
7
  export * from './getFirstPublishedAt';
7
8
  export * from './getPublishedDays';
8
9
  export * from './sendResume';
@@ -5,7 +5,8 @@ export declare class Api {
5
5
  getFirstPublishedAt: (urlParams: api.GetFirstPublishedAtUrlParams, headers: api.GetFirstPublishedAtHeaders) => Promise<api.GetFirstPublishedAtData>;
6
6
  getPublishedDays: (urlParams: api.GetPublishedDaysUrlParams, headers: api.GetPublishedDaysHeaders) => Promise<api.GetPublishedDaysData>;
7
7
  findNewBuildings: (params: api.FindNewBuildingsParams, headers: api.FindNewBuildingsHeaders) => Promise<api.FindNewBuildingsData>;
8
- getExternalLinks: (params: api.GetExternalLinksParams, headers: api.GetExternalLinksHeaders) => Promise<api.GetExternalLinksData>;
8
+ findExternalLinks: (params: api.FindExternalLinksParams, headers?: api.FindExternalLinksHeaders | undefined) => Promise<api.FindExternalLinksData>;
9
+ findStatisticRow: (params: api.FindStatisticRowParams, headers?: api.FindStatisticRowHeaders | undefined) => Promise<api.FindStatisticRowData>;
9
10
  findActualEventsRow: (params: api.FindActualEventsRowParams, headers: api.FindActualEventsRowHeaders) => Promise<api.FindActualEventsRowData>;
10
11
  findPlannedEventsRow: (params: api.FindPlannedEventsRowParams, headers: api.FindPlannedEventsRowHeaders) => Promise<api.FindPlannedEventsRowData>;
11
12
  getScoring: (params: api.FindScoringParams, headers: api.FindScoringHeaders) => Promise<api.FindScoringData>;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.1.127",
2
+ "version": "0.1.129",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -0,0 +1,60 @@
1
+ import axios, { AxiosResponse, AxiosError, AxiosTransformer } from 'axios';
2
+ import qs from 'qs';
3
+ import { CallTask, CallTaskStatus } from '../../types';
4
+
5
+ type Data = Partial<CallTask> & Required<Pick<CallTask, 'id' | 'status' | 'createdAt'>>;
6
+
7
+ type SuccessData = { success: true; data: Data[]; pageParams: { page: number; length: number } };
8
+ type ErrorData = { success: false; data: Record<'error' | 'message', string> };
9
+
10
+ type ResultData = { ids: number[]; byId: Record<string, Data>; meta: { total: number } };
11
+ type ResultError = string;
12
+
13
+ export type FindCallTasksHeaders = { 'x-auth-hc': string };
14
+ export type FindCallTasksParams = {
15
+ filter?: {
16
+ id?: number | number[];
17
+ status?: CallTaskStatus | CallTaskStatus[];
18
+ };
19
+ limits?: { page?: number; count: number | 'all' };
20
+ sorting?: { direction: 'asc' | 'desc'; type: 'createdAt' | 'id' };
21
+ };
22
+ export type FindCallTasksData = AxiosResponse<ResultData>;
23
+ export type FindCallTasksError = AxiosError<ResultError>;
24
+ export type FindCallTasksConfig = {
25
+ baseURL?: string;
26
+ headers: FindCallTasksHeaders;
27
+ params: FindCallTasksParams;
28
+ };
29
+
30
+ export function findCallTasksRequest({ baseURL = 'https://clients.homeapp.ru', headers, params }: FindCallTasksConfig) {
31
+ return axios
32
+ .get('/api/calls/task', {
33
+ baseURL,
34
+ params,
35
+ paramsSerializer: params => qs.stringify(params, { arrayFormat: 'brackets' }),
36
+ headers: { Accept: 'application/json', 'Content-Type': 'application/json', ...headers },
37
+ transformResponse: [
38
+ ...(axios.defaults.transformResponse as AxiosTransformer[]),
39
+ (data: SuccessData | ErrorData): ResultData | ResultError => {
40
+ if (data.success) {
41
+ const ids: ResultData['ids'] = [];
42
+ const byId: ResultData['byId'] = {};
43
+
44
+ data.data.forEach(entity => {
45
+ byId[entity.id] = entity;
46
+ ids.push(entity.id);
47
+ });
48
+
49
+ return { ids, byId, meta: { total: data.pageParams.length } };
50
+ }
51
+
52
+ return data.data.error || data.data.message;
53
+ },
54
+ ],
55
+ })
56
+ .then((res: FindCallTasksData) => res)
57
+ .catch((err: FindCallTasksError) => {
58
+ throw err;
59
+ });
60
+ }
@@ -22,6 +22,7 @@ export * from './callCenter/getOperatorStatus';
22
22
  export * from './callCenter/startOperatorWork';
23
23
 
24
24
  export * from './callTask/createCallTask';
25
+ export * from './callTask/findCallTasks';
25
26
 
26
27
  export * from './contract/approveContract';
27
28
  export * from './contract/declineContract';
@@ -68,6 +69,8 @@ export * from './serviceRequest/returnDeferredServiceRequest';
68
69
  export * from './serviceRequest/sendServiceRequestToModeration';
69
70
  export * from './serviceRequest/startServiceRequestModeration';
70
71
  export * from './serviceRequest/startServiceRequestModerationForOldRealty';
72
+ export * from './serviceRequest/publishServiceRequest';
73
+ export * from './serviceRequest/depublishServiceRequest';
71
74
 
72
75
  export * from './sold/findSoldStatistic';
73
76
 
@@ -0,0 +1,40 @@
1
+ import axios, { AxiosResponse, AxiosError, AxiosTransformer } from 'axios';
2
+
3
+ type SuccessData = { success: true };
4
+ type ErrorData = { success: false; data: { error: string } };
5
+
6
+ type ResultData = null;
7
+ type ResultError = ErrorData['data']['error'];
8
+
9
+ export type DepublishServiceRequestHeaders = { 'x-auth-hc': string };
10
+ export type DepublishServiceRequestUrlParams = { id: number };
11
+ export type DepublishServiceRequestBody = { depublishReason: string; isEnabled: boolean };
12
+ export type DepublishServiceRequestData = AxiosResponse<ResultData>;
13
+ export type DepublishServiceRequestError = AxiosError<ResultError>;
14
+ export type DepublishServiceRequestConfig = {
15
+ baseURL?: string;
16
+ headers: DepublishServiceRequestHeaders;
17
+ urlParams: DepublishServiceRequestUrlParams;
18
+ body: DepublishServiceRequestBody;
19
+ };
20
+
21
+ export function depublishServiceRequest({
22
+ baseURL = 'https://clients.homeapp.ru',
23
+ urlParams,
24
+ body,
25
+ headers,
26
+ }: DepublishServiceRequestConfig) {
27
+ return axios
28
+ .patch(`/api/service-request/depublish/${urlParams.id}`, body, {
29
+ baseURL,
30
+ headers: { Accept: 'application/json', 'Content-Type': 'application/json', ...headers },
31
+ transformResponse: [
32
+ ...(axios.defaults.transformResponse as AxiosTransformer[]),
33
+ (data: SuccessData | ErrorData): ResultData | ResultError => (data.success ? null : data.data?.error),
34
+ ],
35
+ })
36
+ .then((res: DepublishServiceRequestData) => res)
37
+ .catch((err: DepublishServiceRequestError) => {
38
+ throw err;
39
+ });
40
+ }
@@ -0,0 +1,41 @@
1
+ import axios, { AxiosResponse, AxiosError, AxiosTransformer } from 'axios';
2
+
3
+ type SuccessData = { success: true };
4
+ type ErrorData = { success: false; data: { error: string } };
5
+
6
+ type ResultData = null;
7
+ type ResultError = ErrorData['data']['error'];
8
+
9
+ export type PublishServiceRequestUrlParams = { id: number };
10
+ export type PublishServiceRequestHeaders = { 'x-auth-hc': string };
11
+ export type PublishServiceRequestData = AxiosResponse<ResultData>;
12
+ export type PublishServiceRequestError = AxiosError<ResultError>;
13
+ export type PublishServiceRequestConfig = {
14
+ baseURL?: string;
15
+ headers: PublishServiceRequestHeaders;
16
+ urlParams: PublishServiceRequestUrlParams;
17
+ };
18
+
19
+ export function publishServiceRequest({
20
+ baseURL = 'https://clients.homeapp.ru',
21
+ urlParams,
22
+ headers,
23
+ }: PublishServiceRequestConfig) {
24
+ return axios
25
+ .patch(
26
+ `/api/service-request/publish/${urlParams.id}`,
27
+ {},
28
+ {
29
+ baseURL,
30
+ headers: { Accept: 'application/json', 'Content-Type': 'application/json', ...headers },
31
+ transformResponse: [
32
+ ...(axios.defaults.transformResponse as AxiosTransformer[]),
33
+ (data: SuccessData | ErrorData): ResultData | ResultError => (data.success ? null : data.data?.error),
34
+ ],
35
+ }
36
+ )
37
+ .then((res: PublishServiceRequestData) => res)
38
+ .catch((err: PublishServiceRequestError) => {
39
+ throw err;
40
+ });
41
+ }
@@ -96,6 +96,10 @@ export class Api {
96
96
  return api.createCallTaskRequest({ body, headers, baseURL: this.baseURL });
97
97
  };
98
98
 
99
+ findCallTasks = (params: api.FindCallTasksParams, headers: api.FindCallTasksHeaders) => {
100
+ return api.findCallTasksRequest({ params, headers, baseURL: this.baseURL });
101
+ };
102
+
99
103
  // contract
100
104
 
101
105
  approveContract = (
@@ -350,6 +354,21 @@ export class Api {
350
354
  return api.sendServiceRequestToModerationRequest({ urlParams, headers, baseURL: this.baseURL });
351
355
  };
352
356
 
357
+ publishServiceRequest = (
358
+ urlParams: api.PublishServiceRequestUrlParams,
359
+ headers: api.PublishServiceRequestHeaders
360
+ ) => {
361
+ return api.publishServiceRequest({ urlParams, headers, baseURL: this.baseURL });
362
+ };
363
+
364
+ depublishServiceRequest = (
365
+ urlParams: api.DepublishServiceRequestUrlParams,
366
+ headers: api.DepublishServiceRequestHeaders,
367
+ body: api.DepublishServiceRequestBody
368
+ ) => {
369
+ return api.depublishServiceRequest({ urlParams, headers, body, baseURL: this.baseURL });
370
+ };
371
+
353
372
  returnDeferredServiceRequest = (
354
373
  body: api.ReturnDeferredServiceRequestBody,
355
374
  headers: api.ReturnDeferredServiceRequestHeaders
@@ -0,0 +1,65 @@
1
+ import axios, { AxiosResponse, AxiosError, AxiosTransformer } from 'axios';
2
+ import qs from 'qs';
3
+
4
+ export type ExternalLink = { apartmentId: number; url: string; externalSite: string };
5
+ type SuccessData = {
6
+ success: true;
7
+ data: Array<ExternalLink>;
8
+ pageParams: { page?: number; length: number };
9
+ };
10
+ type ErrorData = { success?: false; data: { error: string } };
11
+
12
+ type ResultData = {
13
+ ids: string[];
14
+ byId: Record<string, ExternalLink>;
15
+ meta: { total: number };
16
+ };
17
+ type ResultError = ErrorData['data']['error'];
18
+
19
+ export type FindExternalLinksHeaders = { 'x-auth-hc'?: string };
20
+ export type FindExternalLinksParams = {
21
+ filter?: { 'realty.id'?: string };
22
+ limits?: { page?: number; count?: number | 'all' };
23
+ };
24
+ export type FindExternalLinksData = AxiosResponse<ResultData>;
25
+ export type FindExternalLinksError = AxiosError<ResultError>;
26
+
27
+ export type FindExternalLinksConfig = {
28
+ baseURL?: string;
29
+ headers?: FindExternalLinksHeaders;
30
+ params: FindExternalLinksParams;
31
+ };
32
+
33
+ export function findExternalLinksRequest({
34
+ baseURL = 'https://publisher.homeapp.ru',
35
+ headers,
36
+ params,
37
+ }: FindExternalLinksConfig) {
38
+ return axios
39
+ .get('/api/crud/external-link', {
40
+ baseURL,
41
+ params,
42
+ paramsSerializer: params => qs.stringify(params, { arrayFormat: 'brackets' }),
43
+ headers: { Accept: 'application/json', ...headers },
44
+ transformResponse: [
45
+ ...(axios.defaults.transformResponse as AxiosTransformer[]),
46
+ (data: SuccessData | ErrorData): ResultData | ResultError => {
47
+ if (!data.success) return data.data.error;
48
+
49
+ const ids: ResultData['ids'] = [];
50
+ const byId: ResultData['byId'] = {};
51
+
52
+ data.data.forEach(entity => {
53
+ byId[entity.externalSite] = entity;
54
+ ids.push(entity.externalSite);
55
+ });
56
+
57
+ return { ids, byId, meta: { total: data.pageParams.length } };
58
+ },
59
+ ],
60
+ })
61
+ .then((res: FindExternalLinksData) => res)
62
+ .catch((err: FindExternalLinksError) => {
63
+ throw err;
64
+ });
65
+ }
@@ -0,0 +1,71 @@
1
+ import axios, { AxiosResponse, AxiosError, AxiosTransformer } from 'axios';
2
+ import qs from 'qs';
3
+
4
+ export type StatisticRow = {
5
+ createdAt: string;
6
+ apartmentId?: number;
7
+ likes?: { value: number; delta: number };
8
+ listingViews?: { value: number; delta: number };
9
+ phoneViews?: { value: number; delta: number };
10
+ source: string;
11
+ views: { value: number; delta: number };
12
+ };
13
+ type SuccessData = { success: true; data: Array<StatisticRow>; pageParams: { page?: number; length: number } };
14
+ type ErrorData = { success?: false; data: { error: string } };
15
+
16
+ type ResultData = { ids: string[]; byId: Record<string, StatisticRow>; meta: { total: number } };
17
+ type ResultError = ErrorData['data']['error'];
18
+
19
+ export type FindStatisticRowHeaders = { 'x-auth-hc'?: string };
20
+ export type FindStatisticRowParams = {
21
+ filter?: {
22
+ 'realty.id'?: number;
23
+ createdAt?: {
24
+ from?: string;
25
+ to?: string;
26
+ };
27
+ };
28
+ limits?: { page?: number; count?: number | 'all' };
29
+ };
30
+ export type FindStatisticRowData = AxiosResponse<ResultData>;
31
+ export type FindStatisticRowError = AxiosError<ResultError>;
32
+
33
+ export type FindStatisticRowConfig = {
34
+ baseURL?: string;
35
+ headers?: FindStatisticRowHeaders;
36
+ params: FindStatisticRowParams;
37
+ };
38
+
39
+ export function findStatisticRowRequest({
40
+ baseURL = 'https://publisher.homeapp.ru',
41
+ headers,
42
+ params,
43
+ }: FindStatisticRowConfig) {
44
+ return axios
45
+ .get('/api/crud/statistic-row', {
46
+ baseURL,
47
+ params,
48
+ paramsSerializer: params => qs.stringify(params, { arrayFormat: 'brackets' }),
49
+ headers: { Accept: 'application/json', ...headers },
50
+ transformResponse: [
51
+ ...(axios.defaults.transformResponse as AxiosTransformer[]),
52
+ (data: SuccessData | ErrorData): ResultData | ResultError => {
53
+ if (!data.success) return data.data.error;
54
+
55
+ const ids: ResultData['ids'] = [];
56
+ const byId: ResultData['byId'] = {};
57
+
58
+ data.data.forEach(entity => {
59
+ byId[entity.source] = entity;
60
+ ids.push(entity.source);
61
+ });
62
+
63
+ return { ids, byId, meta: { total: data.pageParams.length } };
64
+ },
65
+ ],
66
+ })
67
+ .then((res: FindStatisticRowData) => res)
68
+ .catch((err: FindStatisticRowError) => {
69
+ throw err;
70
+ });
71
+ }
@@ -2,7 +2,8 @@ export * from './findActualEventsRow';
2
2
  export * from './findNewBuildings';
3
3
  export * from './findPlannedEventsRow';
4
4
  export * from './findScoring';
5
- export * from './getExternalLinks';
5
+ export * from './findExternalLinks';
6
+ export * from './findStatisticRow';
6
7
  export * from './getFirstPublishedAt';
7
8
  export * from './getPublishedDays';
8
9
  export * from './sendResume';
@@ -15,8 +15,12 @@ export class Api {
15
15
  return api.findNewBuildingsRequest({ params, headers, baseURL: this.baseURL });
16
16
  };
17
17
 
18
- getExternalLinks = (params: api.GetExternalLinksParams, headers: api.GetExternalLinksHeaders) => {
19
- return api.getExternalLinksRequest({ params, headers, baseURL: this.baseURL });
18
+ findExternalLinks = (params: api.FindExternalLinksParams, headers?: api.FindExternalLinksHeaders) => {
19
+ return api.findExternalLinksRequest({ params, headers, baseURL: this.baseURL });
20
+ };
21
+
22
+ findStatisticRow = (params: api.FindStatisticRowParams, headers?: api.FindStatisticRowHeaders) => {
23
+ return api.findStatisticRowRequest({ params, headers, baseURL: this.baseURL });
20
24
  };
21
25
 
22
26
  findActualEventsRow = (params: api.FindActualEventsRowParams, headers: api.FindActualEventsRowHeaders) => {
@@ -1,32 +0,0 @@
1
- export declare type GetExternalLinksHeaders = {
2
- 'x-auth-hc': string;
3
- };
4
- export declare type GetExternalLinksParams = {
5
- filter?: {
6
- 'apartment.id'?: number;
7
- };
8
- limits?: {
9
- page: number;
10
- count: number;
11
- };
12
- };
13
- export declare type GetExternalLinksData = {
14
- data: {
15
- ids: number[];
16
- byId: Record<string, {
17
- apartmentId: number;
18
- url: string;
19
- externalSite: string;
20
- }>;
21
- };
22
- };
23
- export declare type GetExternalLinksError = {
24
- status: number;
25
- data: string;
26
- };
27
- export declare type GetExternalLinksConfig = {
28
- baseURL?: string;
29
- headers: GetExternalLinksHeaders;
30
- params: GetExternalLinksParams;
31
- };
32
- export declare function getExternalLinksRequest({ baseURL, headers, params, }: GetExternalLinksConfig): Promise<GetExternalLinksData>;