@zauru-sdk/services 2.0.168 → 2.0.170
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.
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
1
|
+
import { arrayToObject, handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
2
2
|
import { getGraphQLAPIHeaders } from "../common.js";
|
|
3
3
|
import { httpGraphQLAPI } from "./httpGraphQL.js";
|
|
4
|
-
import {
|
|
4
|
+
import { getCasesStringQuery } from "@zauru-sdk/graphql";
|
|
5
|
+
import { httpZauru } from "./httpZauru.js";
|
|
5
6
|
/**
|
|
6
7
|
* getCasesByResponsibleId
|
|
7
8
|
*/
|
|
8
|
-
export async function getCasesByResponsibleId(session,
|
|
9
|
+
export async function getCasesByResponsibleId(session, filters) {
|
|
9
10
|
return handlePossibleAxiosErrors(async () => {
|
|
10
11
|
const headers = await getGraphQLAPIHeaders(session);
|
|
12
|
+
const initialFilters = {
|
|
13
|
+
...(filters ? filters : {}),
|
|
14
|
+
};
|
|
15
|
+
const query = getCasesStringQuery(initialFilters);
|
|
11
16
|
const response = await httpGraphQLAPI.post("", {
|
|
12
|
-
query
|
|
17
|
+
query,
|
|
13
18
|
}, { headers });
|
|
14
19
|
if (response.data.errors) {
|
|
15
20
|
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
@@ -18,3 +23,63 @@ export async function getCasesByResponsibleId(session, responsible_id, wheres =
|
|
|
18
23
|
return registers;
|
|
19
24
|
});
|
|
20
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* createCase
|
|
28
|
+
* @param headers
|
|
29
|
+
* @param body
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
export async function createCase(headers, body) {
|
|
33
|
+
return handlePossibleAxiosErrors(async () => {
|
|
34
|
+
const sendBody = {
|
|
35
|
+
...body,
|
|
36
|
+
case_supplies_attributes: arrayToObject(body.case_supplies),
|
|
37
|
+
tag_ids: ["", ...(body.taggings?.map((x) => x.tag_id) ?? [])],
|
|
38
|
+
};
|
|
39
|
+
if (sendBody.deleted_case_supplies)
|
|
40
|
+
delete sendBody.deleted_case_supplies;
|
|
41
|
+
if (sendBody.__rvfInternalFormId)
|
|
42
|
+
delete sendBody.__rvfInternalFormId;
|
|
43
|
+
if (sendBody.case_supplies)
|
|
44
|
+
delete sendBody.case_supplies;
|
|
45
|
+
if (sendBody.taggings)
|
|
46
|
+
delete sendBody.taggings;
|
|
47
|
+
const response = await httpZauru.post(`/support/cases.json`, { case: sendBody }, { headers });
|
|
48
|
+
return response.data;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* updateCase
|
|
53
|
+
* @param headers
|
|
54
|
+
* @param body
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
export async function updateCase(headers, body) {
|
|
58
|
+
return handlePossibleAxiosErrors(async () => {
|
|
59
|
+
const sendBody = {
|
|
60
|
+
...body,
|
|
61
|
+
case_supplies_attributes: arrayToObject(body.case_supplies),
|
|
62
|
+
};
|
|
63
|
+
if (sendBody.deleted_case_supplies)
|
|
64
|
+
delete sendBody.deleted_case_supplies;
|
|
65
|
+
if (sendBody.__rvfInternalFormId)
|
|
66
|
+
delete sendBody.__rvfInternalFormId;
|
|
67
|
+
if (sendBody.case_supplies)
|
|
68
|
+
delete sendBody.case_supplies;
|
|
69
|
+
const response = await httpZauru.patch(`/support/cases/${body.id}.json`, { case: sendBody }, { headers });
|
|
70
|
+
return response.data;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* deleteCase
|
|
75
|
+
* @param headers
|
|
76
|
+
* @param body
|
|
77
|
+
*/
|
|
78
|
+
export async function deleteCase(headers, id) {
|
|
79
|
+
return handlePossibleAxiosErrors(async () => {
|
|
80
|
+
await httpZauru.delete(`/support/cases/${id}.json`, {
|
|
81
|
+
headers,
|
|
82
|
+
});
|
|
83
|
+
return true;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
@@ -3,4 +3,28 @@ import { AxiosUtilsResponse, CaseGraphQL } from "@zauru-sdk/types";
|
|
|
3
3
|
/**
|
|
4
4
|
* getCasesByResponsibleId
|
|
5
5
|
*/
|
|
6
|
-
export declare function getCasesByResponsibleId(session: Session,
|
|
6
|
+
export declare function getCasesByResponsibleId(session: Session, filters?: {
|
|
7
|
+
responsible_id?: number;
|
|
8
|
+
closed?: boolean;
|
|
9
|
+
client_id?: number;
|
|
10
|
+
}): Promise<AxiosUtilsResponse<CaseGraphQL[]>>;
|
|
11
|
+
/**
|
|
12
|
+
* createCase
|
|
13
|
+
* @param headers
|
|
14
|
+
* @param body
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export declare function createCase(headers: any, body: Partial<CaseGraphQL>): Promise<AxiosUtilsResponse<CaseGraphQL>>;
|
|
18
|
+
/**
|
|
19
|
+
* updateCase
|
|
20
|
+
* @param headers
|
|
21
|
+
* @param body
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
export declare function updateCase(headers: any, body: Partial<CaseGraphQL>): Promise<AxiosUtilsResponse<CaseGraphQL>>;
|
|
25
|
+
/**
|
|
26
|
+
* deleteCase
|
|
27
|
+
* @param headers
|
|
28
|
+
* @param body
|
|
29
|
+
*/
|
|
30
|
+
export declare function deleteCase(headers: any, id: string | number): Promise<AxiosUtilsResponse<boolean>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/services",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.170",
|
|
4
4
|
"description": "Servicios de consulta a Zauru",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@remix-run/node": "^2.8.1",
|
|
27
|
-
"@zauru-sdk/common": "^2.0.
|
|
27
|
+
"@zauru-sdk/common": "^2.0.170",
|
|
28
28
|
"@zauru-sdk/config": "^2.0.100",
|
|
29
|
-
"@zauru-sdk/graphql": "^2.0.
|
|
30
|
-
"@zauru-sdk/types": "^2.0.
|
|
29
|
+
"@zauru-sdk/graphql": "^2.0.169",
|
|
30
|
+
"@zauru-sdk/types": "^2.0.170",
|
|
31
31
|
"axios": "^1.6.7",
|
|
32
32
|
"chalk": "5.3.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "864ff8a1835aacaa8f7487bb2cfa6f38e6ba3367"
|
|
35
35
|
}
|