@zauru-sdk/utils 2.0.113 → 2.0.115

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.
@@ -2,19 +2,28 @@ import { arrayToObject, handlePossibleAxiosErrors } from "@zauru-sdk/common";
2
2
  import { createFormSubmission, getInvoiceFormSubmissionsByInvoiceId, getLastInvoiceFormSubmission, getVariablesByName, } from "@zauru-sdk/services";
3
3
  export function transformFormSubmitObject(input) {
4
4
  const form_submission_values = [];
5
+ const isJsonArray = (value) => {
6
+ try {
7
+ const parsed = JSON.parse(value);
8
+ return Array.isArray(parsed);
9
+ }
10
+ catch (e) {
11
+ return false;
12
+ }
13
+ };
5
14
  // Itera sobre las propiedades del objeto
6
15
  for (const key in input) {
7
16
  // Utiliza una expresión regular para detectar claves que coinciden con el patrón 'word_number'
8
17
  const match = key.match(/^(.+?)_(\d+)$/);
9
- if (match) {
18
+ if (match && !key.includes("deleted")) {
10
19
  const [, , form_field_id] = match;
11
20
  let newObj = {
12
21
  form_field_id,
13
22
  groups_path: "[]",
23
+ value: "",
14
24
  };
15
25
  if (input[key] instanceof File) {
16
26
  const fileType = input[key].type;
17
- newObj["value"] = "";
18
27
  if (input[key]?.size > 0) {
19
28
  // Verifica si el archivo es una imagen
20
29
  if (fileType.startsWith("image/")) {
@@ -30,6 +39,27 @@ export function transformFormSubmitObject(input) {
30
39
  }
31
40
  }
32
41
  }
42
+ else if (isJsonArray(input[key])) {
43
+ const tableJsonArray = JSON.parse(input[key]);
44
+ if (tableJsonArray.length > 0) {
45
+ const form_table_values_attributes = [];
46
+ tableJsonArray.forEach((x, index) => {
47
+ for (const keyTable in x) {
48
+ const matchTableId = keyTable.match(/^(.+?)_(\d+)$/);
49
+ if (matchTableId) {
50
+ const [, , table_header_id] = matchTableId;
51
+ form_table_values_attributes.push({
52
+ table_header_id: Number(table_header_id),
53
+ value: x[keyTable],
54
+ row_or_column_number: index + 1,
55
+ });
56
+ }
57
+ }
58
+ });
59
+ newObj["form_table_values_attributes"] = arrayToObject(form_table_values_attributes);
60
+ delete newObj.value;
61
+ }
62
+ }
33
63
  else {
34
64
  newObj["value"] = input[key];
35
65
  }
@@ -143,7 +173,7 @@ export const getLastMuestra = (headers, session) => {
143
173
  export const getMuestrasByInvoiceId = (headers, session, invoice_id) => {
144
174
  return handlePossibleAxiosErrors(async () => {
145
175
  const { lab_muestras_form_zid } = await getVariablesByName(headers, session, ["lab_muestras_form_zid"]);
146
- const response = await getInvoiceFormSubmissionsByInvoiceId(session, invoice_id, { formZid: Number(lab_muestras_form_zid) });
176
+ const response = await getInvoiceFormSubmissionsByInvoiceId(headers, session, invoice_id, false, { formZid: Number(lab_muestras_form_zid) });
147
177
  if (response.error || !response.data) {
148
178
  throw new Error(`Ocurrió un error al intentar obtener las muestras de la remisión: ${response.userMsg}`);
149
179
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zauru-sdk/utils",
3
- "version": "2.0.113",
3
+ "version": "2.0.115",
4
4
  "description": "Utilidades, parseo de request y demás para desarrollo de webapps de Zauru",
5
5
  "main": "./dist/esm/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -27,8 +27,8 @@
27
27
  "@zauru-sdk/common": "^2.0.109",
28
28
  "@zauru-sdk/config": "^2.0.100",
29
29
  "@zauru-sdk/graphql": "^2.0.113",
30
- "@zauru-sdk/services": "^2.0.113",
30
+ "@zauru-sdk/services": "^2.0.115",
31
31
  "@zauru-sdk/types": "^2.0.109"
32
32
  },
33
- "gitHead": "0251ee194f152e5ddbf5e35bea38d050b2309f31"
33
+ "gitHead": "fe1283bd81104c388ac747ce55c6b6935bd850e3"
34
34
  }