@zauru-sdk/services 2.0.177 → 2.0.178
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,7 +1,7 @@
|
|
|
1
1
|
import { arrayToObject, convertToFormData, handlePossibleAxiosErrors, } from "@zauru-sdk/common";
|
|
2
2
|
import { getGraphQLAPIHeaders } from "../common.js";
|
|
3
3
|
import { httpGraphQLAPI } from "./httpGraphQL.js";
|
|
4
|
-
import { getAllFormsStringQuery, getFormByNameStringQuery, getFormSubmissionByIdStringQuery, getFormsByDocumentTypeStringQuery, getFormsStringQuery, getInvoiceFormSubmissionsByAgencyIdStringQuery, getInvoiceFormSubmissionsByInvoiceIdStringQuery, getLastInvoiceFormSubmissionStringQuery, getMyCaseFormSubmissionsStringQuery, } from "@zauru-sdk/graphql";
|
|
4
|
+
import { getAllFormsStringQuery, getCaseFormSubmissionsByCaseIdStringQuery, getFormByNameStringQuery, getFormSubmissionByIdStringQuery, getFormsByDocumentTypeStringQuery, getFormsStringQuery, getInvoiceFormSubmissionsByAgencyIdStringQuery, getInvoiceFormSubmissionsByInvoiceIdStringQuery, getLastInvoiceFormSubmissionStringQuery, getMyCaseFormSubmissionsStringQuery, } from "@zauru-sdk/graphql";
|
|
5
5
|
import { httpZauru } from "./httpZauru.js";
|
|
6
6
|
/**
|
|
7
7
|
* getForms
|
|
@@ -231,11 +231,10 @@ export async function getLastInvoiceFormSubmission(session, filters = {}) {
|
|
|
231
231
|
export async function getInvoiceFormSubmissionsByInvoiceId(headersZauru, session, invoice_id, withFiles = false, filters = {}) {
|
|
232
232
|
return handlePossibleAxiosErrors(async () => {
|
|
233
233
|
const headers = await getGraphQLAPIHeaders(session);
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}, { headers });
|
|
234
|
+
const query = getInvoiceFormSubmissionsByInvoiceIdStringQuery(Number(invoice_id), {
|
|
235
|
+
formZid: filters?.formZid,
|
|
236
|
+
});
|
|
237
|
+
const response = await httpGraphQLAPI.post("", { query }, { headers });
|
|
239
238
|
if (response.data.errors) {
|
|
240
239
|
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
241
240
|
}
|
|
@@ -277,6 +276,57 @@ export async function getInvoiceFormSubmissionsByInvoiceId(headersZauru, session
|
|
|
277
276
|
return latestVersionRecords;
|
|
278
277
|
});
|
|
279
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* getCaseFormSubmissionsByCaseId
|
|
281
|
+
*/
|
|
282
|
+
export async function getCaseFormSubmissionsByCaseId(headersZauru, session, case_id, withFiles = false, filters = {}) {
|
|
283
|
+
return handlePossibleAxiosErrors(async () => {
|
|
284
|
+
const headers = await getGraphQLAPIHeaders(session);
|
|
285
|
+
const query = getCaseFormSubmissionsByCaseIdStringQuery(Number(case_id), {
|
|
286
|
+
formZid: filters?.formZid,
|
|
287
|
+
});
|
|
288
|
+
const response = await httpGraphQLAPI.post("", { query }, { headers });
|
|
289
|
+
if (response.data.errors) {
|
|
290
|
+
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
291
|
+
}
|
|
292
|
+
let registers = response?.data?.data?.submission_cases;
|
|
293
|
+
if (withFiles) {
|
|
294
|
+
registers = await Promise.all(registers.map(async (register) => {
|
|
295
|
+
try {
|
|
296
|
+
const responseZauru = await httpZauru.get(`/settings/forms/form_submissions/${register.settings_form_submission.id}.json`, {
|
|
297
|
+
headers: headersZauru,
|
|
298
|
+
});
|
|
299
|
+
register.settings_form_submission.settings_form_submission_values =
|
|
300
|
+
register.settings_form_submission.settings_form_submission_values.map((x) => {
|
|
301
|
+
if (x.settings_form_field.field_type === "image" ||
|
|
302
|
+
x.settings_form_field.field_type === "file" ||
|
|
303
|
+
x.settings_form_field.field_type === "pdf") {
|
|
304
|
+
x.value = responseZauru.data[x.settings_form_field.print_var_name]
|
|
305
|
+
?.toString()
|
|
306
|
+
.replace(/\\u0026/g, "&");
|
|
307
|
+
}
|
|
308
|
+
return x;
|
|
309
|
+
});
|
|
310
|
+
return register;
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
console.error(`Error al obtener el archivo del formulario ${register.settings_form_submission.id}`, error);
|
|
314
|
+
return register;
|
|
315
|
+
}
|
|
316
|
+
}));
|
|
317
|
+
}
|
|
318
|
+
// Filtrar los registros para obtener sólo los de la versión más alta.
|
|
319
|
+
const groupedByVersion = registers.reduce((acc, record) => {
|
|
320
|
+
const zid = record.settings_form_submission.zid;
|
|
321
|
+
if (!acc[zid]) {
|
|
322
|
+
acc[zid] = record;
|
|
323
|
+
}
|
|
324
|
+
return acc;
|
|
325
|
+
}, {});
|
|
326
|
+
const latestVersionRecords = Object.values(groupedByVersion).reverse();
|
|
327
|
+
return latestVersionRecords;
|
|
328
|
+
});
|
|
329
|
+
}
|
|
280
330
|
export const getFormSubmissionAPIZauru = async (headers, id) => {
|
|
281
331
|
return handlePossibleAxiosErrors(async () => {
|
|
282
332
|
const responseZauru = await httpZauru.get(`/settings/forms/form_submissions/${id}.json`, { headers });
|
|
@@ -63,6 +63,12 @@ export declare function getLastInvoiceFormSubmission(session: Session, filters?:
|
|
|
63
63
|
export declare function getInvoiceFormSubmissionsByInvoiceId(headersZauru: any, session: Session, invoice_id: string, withFiles?: boolean, filters?: {
|
|
64
64
|
formZid?: number;
|
|
65
65
|
}): Promise<AxiosUtilsResponse<SubmissionInvoicesGraphQL[]>>;
|
|
66
|
+
/**
|
|
67
|
+
* getCaseFormSubmissionsByCaseId
|
|
68
|
+
*/
|
|
69
|
+
export declare function getCaseFormSubmissionsByCaseId(headersZauru: any, session: Session, case_id: string, withFiles?: boolean, filters?: {
|
|
70
|
+
formZid?: number;
|
|
71
|
+
}): Promise<AxiosUtilsResponse<SubmissionCasesGraphQL[]>>;
|
|
66
72
|
export declare const getFormSubmissionAPIZauru: (headers: any, id: number | string) => Promise<AxiosUtilsResponse<any>>;
|
|
67
73
|
/**
|
|
68
74
|
* createForm
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/services",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.178",
|
|
4
4
|
"description": "Servicios de consulta a Zauru",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"@remix-run/node": "^2.8.1",
|
|
27
27
|
"@zauru-sdk/common": "^2.0.177",
|
|
28
28
|
"@zauru-sdk/config": "^2.0.100",
|
|
29
|
-
"@zauru-sdk/graphql": "^2.0.
|
|
29
|
+
"@zauru-sdk/graphql": "^2.0.178",
|
|
30
30
|
"@zauru-sdk/types": "^2.0.177",
|
|
31
31
|
"axios": "^1.6.7",
|
|
32
32
|
"chalk": "5.3.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "de1597493fe293d152d099f9e687208df163c938"
|
|
35
35
|
}
|