@zauru-sdk/services 1.0.49 → 1.0.52
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/cjs/common.js +235 -0
- package/dist/cjs/index.js +50 -0
- package/dist/cjs/sessions/sessions.js +18 -0
- package/dist/cjs/sessions/upstash.js +59 -0
- package/dist/cjs/zauru/httpGraphQL.js +42 -0
- package/dist/cjs/zauru/httpOauth.js +42 -0
- package/dist/cjs/zauru/httpZauru.js +42 -0
- package/dist/cjs/zauru/zauru-agencies.js +27 -0
- package/dist/cjs/zauru/zauru-automatic-numbers.js +28 -0
- package/dist/cjs/zauru/zauru-bookings.js +90 -0
- package/dist/cjs/zauru/zauru-bundles.js +104 -0
- package/dist/cjs/zauru/zauru-cases.js +30 -0
- package/dist/cjs/zauru/zauru-consolidated.js +81 -0
- package/dist/cjs/zauru/zauru-currencies.js +27 -0
- package/dist/cjs/zauru/zauru-deliveries.js +53 -0
- package/dist/cjs/zauru/zauru-discharges.js +55 -0
- package/dist/cjs/zauru/zauru-employees.js +30 -0
- package/dist/cjs/zauru/zauru-forms.js +363 -0
- package/dist/cjs/zauru/zauru-invoices.js +104 -0
- package/dist/cjs/zauru/zauru-items.js +293 -0
- package/dist/cjs/zauru/zauru-lote-record.js +33 -0
- package/dist/cjs/zauru/zauru-lotes.js +312 -0
- package/dist/cjs/zauru/zauru-motivos-rechazo.js +57 -0
- package/dist/cjs/zauru/zauru-payees.js +247 -0
- package/dist/cjs/zauru/zauru-payment-terms.js +75 -0
- package/dist/cjs/zauru/zauru-price-lists.js +49 -0
- package/dist/cjs/zauru/zauru-profiles.js +80 -0
- package/dist/cjs/zauru/zauru-purchase-orders.js +438 -0
- package/dist/cjs/zauru/zauru-receptions.js +104 -0
- package/dist/cjs/zauru/zauru-shipments.js +62 -0
- package/dist/cjs/zauru/zauru-suggested-prices.js +94 -0
- package/dist/cjs/zauru/zauru-tags.js +20 -0
- package/dist/cjs/zauru/zauru-templates.js +22 -0
- package/dist/cjs/zauru/zauru-variables.js +56 -0
- package/dist/cjs/zauru/zauru-web-app-tables.js +167 -0
- package/package.json +12 -9
- package/CHANGELOG.md +0 -232
- package/src/common.ts +0 -343
- package/src/index.ts +0 -37
- package/src/sessions/sessions.ts +0 -17
- package/src/sessions/upstash.ts +0 -55
- package/src/zauru/httpGraphQL.ts +0 -55
- package/src/zauru/httpOauth.ts +0 -55
- package/src/zauru/httpZauru.ts +0 -56
- package/src/zauru/zauru-agencies.ts +0 -32
- package/src/zauru/zauru-automatic-numbers.ts +0 -35
- package/src/zauru/zauru-bookings.ts +0 -134
- package/src/zauru/zauru-bundles.ts +0 -157
- package/src/zauru/zauru-cases.ts +0 -44
- package/src/zauru/zauru-consolidated.ts +0 -129
- package/src/zauru/zauru-currencies.ts +0 -39
- package/src/zauru/zauru-deliveries.ts +0 -70
- package/src/zauru/zauru-discharges.ts +0 -90
- package/src/zauru/zauru-employees.ts +0 -43
- package/src/zauru/zauru-forms.ts +0 -618
- package/src/zauru/zauru-invoices.ts +0 -142
- package/src/zauru/zauru-items.ts +0 -481
- package/src/zauru/zauru-lote-record.ts +0 -77
- package/src/zauru/zauru-lotes.ts +0 -484
- package/src/zauru/zauru-motivos-rechazo.ts +0 -121
- package/src/zauru/zauru-payees.ts +0 -402
- package/src/zauru/zauru-payment-terms.ts +0 -126
- package/src/zauru/zauru-price-lists.ts +0 -68
- package/src/zauru/zauru-profiles.ts +0 -106
- package/src/zauru/zauru-purchase-orders.ts +0 -701
- package/src/zauru/zauru-receptions.ts +0 -148
- package/src/zauru/zauru-shipments.ts +0 -88
- package/src/zauru/zauru-suggested-prices.ts +0 -137
- package/src/zauru/zauru-tags.ts +0 -22
- package/src/zauru/zauru-templates.ts +0 -24
- package/src/zauru/zauru-variables.ts +0 -67
- package/src/zauru/zauru-web-app-tables.ts +0 -256
- package/tsconfig.json +0 -24
- /package/dist/{common.js → esm/common.js} +0 -0
- /package/dist/{index.js → esm/index.js} +0 -0
- /package/dist/{sessions → esm/sessions}/sessions.js +0 -0
- /package/dist/{sessions → esm/sessions}/upstash.js +0 -0
- /package/dist/{zauru → esm/zauru}/httpGraphQL.js +0 -0
- /package/dist/{zauru → esm/zauru}/httpOauth.js +0 -0
- /package/dist/{zauru → esm/zauru}/httpZauru.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-agencies.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-automatic-numbers.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-bookings.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-bundles.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-cases.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-consolidated.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-currencies.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-deliveries.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-discharges.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-employees.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-forms.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-invoices.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-items.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-lote-record.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-lotes.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-motivos-rechazo.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-payees.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-payment-terms.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-price-lists.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-profiles.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-purchase-orders.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-receptions.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-shipments.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-suggested-prices.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-tags.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-templates.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-variables.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-web-app-tables.js +0 -0
package/src/zauru/zauru-forms.ts
DELETED
|
@@ -1,618 +0,0 @@
|
|
|
1
|
-
import type { Session } from "@remix-run/node";
|
|
2
|
-
import {
|
|
3
|
-
arrayToObject,
|
|
4
|
-
convertToFormData,
|
|
5
|
-
handlePossibleAxiosErrors,
|
|
6
|
-
} from "@zauru-sdk/common";
|
|
7
|
-
import {
|
|
8
|
-
AxiosUtilsResponse,
|
|
9
|
-
FormDocumentType,
|
|
10
|
-
FormGraphQL,
|
|
11
|
-
FormSubmissionGraphQL,
|
|
12
|
-
SubmissionCasesGraphQL,
|
|
13
|
-
SubmissionInvoicesGraphQL,
|
|
14
|
-
} from "@zauru-sdk/types";
|
|
15
|
-
import { getGraphQLAPIHeaders } from "../common.js";
|
|
16
|
-
import httpGraphQLAPI from "./httpGraphQL.js";
|
|
17
|
-
import {
|
|
18
|
-
getFormByNameStringQuery,
|
|
19
|
-
getFormSubmissionByIdStringQuery,
|
|
20
|
-
getFormsByDocumentTypeStringQuery,
|
|
21
|
-
getFormsStringQuery,
|
|
22
|
-
getInvoiceFormSubmissionsByAgencyIdStringQuery,
|
|
23
|
-
getInvoiceFormSubmissionsByInvoiceIdStringQuery,
|
|
24
|
-
getLastInvoiceFormSubmissionStringQuery,
|
|
25
|
-
getMyCaseFormSubmissionsStringQuery,
|
|
26
|
-
} from "@zauru-sdk/graphql";
|
|
27
|
-
import httpZauru from "./httpZauru.js";
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* getForms
|
|
31
|
-
*/
|
|
32
|
-
export async function getForms(
|
|
33
|
-
session: Session
|
|
34
|
-
): Promise<AxiosUtilsResponse<FormGraphQL[]>> {
|
|
35
|
-
return handlePossibleAxiosErrors(async () => {
|
|
36
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
37
|
-
|
|
38
|
-
const response = await httpGraphQLAPI.post<{
|
|
39
|
-
data: { settings_forms: FormGraphQL[] };
|
|
40
|
-
errors?: {
|
|
41
|
-
message: string;
|
|
42
|
-
extensions: { path: string; code: string };
|
|
43
|
-
}[];
|
|
44
|
-
}>(
|
|
45
|
-
"",
|
|
46
|
-
{
|
|
47
|
-
query: getFormsStringQuery,
|
|
48
|
-
},
|
|
49
|
-
{ headers }
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
if (response.data.errors) {
|
|
53
|
-
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const registers = response?.data?.data?.settings_forms;
|
|
57
|
-
|
|
58
|
-
return registers;
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* getFormByName
|
|
64
|
-
*/
|
|
65
|
-
export async function getFormByName(
|
|
66
|
-
session: Session,
|
|
67
|
-
name: string
|
|
68
|
-
): Promise<AxiosUtilsResponse<FormGraphQL>> {
|
|
69
|
-
return handlePossibleAxiosErrors(async () => {
|
|
70
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
71
|
-
|
|
72
|
-
const response = await httpGraphQLAPI.post<{
|
|
73
|
-
data: { settings_forms: FormGraphQL[] };
|
|
74
|
-
errors?: {
|
|
75
|
-
message: string;
|
|
76
|
-
extensions: { path: string; code: string };
|
|
77
|
-
}[];
|
|
78
|
-
}>(
|
|
79
|
-
"",
|
|
80
|
-
{
|
|
81
|
-
query: getFormByNameStringQuery,
|
|
82
|
-
variables: {
|
|
83
|
-
name,
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
{ headers }
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
if (response.data.errors) {
|
|
90
|
-
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (!response?.data?.data?.settings_forms[0]) {
|
|
94
|
-
throw new Error(
|
|
95
|
-
`No se encontró ningún formulario con el nombre: ${name} asociado`
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const register = response?.data?.data?.settings_forms[0];
|
|
100
|
-
|
|
101
|
-
return register;
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* getFormsByDocumentType
|
|
107
|
-
*/
|
|
108
|
-
export async function getFormsByDocumentType(
|
|
109
|
-
session: Session,
|
|
110
|
-
document_type: FormDocumentType,
|
|
111
|
-
filters: { formZid?: number } = {}
|
|
112
|
-
): Promise<AxiosUtilsResponse<FormGraphQL[]>> {
|
|
113
|
-
return handlePossibleAxiosErrors(async () => {
|
|
114
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
115
|
-
|
|
116
|
-
const response = await httpGraphQLAPI.post<{
|
|
117
|
-
data: { settings_forms: FormGraphQL[] };
|
|
118
|
-
errors?: {
|
|
119
|
-
message: string;
|
|
120
|
-
extensions: { path: string; code: string };
|
|
121
|
-
}[];
|
|
122
|
-
}>(
|
|
123
|
-
"",
|
|
124
|
-
{
|
|
125
|
-
query: getFormsByDocumentTypeStringQuery(filters),
|
|
126
|
-
variables: {
|
|
127
|
-
document_type,
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
{ headers }
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
if (response.data.errors) {
|
|
134
|
-
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const registers = response?.data?.data?.settings_forms;
|
|
138
|
-
|
|
139
|
-
// Filtrar los registros para obtener sólo los de la versión más alta.
|
|
140
|
-
const groupedByVersion = registers.reduce((acc, record) => {
|
|
141
|
-
const zid = record.zid;
|
|
142
|
-
|
|
143
|
-
if (!acc[zid]) {
|
|
144
|
-
acc[zid] = record;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return acc;
|
|
148
|
-
}, {} as { [key: string]: FormGraphQL });
|
|
149
|
-
|
|
150
|
-
const latestVersionRecords = Object.values(groupedByVersion).reverse();
|
|
151
|
-
|
|
152
|
-
return latestVersionRecords;
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* getFormSubmissionById
|
|
158
|
-
*/
|
|
159
|
-
export async function getFormSubmissionById(
|
|
160
|
-
headersZauru: any,
|
|
161
|
-
session: Session,
|
|
162
|
-
id: string | number,
|
|
163
|
-
config: {
|
|
164
|
-
withFiles?: boolean;
|
|
165
|
-
} = { withFiles: false }
|
|
166
|
-
): Promise<AxiosUtilsResponse<FormSubmissionGraphQL>> {
|
|
167
|
-
return handlePossibleAxiosErrors(async () => {
|
|
168
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
169
|
-
|
|
170
|
-
const response = await httpGraphQLAPI.post<{
|
|
171
|
-
data: { settings_form_submissions: FormSubmissionGraphQL[] };
|
|
172
|
-
errors?: {
|
|
173
|
-
message: string;
|
|
174
|
-
extensions: { path: string; code: string };
|
|
175
|
-
}[];
|
|
176
|
-
}>(
|
|
177
|
-
"",
|
|
178
|
-
{
|
|
179
|
-
query: getFormSubmissionByIdStringQuery,
|
|
180
|
-
variables: {
|
|
181
|
-
formId: id,
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
{ headers }
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
if (response.data.errors) {
|
|
188
|
-
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (!response?.data?.data?.settings_form_submissions.length) {
|
|
192
|
-
throw new Error("No se encontró el form submission indicado.");
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const register = response?.data?.data?.settings_form_submissions[0];
|
|
196
|
-
|
|
197
|
-
if (config.withFiles) {
|
|
198
|
-
const responseZauru = await httpZauru.get(
|
|
199
|
-
`/settings/forms/form_submissions/${id}.json`,
|
|
200
|
-
{
|
|
201
|
-
headers: headersZauru,
|
|
202
|
-
}
|
|
203
|
-
);
|
|
204
|
-
|
|
205
|
-
register.settings_form_submission_values =
|
|
206
|
-
register.settings_form_submission_values.map((x) => {
|
|
207
|
-
if (
|
|
208
|
-
x.settings_form_field.field_type === "image" ||
|
|
209
|
-
x.settings_form_field.field_type === "file" ||
|
|
210
|
-
x.settings_form_field.field_type === "pdf"
|
|
211
|
-
) {
|
|
212
|
-
x.value = responseZauru.data[x.settings_form_field.print_var_name]
|
|
213
|
-
?.toString()
|
|
214
|
-
.replace(/\\u0026/g, "&");
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return x;
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return register;
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* getInvoiceFormSubmissionsByAgencyId
|
|
227
|
-
*/
|
|
228
|
-
export async function getInvoiceFormSubmissionsByAgencyId(
|
|
229
|
-
session: Session,
|
|
230
|
-
agency_id: string,
|
|
231
|
-
filters?: {
|
|
232
|
-
startDate?: string;
|
|
233
|
-
endDate?: string;
|
|
234
|
-
seller_id?: string | number;
|
|
235
|
-
payee_id_number_search?: string;
|
|
236
|
-
some_field_value?: string;
|
|
237
|
-
item_ids?: number[];
|
|
238
|
-
bundle_ids?: number[];
|
|
239
|
-
}
|
|
240
|
-
): Promise<AxiosUtilsResponse<SubmissionInvoicesGraphQL[]>> {
|
|
241
|
-
return handlePossibleAxiosErrors(async () => {
|
|
242
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
243
|
-
|
|
244
|
-
const queryBuilded = getInvoiceFormSubmissionsByAgencyIdStringQuery({
|
|
245
|
-
seller_id: filters?.seller_id,
|
|
246
|
-
payee_id_number_search: filters?.payee_id_number_search,
|
|
247
|
-
//some_field_value: filters?.some_field_value, //Este filtro ahora lo hago abajo, con código, porque al hacerlo así antes,
|
|
248
|
-
//no funcionaba para cuando se cambiaba un campo, por ejemplo, tengo campo1 con "blabla", si lo cambiaba a campo1 = "bleble",
|
|
249
|
-
//ese campo1 con "blabla" ya iba a ser la versión vieja, pero si buscaba por ese blabla, si me iba a seguir apareciendo.
|
|
250
|
-
bundle_ids: filters?.bundle_ids,
|
|
251
|
-
item_ids: filters?.item_ids,
|
|
252
|
-
startDate: filters?.startDate,
|
|
253
|
-
endDate: filters?.endDate,
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
const response = await httpGraphQLAPI.post<{
|
|
257
|
-
data: { submission_invoices: SubmissionInvoicesGraphQL[] };
|
|
258
|
-
errors?: {
|
|
259
|
-
message: string;
|
|
260
|
-
extensions: { path: string; code: string };
|
|
261
|
-
}[];
|
|
262
|
-
}>(
|
|
263
|
-
"",
|
|
264
|
-
{
|
|
265
|
-
query: queryBuilded,
|
|
266
|
-
variables: {
|
|
267
|
-
agency_id,
|
|
268
|
-
},
|
|
269
|
-
},
|
|
270
|
-
{ headers }
|
|
271
|
-
);
|
|
272
|
-
|
|
273
|
-
if (response.data.errors) {
|
|
274
|
-
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
const registers = response?.data?.data?.submission_invoices;
|
|
278
|
-
|
|
279
|
-
// Filtrar los registros para obtener sólo los de la versión más alta.
|
|
280
|
-
const groupedByVersion = registers.reduce((acc, record) => {
|
|
281
|
-
const zid = record.settings_form_submission.zid;
|
|
282
|
-
|
|
283
|
-
if (!acc[zid]) {
|
|
284
|
-
acc[zid] = record;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
return acc;
|
|
288
|
-
}, {} as { [key: string]: SubmissionInvoicesGraphQL });
|
|
289
|
-
|
|
290
|
-
let latestVersionRecords = Object.values(groupedByVersion).reverse();
|
|
291
|
-
|
|
292
|
-
//aplico el filtro de somevalue
|
|
293
|
-
if (filters?.some_field_value) {
|
|
294
|
-
latestVersionRecords = latestVersionRecords.filter((x) =>
|
|
295
|
-
x.settings_form_submission.settings_form_submission_values.some(
|
|
296
|
-
(y) => y.value === filters?.some_field_value
|
|
297
|
-
)
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
return latestVersionRecords;
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* getMyCaseFormSubmissions
|
|
307
|
-
*/
|
|
308
|
-
export async function getMyCaseFormSubmissions(
|
|
309
|
-
headersZauru: any,
|
|
310
|
-
session: Session,
|
|
311
|
-
filters: { formZid?: number; caseId?: number } = {},
|
|
312
|
-
config: { withFiles?: boolean } = { withFiles: false }
|
|
313
|
-
): Promise<AxiosUtilsResponse<SubmissionCasesGraphQL[]>> {
|
|
314
|
-
return handlePossibleAxiosErrors(async () => {
|
|
315
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
316
|
-
|
|
317
|
-
const response = await httpGraphQLAPI.post<{
|
|
318
|
-
data: { submission_cases: SubmissionCasesGraphQL[] };
|
|
319
|
-
errors?: {
|
|
320
|
-
message: string;
|
|
321
|
-
extensions: { path: string; code: string };
|
|
322
|
-
}[];
|
|
323
|
-
}>(
|
|
324
|
-
"",
|
|
325
|
-
{
|
|
326
|
-
query: getMyCaseFormSubmissionsStringQuery({
|
|
327
|
-
formZid: filters?.formZid,
|
|
328
|
-
caseId: filters?.caseId,
|
|
329
|
-
}),
|
|
330
|
-
variables: {
|
|
331
|
-
responsible_id: session.get("employee_id"),
|
|
332
|
-
},
|
|
333
|
-
},
|
|
334
|
-
{ headers }
|
|
335
|
-
);
|
|
336
|
-
|
|
337
|
-
if (response.data.errors) {
|
|
338
|
-
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
let registers = response?.data?.data?.submission_cases;
|
|
342
|
-
|
|
343
|
-
if (config.withFiles) {
|
|
344
|
-
registers = await Promise.all(
|
|
345
|
-
registers.map(async (register) => {
|
|
346
|
-
const responseZauru = await httpZauru.get(
|
|
347
|
-
`/settings/forms/form_submissions/${register.settings_form_submission.id}.json`,
|
|
348
|
-
{
|
|
349
|
-
headers: headersZauru,
|
|
350
|
-
}
|
|
351
|
-
);
|
|
352
|
-
|
|
353
|
-
register.settings_form_submission.settings_form_submission_values =
|
|
354
|
-
register.settings_form_submission.settings_form_submission_values.map(
|
|
355
|
-
(x) => {
|
|
356
|
-
if (
|
|
357
|
-
x.settings_form_field.field_type === "image" ||
|
|
358
|
-
x.settings_form_field.field_type === "file" ||
|
|
359
|
-
x.settings_form_field.field_type === "pdf"
|
|
360
|
-
) {
|
|
361
|
-
x.value = responseZauru.data[
|
|
362
|
-
x.settings_form_field.print_var_name
|
|
363
|
-
]
|
|
364
|
-
?.toString()
|
|
365
|
-
.replace(/\\u0026/g, "&");
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
return x;
|
|
369
|
-
}
|
|
370
|
-
);
|
|
371
|
-
|
|
372
|
-
return register;
|
|
373
|
-
})
|
|
374
|
-
);
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
return registers;
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* getLastInvoiceFormSubmission
|
|
383
|
-
* @param session
|
|
384
|
-
* @param filters
|
|
385
|
-
* @returns
|
|
386
|
-
*/
|
|
387
|
-
export async function getLastInvoiceFormSubmission(
|
|
388
|
-
session: Session,
|
|
389
|
-
filters: { formZid?: number } = {}
|
|
390
|
-
): Promise<AxiosUtilsResponse<SubmissionInvoicesGraphQL>> {
|
|
391
|
-
return handlePossibleAxiosErrors(async () => {
|
|
392
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
393
|
-
|
|
394
|
-
const response = await httpGraphQLAPI.post<{
|
|
395
|
-
data: { submission_invoices: SubmissionInvoicesGraphQL[] };
|
|
396
|
-
errors?: {
|
|
397
|
-
message: string;
|
|
398
|
-
extensions: { path: string; code: string };
|
|
399
|
-
}[];
|
|
400
|
-
}>(
|
|
401
|
-
"",
|
|
402
|
-
{
|
|
403
|
-
query: getLastInvoiceFormSubmissionStringQuery({
|
|
404
|
-
formZid: filters?.formZid,
|
|
405
|
-
}),
|
|
406
|
-
},
|
|
407
|
-
{ headers }
|
|
408
|
-
);
|
|
409
|
-
|
|
410
|
-
if (response.data.errors) {
|
|
411
|
-
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
const register = response?.data?.data?.submission_invoices[0];
|
|
415
|
-
|
|
416
|
-
return register;
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
/**
|
|
421
|
-
* getInvoiceFormSubmissionsByInvoiceId
|
|
422
|
-
*/
|
|
423
|
-
export async function getInvoiceFormSubmissionsByInvoiceId(
|
|
424
|
-
session: Session,
|
|
425
|
-
invoice_id: string,
|
|
426
|
-
filters: { formZid?: number } = {}
|
|
427
|
-
): Promise<AxiosUtilsResponse<SubmissionInvoicesGraphQL[]>> {
|
|
428
|
-
return handlePossibleAxiosErrors(async () => {
|
|
429
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
430
|
-
|
|
431
|
-
const response = await httpGraphQLAPI.post<{
|
|
432
|
-
data: { submission_invoices: SubmissionInvoicesGraphQL[] };
|
|
433
|
-
errors?: {
|
|
434
|
-
message: string;
|
|
435
|
-
extensions: { path: string; code: string };
|
|
436
|
-
}[];
|
|
437
|
-
}>(
|
|
438
|
-
"",
|
|
439
|
-
{
|
|
440
|
-
query: getInvoiceFormSubmissionsByInvoiceIdStringQuery({
|
|
441
|
-
formZid: filters?.formZid,
|
|
442
|
-
}),
|
|
443
|
-
variables: {
|
|
444
|
-
invoice_id,
|
|
445
|
-
},
|
|
446
|
-
},
|
|
447
|
-
{ headers }
|
|
448
|
-
);
|
|
449
|
-
|
|
450
|
-
if (response.data.errors) {
|
|
451
|
-
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
const registers = response?.data?.data?.submission_invoices;
|
|
455
|
-
|
|
456
|
-
// Filtrar los registros para obtener sólo los de la versión más alta.
|
|
457
|
-
const groupedByVersion = registers.reduce((acc, record) => {
|
|
458
|
-
const zid = record.settings_form_submission.zid;
|
|
459
|
-
|
|
460
|
-
if (!acc[zid]) {
|
|
461
|
-
acc[zid] = record;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
return acc;
|
|
465
|
-
}, {} as { [key: string]: SubmissionInvoicesGraphQL });
|
|
466
|
-
|
|
467
|
-
const latestVersionRecords = Object.values(groupedByVersion).reverse();
|
|
468
|
-
|
|
469
|
-
return latestVersionRecords;
|
|
470
|
-
});
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
* createForm
|
|
475
|
-
* @param headers
|
|
476
|
-
* @param body
|
|
477
|
-
*/
|
|
478
|
-
export async function createForm(
|
|
479
|
-
headers: any,
|
|
480
|
-
body: Partial<FormGraphQL>
|
|
481
|
-
): Promise<AxiosUtilsResponse<FormGraphQL>> {
|
|
482
|
-
return handlePossibleAxiosErrors(async () => {
|
|
483
|
-
const sendBody = {
|
|
484
|
-
...body,
|
|
485
|
-
form_fields_attributes: arrayToObject(body.settings_form_fields),
|
|
486
|
-
};
|
|
487
|
-
delete sendBody.settings_form_fields;
|
|
488
|
-
const response = await httpZauru.post<FormGraphQL>(
|
|
489
|
-
`/settings/forms.json`,
|
|
490
|
-
{ settings_form: sendBody },
|
|
491
|
-
{ headers }
|
|
492
|
-
);
|
|
493
|
-
return response.data;
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
/**
|
|
498
|
-
* deleteForm
|
|
499
|
-
* @param headers
|
|
500
|
-
* @param body
|
|
501
|
-
*/
|
|
502
|
-
export async function deleteForm(
|
|
503
|
-
headers: any,
|
|
504
|
-
id: string | number
|
|
505
|
-
): Promise<AxiosUtilsResponse<boolean>> {
|
|
506
|
-
return handlePossibleAxiosErrors(async () => {
|
|
507
|
-
await httpZauru.delete<any>(`/settings/forms/${id}?destroy=true`, {
|
|
508
|
-
headers,
|
|
509
|
-
});
|
|
510
|
-
return true;
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
/**
|
|
515
|
-
* createForm
|
|
516
|
-
* @param headers
|
|
517
|
-
* @param body
|
|
518
|
-
*/
|
|
519
|
-
export async function updateForm(
|
|
520
|
-
headers: any,
|
|
521
|
-
body: Partial<FormGraphQL>
|
|
522
|
-
): Promise<AxiosUtilsResponse<FormGraphQL>> {
|
|
523
|
-
return handlePossibleAxiosErrors(async () => {
|
|
524
|
-
const sendBody = {
|
|
525
|
-
...body,
|
|
526
|
-
form_fields_attributes: arrayToObject(body.settings_form_fields),
|
|
527
|
-
};
|
|
528
|
-
delete sendBody.settings_form_fields;
|
|
529
|
-
const response = await httpZauru.post<FormGraphQL>(
|
|
530
|
-
`/settings/forms.json`,
|
|
531
|
-
{ settings_form: sendBody },
|
|
532
|
-
{ headers }
|
|
533
|
-
);
|
|
534
|
-
return response.data;
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
* createFormSubmission
|
|
540
|
-
* @param headers
|
|
541
|
-
* @param body
|
|
542
|
-
* @returns
|
|
543
|
-
*/
|
|
544
|
-
export async function createFormSubmission(
|
|
545
|
-
headers: any,
|
|
546
|
-
body: Partial<FormSubmissionGraphQL>
|
|
547
|
-
) {
|
|
548
|
-
return handlePossibleAxiosErrors(async () => {
|
|
549
|
-
delete headers["Content-type"];
|
|
550
|
-
|
|
551
|
-
const sendBody = convertToFormData({
|
|
552
|
-
settings_form_submission: body,
|
|
553
|
-
});
|
|
554
|
-
|
|
555
|
-
const response = await httpZauru.post<FormSubmissionGraphQL>(
|
|
556
|
-
`/settings/forms/form_submissions.json`,
|
|
557
|
-
sendBody,
|
|
558
|
-
{ headers }
|
|
559
|
-
);
|
|
560
|
-
|
|
561
|
-
return response.data;
|
|
562
|
-
});
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
/**
|
|
566
|
-
* updateSubmissionInvoiceFormSubmission
|
|
567
|
-
* @param headers
|
|
568
|
-
* @param body
|
|
569
|
-
* @returns
|
|
570
|
-
*/
|
|
571
|
-
export async function updateSubmissionInvoiceFormSubmission(
|
|
572
|
-
headers: any,
|
|
573
|
-
body: Partial<SubmissionInvoicesGraphQL>
|
|
574
|
-
) {
|
|
575
|
-
return handlePossibleAxiosErrors(async () => {
|
|
576
|
-
const settings_form_submission = {
|
|
577
|
-
form_id: body.settings_form_submission?.settings_form?.id,
|
|
578
|
-
reference: body.settings_form_submission?.reference,
|
|
579
|
-
document_type: "invoice",
|
|
580
|
-
document_id: body.invoice_id,
|
|
581
|
-
zid: body.settings_form_submission?.zid,
|
|
582
|
-
form_submission_values_attributes: arrayToObject(
|
|
583
|
-
body.settings_form_submission?.settings_form_submission_values?.map(
|
|
584
|
-
(x) => {
|
|
585
|
-
delete (x as any).settings_form_field;
|
|
586
|
-
return x;
|
|
587
|
-
}
|
|
588
|
-
)
|
|
589
|
-
),
|
|
590
|
-
} as any;
|
|
591
|
-
const response = await httpZauru.post<FormSubmissionGraphQL>(
|
|
592
|
-
`/settings/forms/form_submissions.json`,
|
|
593
|
-
{
|
|
594
|
-
settings_form_submission,
|
|
595
|
-
},
|
|
596
|
-
{ headers }
|
|
597
|
-
);
|
|
598
|
-
|
|
599
|
-
return response.data;
|
|
600
|
-
});
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
/**
|
|
604
|
-
* deleteFormSubmission
|
|
605
|
-
* @param headers
|
|
606
|
-
* @param body
|
|
607
|
-
*/
|
|
608
|
-
export async function deleteFormSubmission(
|
|
609
|
-
headers: any,
|
|
610
|
-
id: string | number
|
|
611
|
-
): Promise<AxiosUtilsResponse<boolean>> {
|
|
612
|
-
return handlePossibleAxiosErrors(async () => {
|
|
613
|
-
await httpZauru.delete<any>(`/settings/forms/form_submissions/${id}.json`, {
|
|
614
|
-
headers,
|
|
615
|
-
});
|
|
616
|
-
return true;
|
|
617
|
-
});
|
|
618
|
-
}
|