@hapl/api-queries 0.1.128 → 0.1.131

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,38 @@
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
+ query?: string;
18
+ id?: number | number[];
19
+ status?: CallTaskStatus | CallTaskStatus[];
20
+ };
21
+ limits?: {
22
+ page?: number;
23
+ count: number | 'all';
24
+ };
25
+ sorting?: {
26
+ direction: 'asc' | 'desc';
27
+ type: 'createdAt' | 'id';
28
+ };
29
+ };
30
+ export declare type FindCallTasksData = AxiosResponse<ResultData>;
31
+ export declare type FindCallTasksError = AxiosError<ResultError>;
32
+ export declare type FindCallTasksConfig = {
33
+ baseURL?: string;
34
+ headers: FindCallTasksHeaders;
35
+ params: FindCallTasksParams;
36
+ };
37
+ export declare function findCallTasksRequest({ baseURL, headers, params }: FindCallTasksConfig): Promise<FindCallTasksData>;
38
+ 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';
@@ -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>;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.1.128",
2
+ "version": "0.1.131",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -0,0 +1,61 @@
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
+ query?: string;
17
+ id?: number | number[];
18
+ status?: CallTaskStatus | CallTaskStatus[];
19
+ };
20
+ limits?: { page?: number; count: number | 'all' };
21
+ sorting?: { direction: 'asc' | 'desc'; type: 'createdAt' | 'id' };
22
+ };
23
+ export type FindCallTasksData = AxiosResponse<ResultData>;
24
+ export type FindCallTasksError = AxiosError<ResultError>;
25
+ export type FindCallTasksConfig = {
26
+ baseURL?: string;
27
+ headers: FindCallTasksHeaders;
28
+ params: FindCallTasksParams;
29
+ };
30
+
31
+ export function findCallTasksRequest({ baseURL = 'https://clients.homeapp.ru', headers, params }: FindCallTasksConfig) {
32
+ return axios
33
+ .get('/api/calls/task', {
34
+ baseURL,
35
+ params,
36
+ paramsSerializer: params => qs.stringify(params, { arrayFormat: 'brackets' }),
37
+ headers: { Accept: 'application/json', 'Content-Type': 'application/json', ...headers },
38
+ transformResponse: [
39
+ ...(axios.defaults.transformResponse as AxiosTransformer[]),
40
+ (data: SuccessData | ErrorData): ResultData | ResultError => {
41
+ if (data.success) {
42
+ const ids: ResultData['ids'] = [];
43
+ const byId: ResultData['byId'] = {};
44
+
45
+ data.data.forEach(entity => {
46
+ byId[entity.id] = entity;
47
+ ids.push(entity.id);
48
+ });
49
+
50
+ return { ids, byId, meta: { total: data.pageParams.length } };
51
+ }
52
+
53
+ return data.data.error || data.data.message;
54
+ },
55
+ ],
56
+ })
57
+ .then((res: FindCallTasksData) => res)
58
+ .catch((err: FindCallTasksError) => {
59
+ throw err;
60
+ });
61
+ }
@@ -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';
@@ -25,7 +25,7 @@ export function depublishServiceRequest({
25
25
  headers,
26
26
  }: DepublishServiceRequestConfig) {
27
27
  return axios
28
- .patch(`/api/service-request/depublish/${urlParams.id}`, body, {
28
+ .post(`/api/service-request/depublish/${urlParams.id}`, body, {
29
29
  baseURL,
30
30
  headers: { Accept: 'application/json', 'Content-Type': 'application/json', ...headers },
31
31
  transformResponse: [
@@ -22,7 +22,7 @@ export function publishServiceRequest({
22
22
  headers,
23
23
  }: PublishServiceRequestConfig) {
24
24
  return axios
25
- .patch(
25
+ .post(
26
26
  `/api/service-request/publish/${urlParams.id}`,
27
27
  {},
28
28
  {
@@ -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 = (