@zauru-sdk/utils 2.0.113 → 2.0.114
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.
- package/dist/esm/zauru/form.utils.js +32 -2
- package/package.json +2 -2
|
@@ -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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/utils",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.114",
|
|
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",
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"@zauru-sdk/services": "^2.0.113",
|
|
31
31
|
"@zauru-sdk/types": "^2.0.109"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "8d4c13cbf928873304a52c5870c6ccba7cabbcc2"
|
|
34
34
|
}
|